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.



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

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

Instance Method Details

#scrub(node) ⇒ Object



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

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