Rails, given an HTML string from WYSIWYG - how to get only text

I have a large HTML string from WYSIWYG and you want to show truncates string of only text, html or html tags. Is there a way to do this built into the rails, or do I need gsub to get rid of all the html brackets?

thank

+3
source share
3 answers

Rails already includes some powerful sanitation assistants .

string = '<span id="span_is"><br><br><u><i>Hi</i></u></span>'
strip_tags(string)
+4
source

, HTML, , , Nokogiri XPath, , HTML. , , .

+1

, , HTML . - Loofah sanitize , Nokogiri HTML, , .

require 'sanitize'

html = '<html><body>Jackdaws love my giant sphinx of quartz.</body></html>'
puts Sanitize.clean(html)
# >> Jackdaws love my giant sphinx of quartz.

, loofah , , , , - , , .

0

Source: https://habr.com/ru/post/1777129/


All Articles