Note that there are some explanatory texts on larger screens.

plurals
  1. POTruncate Markdown?
    primarykey
    data
    text
    <p>I have a Rails site, where the content is written in markdown. I wish to display a snippet of each, with a "Read more.." link.</p> <p>How do I go about this? Simple truncating the raw text will not work, for example..</p> <pre><code>&gt;&gt; "This is an [example](http://example.com)"[0..25] =&gt; "This is an [example](http:" </code></pre> <p>Ideally I want to allow the author to (optionally) insert a marker to specify what to use as the "snippet", if not it would take 250 words, and append "..." - for example..</p> <pre><code>This article is an example of something or other. This segment will be used as the snippet on the index page. ^^^^^^^^^^^^^^^ This text will be visible once clicking the "Read more.." link </code></pre> <p>The marker could be thought of like an EOF marker (which can be ignored when displaying the full document)</p> <p>I am using <a href="http://maruku.rubyforge.org/" rel="noreferrer">maruku</a> for the Markdown processing (RedCloth is very biased towards Textile, BlueCloth is extremely buggy, and I wanted a native-Ruby parser which ruled out peg-markdown and RDiscount)</p> <p>Alternatively (since the Markdown is translated to HTML anyway) truncating the HTML correctly would be an option - although it would be preferable to not <code>markdown()</code> the entire document, just to get the first few lines.</p> <p>So, the options I can think of are (in order of preference)..</p> <ul> <li>Add a "truncate" option to the maruku parser, which will only parse the first x words, or till the "excerpt" marker.</li> <li>Write/find a parser-agnostic Markdown truncate'r</li> <li>Write/find an intelligent HTML truncating function</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload