Module: Coradoc::Input::HTML::Converters

Defined in:
lib/coradoc/input/html/converters.rb,
lib/coradoc/input/html/converters/a.rb,
lib/coradoc/input/html/converters/h.rb,
lib/coradoc/input/html/converters/p.rb,
lib/coradoc/input/html/converters/q.rb,
lib/coradoc/input/html/converters/br.rb,
lib/coradoc/input/html/converters/dl.rb,
lib/coradoc/input/html/converters/em.rb,
lib/coradoc/input/html/converters/hr.rb,
lib/coradoc/input/html/converters/li.rb,
lib/coradoc/input/html/converters/ol.rb,
lib/coradoc/input/html/converters/td.rb,
lib/coradoc/input/html/converters/th.rb,
lib/coradoc/input/html/converters/tr.rb,
lib/coradoc/input/html/converters/div.rb,
lib/coradoc/input/html/converters/img.rb,
lib/coradoc/input/html/converters/pre.rb,
lib/coradoc/input/html/converters/sub.rb,
lib/coradoc/input/html/converters/sup.rb,
lib/coradoc/input/html/converters/base.rb,
lib/coradoc/input/html/converters/code.rb,
lib/coradoc/input/html/converters/drop.rb,
lib/coradoc/input/html/converters/head.rb,
lib/coradoc/input/html/converters/mark.rb,
lib/coradoc/input/html/converters/math.rb,
lib/coradoc/input/html/converters/text.rb,
lib/coradoc/input/html/converters/aside.rb,
lib/coradoc/input/html/converters/audio.rb,
lib/coradoc/input/html/converters/table.rb,
lib/coradoc/input/html/converters/video.rb,
lib/coradoc/input/html/converters/bypass.rb,
lib/coradoc/input/html/converters/figure.rb,
lib/coradoc/input/html/converters/ignore.rb,
lib/coradoc/input/html/converters/markup.rb,
lib/coradoc/input/html/converters/strong.rb,
lib/coradoc/input/html/converters/blockquote.rb,
lib/coradoc/input/html/converters/pass_through.rb

Defined Under Namespace

Classes: A, Aside, Audio, Base, Blockquote, Br, Bypass, Code, Div, Dl, Drop, Em, Figure, H, Head, Hr, Ignore, Img, Li, Mark, Markup, Math, Ol, P, PassThrough, Pre, Q, Strong, Sub, Sup, Table, Td, Text, Th, Tr, Video

Class Method Summary collapse

Class Method Details

.default_converter(tag_name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/coradoc/input/html/converters.rb', line 40

def self.default_converter(tag_name)
  case Coradoc::Input::HTML.config.unknown_tags.to_sym
  when :pass_through
    Coradoc::Input::HTML::Converters::PassThrough.new
  when :drop
    Coradoc::Input::HTML::Converters::Drop.new
  when :bypass
    Coradoc::Input::HTML::Converters::Bypass.new
  when :raise
    raise UnknownTagError, "unknown tag: #{tag_name}"
  else
    raise InvalidConfigurationError,
          "unknown value #{Coradoc::Input::HTML.config.unknown_tags.inspect} for Coradoc::Input::HTML.config.unknown_tags"
  end
end

.lookup(tag_name) ⇒ Object



13
14
15
16
17
# File 'lib/coradoc/input/html/converters.rb', line 13

def self.lookup(tag_name)
  converter = @@converters[tag_name.to_sym] || default_converter(tag_name)
  converter = converter.new if converter.respond_to? :new
  converter
end

.process(node, state) ⇒ Object

Note: process won’t run plugin hooks



20
21
22
23
24
25
# File 'lib/coradoc/input/html/converters.rb', line 20

def self.process(node, state)
  node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
  return node.map { |i| process(i, state) }.join if node.is_a? Array

  lookup(node.name).convert(node, state)
end

.process_coradoc(node, state) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/coradoc/input/html/converters.rb', line 27

def self.process_coradoc(node, state)
  node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
  return node.map { |i| process_coradoc(i, state) } if node.is_a? Array

  plugins = state[:plugin_instances] || {}
  process = proc { lookup(node.name).to_coradoc(node, state) }
  plugins.each do |i|
    prev_process = process
    process = proc { i.html_tree_run_hooks(node, state, &prev_process) }
  end
  process.(node, state)
end

.register(tag_name, converter) ⇒ Object



4
5
6
7
# File 'lib/coradoc/input/html/converters.rb', line 4

def self.register(tag_name, converter)
  @@converters ||= {}
  @@converters[tag_name.to_sym] = converter
end

.unregister(tag_name) ⇒ Object



9
10
11
# File 'lib/coradoc/input/html/converters.rb', line 9

def self.unregister(tag_name)
  @@converters.delete(tag_name.to_sym)
end