Module: Uuml::HTML

Extended by:
HTML
Included in:
HTML
Defined in:
lib/uuml/html.rb

Constant Summary collapse

TEXT_TAGS =
%w{title p a li h1 h2 h3 h4 h5 h6 div span option strong em b i u}

Instance Method Summary collapse

Instance Method Details

#convert(html) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/uuml/html.rb', line 8

def convert(html)
  replacer = lambda do |node| 
    node.content = node.content.
                        gsub(/(?<![Qq])ue/, 'ü').
                        gsub(/(?<![QqOoAa])u(?![i])/, 'ü').
                        gsub(/(?<![QqOoAa])U(?![Ii])/, 'Ü')
  end
  condition = TEXT_TAGS.map { |t| "parent::#{t}"}.join(' or ')

  doc = Nokogiri::HTML(html)
  doc.xpath("//text()[#{condition}]").each(&replacer)
  doc.xpath('//@alt').each(&replacer)
  doc.xpath('//@title').each(&replacer)
  doc.to_s
end