Is there an HTML safe truncate method in Rails?

后端 未结 10 665
执笔经年
执笔经年 2020-12-24 05:45

I have a string of HTML in Rails. I\'d like to truncate the string after a certain number of characters not including the HTML markup. Also, if the split happens to fall in

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 06:11

    We had this need in zendone.com. The problem was that the existing solutions were very slow when truncating long HTML documents (MBs) into shorter ones (KBs). I ended up coding a library based in Nokogiri called truncato. The library includes some benchmarks comparing its performance with other libs.

提交回复
热议问题