Class: Coradoc::Input::HTML::Converters::Dl
- Inherits:
-
Base
- Object
- Base
- Coradoc::Input::HTML::Converters::Dl
show all
- Defined in:
- lib/coradoc/input/html/converters/dl.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
#process_dl(node, state = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/coradoc/input/html/converters/dl.rb', line 12
def process_dl(node, state = {})
groups = []
current = {name: [], value: []}
seen_dd = false
child = node.at_xpath("*[1]")
grandchild = nil
while !child.nil?
if child.name == "div"
grandchild = child.at_xpath("*[1]")
while !grandchild.nil?
groups, current, seen_dd = process_dt_or_dd(groups, current, seen_dd, grandchild, state)
grandchild = grandchild.at_xpath("following-sibling::*[1]")
end
elsif ["dt", "dd"].include?(child.name)
groups, current, seen_dd = process_dt_or_dd(groups, current, seen_dd, child, state)
end
child = child.at_xpath("following-sibling::*[1]")
if current[:name].any? && current[:value].any?
groups << current
end
end
groups
end
|
#process_dt_or_dd(groups, current, seen_dd, subnode, state = {}) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/coradoc/input/html/converters/dl.rb', line 37
def process_dt_or_dd(groups, current, seen_dd, subnode, state = {})
if subnode.name == "dt"
if seen_dd
current = {name: [], value: []}
seen_dd = false
end
current[:name] += treat_children_coradoc(subnode, state)
elsif subnode.name == "dd"
current[:value] += treat_children_coradoc(subnode, state)
seen_dd = true
end
[groups, current, seen_dd]
end
|
#to_coradoc(node, state = {}) ⇒ Object