Last Updated: March 18, 2016
·
15.74K
· vumanhcuongit

How to truncate a string that's Markdown format

Regarding this Markdown tip. Today, I got a trouble about truncating string written in Markdown format.

Firstly, I just used truncate(markdown(text), length: 100) but it doesn't work well.

<h1>An h1 header</h1> <p>Paragraphs are separated by a blank line.</p> <p>2nd paragraph. <em>It...

Finally, I tried this one and it works :)

truncate(markdown(item.description), length: 100, escape: false)