Class: Coradoc::Input::HTML::Converters::H
- Inherits:
-
Base
- Object
- Base
- Coradoc::Input::HTML::Converters::H
show all
- Defined in:
- lib/coradoc/input/html/converters/h.rb
Instance Method Summary
collapse
Methods inherited from Base
#convert, #extract_leading_trailing_whitespace, #extract_title, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?
Instance Method Details
#to_coradoc(node, state = {}) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/coradoc/input/html/converters/h.rb', line 4
def to_coradoc(node, state = {})
id = node["id"]
internal_anchor = treat_children_anchors(node, state)
if id.to_s.empty? && internal_anchor.size.positive?
if internal_anchor.first.respond_to? :id
id = internal_anchor.first.id
end
end
level = node.name[/\d/].to_i
content = treat_children_no_anchors(node, state)
Coradoc::Element::Title.new(content, level, id: id)
end
|
#treat_children_anchors(node, state) ⇒ Object
26
27
28
29
30
|
# File 'lib/coradoc/input/html/converters/h.rb', line 26
def treat_children_anchors(node, state)
node.children.select { |a| a.name == "a" }.map do |child|
treat_coradoc(child, state)
end
end
|
#treat_children_no_anchors(node, state) ⇒ Object
20
21
22
23
24
|
# File 'lib/coradoc/input/html/converters/h.rb', line 20
def treat_children_no_anchors(node, state)
node.children.reject { |a| a.name == "a" }.map do |child|
treat_coradoc(child, state)
end
end
|