Class: ReverseAdoc::Converters::H
- Inherits:
-
Base
- Object
- Base
- ReverseAdoc::Converters::H
show all
- Defined in:
- lib/reverse_adoc/converters/h.rb
Instance Method Summary
collapse
Methods inherited from Base
#constrained?, #escape_keychars, #extract_title, #node_has_ancestor?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?
Instance Method Details
#convert(node, state = {}) ⇒ Object
18
19
20
|
# File 'lib/reverse_adoc/converters/h.rb', line 18
def convert(node, state = {})
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
end
|
#to_coradoc(node, state = {}) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/reverse_adoc/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?
id = internal_anchor.first.id
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
28
29
30
31
32
|
# File 'lib/reverse_adoc/converters/h.rb', line 28
def treat_children_anchors(node, state)
node.children.select { |a| a.name == "a" }.inject([]) do |memo, child|
memo << treat_coradoc(child, state)
end
end
|
#treat_children_no_anchors(node, state) ⇒ Object
22
23
24
25
26
|
# File 'lib/reverse_adoc/converters/h.rb', line 22
def treat_children_no_anchors(node, state)
node.children.reject { |a| a.name == "a" }.inject([]) do |memo, child|
memo << treat_coradoc(child, state)
end
end
|