Reputation: 553
I'm truncating some text like this:
<%= sanitize(post.body_text, tags: %w(p img)).truncate(20, :separator => " ").html_safe %>
The problem is if an img or p tag is caught in between 20 characters it cuts off like so:
<p>This is some text <img...
Which messes up the html of the rest of the page. So how do I truncate without leaving unclosed tags?
Upvotes: 1
Views: 714