Class: ReverseAdoc::Converters::Strong
- Inherits:
-
Base
- Object
- Base
- ReverseAdoc::Converters::Strong
show all
- Defined in:
- lib/reverse_adoc/converters/strong.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
44
45
46
|
# File 'lib/reverse_adoc/converters/strong.rb', line 44
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/reverse_adoc/converters/strong.rb', line 4
def to_coradoc(node, state = {})
content = treat_children_coradoc(node,
state.merge(already_strong: true))
if Coradoc::Generator.gen_adoc(content).strip.empty?
return ""
end
if node_has_ancestor?(node, ["strong", "b"])
return content
end
u_before = unconstrained_before?(node)
u_after = unconstrained_after?(node)
node.text =~ /^(\s+)/
leading_whitespace = $1
has_leading_whitespace = !leading_whitespace.nil?
if has_leading_whitespace
first_text = node.at_xpath("./text()[1]")
first_text.replace(first_text.text.lstrip)
leading_whitespace = u_before ? " " : " "
end
node.text =~ /(\s+)$/
trailing_whitespace = $1
has_trailing_whitespace = !trailing_whitespace.nil?
if has_trailing_whitespace
last_text = node.at_xpath("./text()[last()]")
last_text.replace(last_text.text.rstrip)
trailing_whitespace = u_after ? "" : ""
end
u = !((!u_before || has_leading_whitespace) && (!u_after || has_trailing_whitespace))
e = Coradoc::Element::Inline::Bold.new(content, u)
[leading_whitespace, e, trailing_whitespace]
end
|