Class: ReverseAdoc::Converters::A
- Inherits:
-
Base
- Object
- Base
- ReverseAdoc::Converters::A
show all
- Defined in:
- lib/reverse_adoc/converters/a.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
35
36
37
|
# File 'lib/reverse_adoc/converters/a.rb', line 35
def convert(node, state = {})
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
end
|
#to_coradoc(node, state = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/reverse_adoc/converters/a.rb', line 6
def to_coradoc(node, state = {})
name = treat_children(node, state)
href = node["href"]
title = (node)
id = node["id"] || node["name"]
id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
return "" if /^_Toc\d+$|^_GoBack$/.match?(id)
if !id.nil? && !id.empty?
return Coradoc::Element::Inline::Anchor.new(id)
end
if href.to_s.start_with?("#")
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
return Coradoc::Element::Inline::CrossReference.new(href, name)
end
if href.to_s.empty?
return name
end
Coradoc::Element::Inline::Link.new(path: href,
name: name,
title: title)
end
|