Is there an HTML safe truncate method in Rails? -


i have string of html in rails. i'd truncate string after number of characters not including html markup. also, if split happens fall in middle of opening , closing tag, i'd close open tag/s. example;

html = "123<a href='#'>456</a>7890" truncate_markup(html, :length => 5) --> "123<a href='#'>45</a>" 

there 2 different solutions both same name: truncate_html

  1. https://github.com/ianwhite/truncate_html : gem , uses html parser (nokogiri)
  2. https://github.com/hgmnz/truncate_html : file put in helpers directory. uses regular expressions , has no dependencies.

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -