here with" /> here with" /> here with"/>

parse_markdown and truncate

90 Views Asked by At

I have to use at the same time parse_markdown and truncate. My text is (for example)

"Hi **boys**, I am very happy to be <a href="/here">here<a/> with you. I am so proud of you and your work."

If I use

<%= parse_markdown(truncate(@city.last_news.text, length: 30, separator: ' ')).html_safe %>

I see

Hi **boys**, I am very happy to be <a href="/here">here<a/> with you. I am so proud of you and your work.

with the markdown but without the truncate.

and if I use

<%= truncate(parse_markdown(@city.last_news.text).html_safe, length: 30, separator: ' ') %>

I see

    Hi **boys**, I am very happy to be <a href="/here">here<a/> with yo...

with the truncatebut without the markdown.

How to solve?

1

There are 1 best solutions below

0
Vi. On

I was using this gem to truncate html. If you can manage to get it working today (latest commit is from 5 years ago), this will solve one part of your problem. Idk if it can be useful for markdown too. Try it out

Example usage:

%p
  = truncate_html(document.description, length: 200)