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.fragment("<script>alert('EVIL');</script>")

can pass an argument as shown:
that the result is unsafe to render in a browser, then you
escaped. If you want unescaped entities, and you understand
By default, the returned text will have HTML entities

# => "TitleContent"
Loofah.document("

Title

Content
").text

clever about whitespace around block elements.
This method is significantly faster than #to_text, but isn't

with HTML entities encoded.
Returns a plain-text version of the markup contained by the document,
def text(options={})
  result = serialize_root.children.inner_text rescue ""
  if options[:encode_special_chars] == false
    result # possibly dangerous if rendered in a browser
  else
    encode_special_chars result
  end
end

def to_text(options={})


# => "\nTitle\n\nContent\n"
Loofah.document("

Title

Content
").to_text

whitespace around block elements.
This method is slower than #to_text, but is clever about

fragment, with HTML entities encoded.
Returns a plain-text version of the markup contained by the
def to_text(options={})
  Loofah.remove_extraneous_whitespace self.dup.scrub!(:newline_block_elements).text(options)
end