Class: Redmine::WikiFormatting::HtmlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine/wiki_formatting/html_parser.rb

Direct Known Subclasses

Markdown::HtmlParser, Textile::HtmlParser

Defined Under Namespace

Classes: WikiTags

Class Method Summary collapse

Class Method Details

.to_text(html) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/redmine/wiki_formatting/html_parser.rb', line 32

def self.to_text(html)
  html = html.gsub(/[\n\r]/, ' ')

  doc = Loofah.document(html)
  doc.scrub!(WikiTags.new(tags))
  doc.scrub!(:newline_block_elements)

  Loofah.remove_extraneous_whitespace(doc.text(:encode_special_chars => false)).strip.squeeze(' ').gsub(/^ +/, '')
end