Class: Redmine::WikiFormatting::HtmlParser::WikiTags

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

Instance Method Summary collapse

Constructor Details

#initialize(tags_to_text) ⇒ WikiTags

Returns a new instance of WikiTags.



42
43
44
45
# File 'lib/redmine/wiki_formatting/html_parser.rb', line 42

def initialize(tags_to_text)
  super(:direction => :bottom_up)
  @tags_to_text = tags_to_text || {}
end

Instance Method Details

#scrub(node) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/redmine/wiki_formatting/html_parser.rb', line 47

def scrub(node)
  formatting = @tags_to_text[node.name]
  case formatting
  when Hash
    node.add_next_sibling Nokogiri::XML::Text.new("#{formatting[:pre]}#{node.content}#{formatting[:post]}", node.document)
    node.remove
  when String
    node.add_next_sibling Nokogiri::XML::Text.new(formatting, node.document)
    node.remove
  when Proc
    node.add_next_sibling formatting.call(node)
    node.remove
  else
    CONTINUE
  end
end