Class: Coradoc::Input::Html::Converters::H
- Inherits:
-
Base
- Object
- Base
- Coradoc::Input::Html::Converters::H
show all
- Defined in:
- lib/coradoc/html/input/converters/h.rb
Instance Method Summary
collapse
Methods inherited from Base
#convert, #escape_text, #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
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/coradoc/html/input/converters/h.rb', line 8
def to_coradoc(node, state = {})
id = node['id']
internal_anchor = treat_children_anchors(node, state)
if id.to_s.empty? && internal_anchor.size.positive?
first_model = internal_anchor.first
id = first_model.target if first_model.is_a?(Coradoc::CoreModel::InlineElement) && first_model.target
end
level_int = node.name[/\d/].to_i
content = treat_children_no_anchors(node, state)
Coradoc::CoreModel::StructuralElement.new(
element_type: 'section',
title: (content),
level: level_int,
id: id,
children: []
)
end
|
#treat_children_anchors(node, state) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/coradoc/html/input/converters/h.rb', line 38
def treat_children_anchors(node, state)
node.children.select { |a| a.name == 'a' }
.map do |child|
treat_coradoc(child, state)
end.flatten.compact
end
|
#treat_children_no_anchors(node, state) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/coradoc/html/input/converters/h.rb', line 31
def treat_children_no_anchors(node, state)
node.children.reject { |a| a.name == 'a' }
.map do |child|
treat_coradoc(child, state)
end.flatten.compact
end
|