module Loofah::TextBehavior
def text(options = {})
frag.text(:encode_special_chars => false) # => ""
# decidedly not ok for browser:
frag.text # => "<script>alert('EVIL');</script>"
# ok for browser:
frag = Loofah.html5_fragment("<script>alert('EVIL');</script>")
pass an argument as shown:
entities, and you understand that the result is unsafe to render in a browser, then you can
By default, the returned text will have HTML entities escaped. If you want unescaped
# => "TitleContent"
Loofah.html5_document("
Title
Content
").textblock elements.
This method is significantly faster than #to_text, but isn't clever about whitespace around
encoded.
Returns a plain-text version of the markup contained by the document, with HTML entities
def text(options = {}) result = if serialize_root serialize_root.children.reject(&:comment?).map(&:inner_text).join("") else "" end if options[:encode_special_chars] == false result # possibly dangerous if rendered in a browser else encode_special_chars(result) end end