reverse_adoc 0.3.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +4 -3
- data/Gemfile +1 -1
- data/Rakefile +7 -7
- data/exe/reverse_adoc +11 -11
- data/exe/w2a +15 -16
- data/lib/reverse_adoc/cleaner.rb +17 -18
- data/lib/reverse_adoc/config.rb +7 -7
- data/lib/reverse_adoc/converters/a.rb +24 -24
- data/lib/reverse_adoc/converters/aside.rb +6 -4
- data/lib/reverse_adoc/converters/audio.rb +16 -21
- data/lib/reverse_adoc/converters/base.rb +79 -5
- data/lib/reverse_adoc/converters/blockquote.rb +16 -7
- data/lib/reverse_adoc/converters/br.rb +5 -1
- data/lib/reverse_adoc/converters/bypass.rb +38 -34
- data/lib/reverse_adoc/converters/code.rb +42 -1
- data/lib/reverse_adoc/converters/div.rb +7 -3
- data/lib/reverse_adoc/converters/drop.rb +6 -2
- data/lib/reverse_adoc/converters/em.rb +44 -7
- data/lib/reverse_adoc/converters/figure.rb +10 -6
- data/lib/reverse_adoc/converters/h.rb +19 -11
- data/lib/reverse_adoc/converters/head.rb +7 -2
- data/lib/reverse_adoc/converters/hr.rb +5 -1
- data/lib/reverse_adoc/converters/ignore.rb +6 -2
- data/lib/reverse_adoc/converters/img.rb +29 -19
- data/lib/reverse_adoc/converters/li.rb +6 -13
- data/lib/reverse_adoc/converters/mark.rb +11 -2
- data/lib/reverse_adoc/converters/math.rb +13 -2
- data/lib/reverse_adoc/converters/ol.rb +44 -26
- data/lib/reverse_adoc/converters/p.rb +13 -7
- data/lib/reverse_adoc/converters/pass_through.rb +5 -1
- data/lib/reverse_adoc/converters/pre.rb +23 -10
- data/lib/reverse_adoc/converters/q.rb +6 -2
- data/lib/reverse_adoc/converters/strong.rb +41 -6
- data/lib/reverse_adoc/converters/sub.rb +6 -2
- data/lib/reverse_adoc/converters/sup.rb +6 -2
- data/lib/reverse_adoc/converters/table.rb +28 -23
- data/lib/reverse_adoc/converters/td.rb +32 -16
- data/lib/reverse_adoc/converters/text.rb +16 -14
- data/lib/reverse_adoc/converters/th.rb +4 -6
- data/lib/reverse_adoc/converters/tr.rb +7 -7
- data/lib/reverse_adoc/converters/video.rb +16 -23
- data/lib/reverse_adoc/converters.rb +2 -3
- data/lib/reverse_adoc/html_converter.rb +48 -43
- data/lib/reverse_adoc/version.rb +1 -1
- data/lib/reverse_adoc.rb +9 -9
- data/reverse_adoc.gemspec +4 -1
- data/spec/assets/basic.html +3 -0
- data/spec/bin/reverse_adoc_spec.rb +9 -8
- data/spec/bin/w2a_spec.rb +12 -12
- data/spec/components/anchors_spec.rb +18 -12
- data/spec/components/basic_spec.rb +28 -14
- data/spec/components/code_spec.rb +2 -4
- data/spec/components/escapables_spec.rb +4 -6
- data/spec/components/from_the_wild_spec.rb +2 -4
- data/spec/components/html_fragment_spec.rb +2 -3
- data/spec/components/lists_spec.rb +12 -8
- data/spec/components/paragraphs_spec.rb +2 -3
- data/spec/components/quotation_spec.rb +5 -5
- data/spec/components/tables_spec.rb +22 -11
- data/spec/components/unknown_tags_spec.rb +13 -10
- data/spec/lib/reverse_adoc/cleaner_spec.rb +70 -71
- data/spec/lib/reverse_adoc/config_spec.rb +5 -6
- data/spec/lib/reverse_adoc/converters/aside_spec.rb +2 -3
- data/spec/lib/reverse_adoc/converters/audio_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +5 -6
- data/spec/lib/reverse_adoc/converters/br_spec.rb +2 -2
- data/spec/lib/reverse_adoc/converters/code_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/div_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/figure_spec.rb +2 -4
- data/spec/lib/reverse_adoc/converters/img_spec.rb +5 -7
- data/spec/lib/reverse_adoc/converters/li_spec.rb +2 -4
- data/spec/lib/reverse_adoc/converters/mark_spec.rb +4 -4
- data/spec/lib/reverse_adoc/converters/p_spec.rb +2 -3
- data/spec/lib/reverse_adoc/converters/pre_spec.rb +8 -9
- data/spec/lib/reverse_adoc/converters/q_spec.rb +3 -3
- data/spec/lib/reverse_adoc/converters/strong_spec.rb +9 -8
- data/spec/lib/reverse_adoc/converters/text_spec.rb +13 -14
- data/spec/lib/reverse_adoc/converters/video_spec.rb +7 -9
- data/spec/lib/reverse_adoc/converters_spec.rb +9 -6
- data/spec/lib/reverse_adoc.rb +25 -25
- data/spec/spec_helper.rb +11 -11
- data/spec/support/shell_helpers.rb +1 -1
- metadata +17 -3
@@ -1,21 +1,34 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Pre < Base
|
4
|
-
def
|
5
|
-
id = node[
|
6
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
id = node["id"]
|
7
6
|
lang = language(node)
|
8
7
|
content = treat_children(node, state)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
|
9
|
+
unless lang
|
10
|
+
return Coradoc::Element::Block::Literal.new(
|
11
|
+
nil,
|
12
|
+
lines: content,
|
13
|
+
id: id,
|
14
|
+
)
|
13
15
|
end
|
16
|
+
|
17
|
+
Coradoc::Element::Block::SourceCode.new(
|
18
|
+
nil,
|
19
|
+
lines: content,
|
20
|
+
lang: lang,
|
21
|
+
id: id,
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def convert(node, state = {})
|
26
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
14
27
|
end
|
15
28
|
|
16
29
|
private
|
17
30
|
|
18
|
-
def treat(node,
|
31
|
+
def treat(node, _state)
|
19
32
|
return "\n" if node.name == "br"
|
20
33
|
|
21
34
|
prefix = postfix = "\n\n" if node.name == "p"
|
@@ -29,11 +42,11 @@ module ReverseAdoc
|
|
29
42
|
end
|
30
43
|
|
31
44
|
def language_from_highlight_class(node)
|
32
|
-
node.parent[
|
45
|
+
node.parent["class"].to_s[/highlight-([a-zA-Z0-9]+)/, 1]
|
33
46
|
end
|
34
47
|
|
35
48
|
def language_from_confluence_class(node)
|
36
|
-
node[
|
49
|
+
node["class"].to_s[/brush:\s?(:?.*);/, 1]
|
37
50
|
end
|
38
51
|
end
|
39
52
|
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Q < Base
|
4
|
-
def
|
4
|
+
def to_coradoc(node, state = {})
|
5
5
|
content = treat_children(node, state)
|
6
|
-
|
6
|
+
Coradoc::Element::Inline::Quotation.new(content)
|
7
|
+
end
|
8
|
+
|
9
|
+
def convert(node, state = {})
|
10
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -1,13 +1,48 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Strong < Base
|
4
|
-
def
|
5
|
-
content =
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
"
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
content = treat_children_coradoc(node,
|
6
|
+
state.merge(already_strong: true))
|
7
|
+
|
8
|
+
if Coradoc::Generator.gen_adoc(content).strip.empty?
|
9
|
+
return ""
|
10
|
+
end
|
11
|
+
|
12
|
+
if node_has_ancestor?(node, ["strong", "b"])
|
13
|
+
return content
|
10
14
|
end
|
15
|
+
|
16
|
+
u_before = unconstrained_before?(node)
|
17
|
+
u_after = unconstrained_after?(node)
|
18
|
+
node.text =~ /^(\s+)/
|
19
|
+
leading_whitespace = $1
|
20
|
+
has_leading_whitespace = !leading_whitespace.nil?
|
21
|
+
|
22
|
+
if has_leading_whitespace
|
23
|
+
first_text = node.at_xpath("./text()[1]")
|
24
|
+
first_text.replace(first_text.text.lstrip)
|
25
|
+
leading_whitespace = u_before ? " " : " " # ########################33 somethings wrong in here
|
26
|
+
end
|
27
|
+
|
28
|
+
node.text =~ /(\s+)$/
|
29
|
+
trailing_whitespace = $1
|
30
|
+
has_trailing_whitespace = !trailing_whitespace.nil?
|
31
|
+
|
32
|
+
if has_trailing_whitespace
|
33
|
+
last_text = node.at_xpath("./text()[last()]")
|
34
|
+
last_text.replace(last_text.text.rstrip)
|
35
|
+
trailing_whitespace = u_after ? "" : "" ###############################
|
36
|
+
end
|
37
|
+
|
38
|
+
u = !((!u_before || has_leading_whitespace) && (!u_after || has_trailing_whitespace))
|
39
|
+
e = Coradoc::Element::Inline::Bold.new(content, u)
|
40
|
+
|
41
|
+
[leading_whitespace, e, trailing_whitespace]
|
42
|
+
end
|
43
|
+
|
44
|
+
def convert(node, state = {})
|
45
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
11
46
|
end
|
12
47
|
end
|
13
48
|
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Sub < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
content = treat_children_coradoc(node, state)
|
6
|
+
Coradoc::Element::Inline::Subscript.new(content)
|
7
|
+
end
|
8
|
+
|
4
9
|
def convert(node, state = {})
|
5
|
-
|
6
|
-
"#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
|
10
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Sup < Base
|
4
|
-
def
|
4
|
+
def to_coradoc(node, state = {})
|
5
5
|
content = treat_children(node, state)
|
6
|
-
|
6
|
+
Coradoc::Element::Inline::Superscript.new(content)
|
7
|
+
end
|
8
|
+
|
9
|
+
def convert(node, state = {})
|
10
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -1,61 +1,66 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Table < Base
|
4
|
-
def
|
5
|
-
id = node[
|
6
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
id = node["id"]
|
7
6
|
title = extract_title(node)
|
8
|
-
title = ".#{title}\n" unless title.empty?
|
9
7
|
attrs = style(node)
|
10
|
-
|
8
|
+
content = treat_children_coradoc(node, state)
|
9
|
+
Coradoc::Element::Table.new(title, content, { id: id, attrs: attrs })
|
10
|
+
end
|
11
|
+
|
12
|
+
def convert(node, state = {})
|
13
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
11
14
|
end
|
12
15
|
|
13
16
|
def extract_title(node)
|
14
17
|
title = node.at("./caption")
|
15
18
|
return "" if title.nil?
|
19
|
+
|
16
20
|
treat_children(title, {})
|
17
21
|
end
|
18
22
|
|
19
23
|
def frame(node)
|
20
24
|
case node["frame"]
|
21
25
|
when "void"
|
22
|
-
"
|
26
|
+
"none"
|
23
27
|
when "hsides"
|
24
|
-
"
|
28
|
+
"topbot"
|
25
29
|
when "vsides"
|
26
|
-
"
|
30
|
+
"sides"
|
27
31
|
when "box", "border"
|
28
|
-
"
|
29
|
-
else
|
30
|
-
nil
|
32
|
+
"all"
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
def rules(node)
|
35
37
|
case node["rules"]
|
36
38
|
when "all"
|
37
|
-
"
|
39
|
+
"all"
|
38
40
|
when "rows"
|
39
|
-
"
|
41
|
+
"rows"
|
40
42
|
when "cols"
|
41
|
-
"
|
43
|
+
"cols"
|
42
44
|
when "none"
|
43
|
-
"
|
44
|
-
else
|
45
|
-
nil
|
45
|
+
"none"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def style(node)
|
50
|
-
|
51
|
-
|
50
|
+
attrs = Coradoc::Element::AttributeList.new
|
51
|
+
# Width is disabled on tables for now. (From #88)
|
52
|
+
# attrs.add_named("width", node["width"]) if node["width"]
|
53
|
+
|
52
54
|
frame_attr = frame(node)
|
55
|
+
attrs.add_named("frame", frame_attr) if frame_attr
|
56
|
+
|
53
57
|
rules_attr = rules(node)
|
54
|
-
attrs
|
55
|
-
|
56
|
-
|
58
|
+
attrs.add_named("rules", rules_attr) if rules_attr
|
59
|
+
|
60
|
+
# This line should be removed.
|
57
61
|
return "" if attrs.empty?
|
58
|
-
|
62
|
+
|
63
|
+
attrs
|
59
64
|
end
|
60
65
|
end
|
61
66
|
|
@@ -1,32 +1,48 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Td < Base
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
colrowattr = colrow(node[
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
# convert(node, state)
|
6
|
+
id = node["id"]
|
7
|
+
colrowattr = colrow(node["colspan"], node["rowspan"])
|
8
8
|
alignattr = alignstyle(node)
|
9
9
|
style = cellstyle(node)
|
10
|
+
|
10
11
|
singlepara = node.elements.size == 1 && node.elements.first.name == "p"
|
11
12
|
state[:tdsinglepara] = singlepara if singlepara
|
13
|
+
|
12
14
|
adoccell = node.at(".//ul | .//ol | .//pre | .//blockquote | .//br | .//hr") ||
|
13
15
|
node.at(".//p") && !singlepara
|
16
|
+
|
14
17
|
style = "a" if adoccell
|
15
18
|
delim = adoccell ? "\n" : " "
|
16
|
-
content =
|
17
|
-
|
19
|
+
content = treat_children_coradoc(node, state)
|
20
|
+
options = {}.tap do |hash|
|
21
|
+
hash[:id] = id
|
22
|
+
hash[:colrowattr] = colrowattr
|
23
|
+
hash[:alignattr] = alignattr
|
24
|
+
hash[:style] = style
|
25
|
+
hash[:content] = content
|
26
|
+
hash[:delim] = delim
|
27
|
+
end
|
28
|
+
|
29
|
+
Coradoc::Element::Table::Cell.new(options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def convert(node, state = {})
|
33
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
18
34
|
end
|
19
35
|
|
20
|
-
def cellstyle(
|
36
|
+
def cellstyle(_node)
|
21
37
|
""
|
22
38
|
end
|
23
39
|
|
24
40
|
def colrow(colspan, rowspan)
|
25
|
-
if colspan && rowspan
|
41
|
+
if colspan && rowspan && colspan != "1" && rowspan != "1"
|
26
42
|
"#{colspan}.#{rowspan}+"
|
27
|
-
elsif colspan
|
43
|
+
elsif colspan && colspan != "1"
|
28
44
|
"#{colspan}+"
|
29
|
-
elsif rowspan
|
45
|
+
elsif rowspan && rowspan != "1"
|
30
46
|
".#{rowspan}+"
|
31
47
|
else
|
32
48
|
""
|
@@ -37,16 +53,16 @@ module ReverseAdoc
|
|
37
53
|
align = node["align"]
|
38
54
|
valign = node["valign"]
|
39
55
|
a = case align
|
40
|
-
|
41
|
-
|
42
|
-
|
56
|
+
when "left" then "<"
|
57
|
+
when "center" then "^"
|
58
|
+
when "right" then ">"
|
43
59
|
else
|
44
60
|
""
|
45
61
|
end
|
46
62
|
v = case valign
|
47
|
-
|
48
|
-
|
49
|
-
|
63
|
+
when "top" then "<"
|
64
|
+
when "middle" then "^"
|
65
|
+
when "bottom" then ">"
|
50
66
|
else
|
51
67
|
""
|
52
68
|
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Text < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
return treat_empty(node, state) if node.text.strip.empty?
|
6
|
+
|
7
|
+
Coradoc::Element::TextElement.new(treat_text(node))
|
8
|
+
end
|
9
|
+
|
4
10
|
def convert(node, state = {})
|
5
|
-
|
6
|
-
treat_empty(node, state)
|
7
|
-
else
|
8
|
-
treat_text(node)
|
9
|
-
end
|
11
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
13
15
|
|
14
16
|
def treat_empty(node, state)
|
15
17
|
parent = node.parent.name.to_sym
|
16
|
-
if [
|
17
|
-
|
18
|
+
if %i[ol ul].include?(parent) # Otherwise the identation is broken
|
19
|
+
""
|
18
20
|
elsif state[:tdsinglepara]
|
19
|
-
|
20
|
-
elsif node.text ==
|
21
|
-
|
21
|
+
""
|
22
|
+
elsif node.text == " " # Regular whitespace text node
|
23
|
+
" "
|
22
24
|
else
|
23
|
-
|
25
|
+
""
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -44,16 +46,16 @@ module ReverseAdoc
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def remove_border_newlines(text)
|
47
|
-
text.gsub(/\A\n+/,
|
49
|
+
text.gsub(/\A\n+/, "").gsub(/\n+\z/, "")
|
48
50
|
end
|
49
51
|
|
50
52
|
def remove_inner_newlines(text)
|
51
|
-
text.tr("\n\t",
|
53
|
+
text.tr("\n\t", " ").squeeze(" ")
|
52
54
|
end
|
53
55
|
|
54
56
|
def preserve_keychars_within_backticks(text)
|
55
57
|
text.gsub(/`.*?`/) do |match|
|
56
|
-
match.gsub('\_',
|
58
|
+
match.gsub('\_', "_").gsub('\*', "*")
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -2,12 +2,10 @@ module ReverseAdoc
|
|
2
2
|
module Converters
|
3
3
|
class Th < Td
|
4
4
|
def cellstyle(node)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
"h"
|
10
|
-
end
|
5
|
+
# this is the header row
|
6
|
+
return "" if node.parent.previous_element.nil?
|
7
|
+
|
8
|
+
"h"
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Tr < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
content = treat_children_coradoc(node, state)
|
6
|
+
header = table_header_row?(node)
|
7
|
+
Coradoc::Element::Table::Row.new(content, header)
|
8
|
+
end
|
9
|
+
|
4
10
|
def convert(node, state = {})
|
5
|
-
|
6
|
-
result = "#{content}\n"
|
7
|
-
table_header_row?(node) ? result + underline_for(node) : result
|
11
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
8
12
|
end
|
9
13
|
|
10
14
|
def table_header_row?(node)
|
11
15
|
# node.element_children.all? {|child| child.name.to_sym == :th}
|
12
16
|
node.previous_element.nil?
|
13
17
|
end
|
14
|
-
|
15
|
-
def underline_for(node)
|
16
|
-
"\n"
|
17
|
-
end
|
18
18
|
end
|
19
19
|
|
20
20
|
register :tr, Tr.new
|
@@ -1,33 +1,26 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Video < Base
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
controls = node['controls']
|
8
|
-
src = node['src']
|
9
|
-
id = node['id']
|
10
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
4
|
+
def to_coradoc(node, _state = {})
|
5
|
+
src = node["src"]
|
6
|
+
id = node["id"]
|
11
7
|
title = extract_title(node)
|
12
|
-
|
13
|
-
|
8
|
+
attributes = Coradoc::Element::AttributeList.new
|
9
|
+
options = options(node)
|
10
|
+
attributes.add_named("options", options) if options.any?
|
11
|
+
Coradoc::Element::Video.new(title, id: id, src: src,
|
12
|
+
attributes: attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def convert(node, state = {})
|
16
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
14
17
|
end
|
15
18
|
|
16
19
|
def options(node)
|
17
|
-
autoplay
|
18
|
-
loop_attr
|
19
|
-
controls
|
20
|
-
|
21
|
-
ret = ""
|
22
|
-
if autoplay || loop_attr || controls
|
23
|
-
out = []
|
24
|
-
out << "autoplay" if autoplay
|
25
|
-
out << "loop" if loop_attr
|
26
|
-
out << "controls" if controls
|
27
|
-
out << "width=#{width}" if width
|
28
|
-
ret = %{options="#{out.join(',')}"}
|
29
|
-
end
|
30
|
-
ret
|
20
|
+
autoplay = node["autoplay"]
|
21
|
+
loop_attr = node["loop"]
|
22
|
+
controls = node["controls"]
|
23
|
+
[autoplay, loop_attr, controls].compact
|
31
24
|
end
|
32
25
|
end
|
33
26
|
|
@@ -13,8 +13,6 @@ module ReverseAdoc
|
|
13
13
|
@@converters[tag_name.to_sym] or default_converter(tag_name)
|
14
14
|
end
|
15
15
|
|
16
|
-
private
|
17
|
-
|
18
16
|
def self.default_converter(tag_name)
|
19
17
|
case ReverseAdoc.config.unknown_tags.to_sym
|
20
18
|
when :pass_through
|
@@ -26,7 +24,8 @@ module ReverseAdoc
|
|
26
24
|
when :raise
|
27
25
|
raise UnknownTagError, "unknown tag: #{tag_name}"
|
28
26
|
else
|
29
|
-
raise InvalidConfigurationError,
|
27
|
+
raise InvalidConfigurationError,
|
28
|
+
"unknown value #{ReverseAdoc.config.unknown_tags.inspect} for ReverseAdoc.config.unknown_tags"
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -1,56 +1,61 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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
|
-
|
3
|
+
require_relative "converters/a"
|
4
|
+
require_relative "converters/aside"
|
5
|
+
require_relative "converters/audio"
|
6
|
+
require_relative "converters/blockquote"
|
7
|
+
require_relative "converters/br"
|
8
|
+
require_relative "converters/bypass"
|
9
|
+
require_relative "converters/code"
|
10
|
+
require_relative "converters/div"
|
11
|
+
require_relative "converters/drop"
|
12
|
+
require_relative "converters/em"
|
13
|
+
require_relative "converters/figure"
|
14
|
+
require_relative "converters/h"
|
15
|
+
require_relative "converters/head"
|
16
|
+
require_relative "converters/hr"
|
17
|
+
require_relative "converters/ignore"
|
18
|
+
require_relative "converters/img"
|
19
|
+
require_relative "converters/mark"
|
20
|
+
require_relative "converters/li"
|
21
|
+
require_relative "converters/ol"
|
22
|
+
require_relative "converters/p"
|
23
|
+
require_relative "converters/pass_through"
|
24
|
+
require_relative "converters/pre"
|
25
|
+
require_relative "converters/q"
|
26
|
+
require_relative "converters/strong"
|
27
|
+
require_relative "converters/sup"
|
28
|
+
require_relative "converters/sub"
|
29
|
+
require_relative "converters/table"
|
30
|
+
require_relative "converters/td"
|
31
|
+
require_relative "converters/th"
|
32
|
+
require_relative "converters/text"
|
33
|
+
require_relative "converters/tr"
|
34
|
+
require_relative "converters/video"
|
35
|
+
require_relative "converters/math"
|
36
36
|
|
37
37
|
module ReverseAdoc
|
38
38
|
class HtmlConverter
|
39
|
-
def self.
|
40
|
-
root =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
def self.to_coradoc(input, options = {})
|
40
|
+
root = case input
|
41
|
+
when String
|
42
|
+
Nokogiri::HTML(input).root
|
43
|
+
when Nokogiri::XML::Document
|
44
|
+
input.root
|
45
|
+
when Nokogiri::XML::Node
|
46
|
+
input
|
46
47
|
end
|
47
48
|
|
48
|
-
|
49
|
+
return "" unless root
|
49
50
|
|
50
51
|
ReverseAdoc.config.with(options) do
|
51
|
-
|
52
|
-
ReverseAdoc.cleaner.tidy(result)
|
52
|
+
ReverseAdoc::Converters.lookup(root.name).to_coradoc(root)
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
def self.convert(input, options = {})
|
57
|
+
result = Coradoc::Generator.gen_adoc(to_coradoc(input, options))
|
58
|
+
ReverseAdoc.cleaner.tidy(result)
|
59
|
+
end
|
55
60
|
end
|
56
61
|
end
|
data/lib/reverse_adoc/version.rb
CHANGED
data/lib/reverse_adoc.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
require "digest"
|
4
|
+
require "nokogiri"
|
5
|
+
require_relative "reverse_adoc/version"
|
6
|
+
require_relative "reverse_adoc/errors"
|
7
|
+
require_relative "reverse_adoc/cleaner"
|
8
|
+
require_relative "reverse_adoc/config"
|
9
|
+
require_relative "reverse_adoc/converters"
|
10
|
+
require_relative "reverse_adoc/converters/base"
|
11
|
+
require_relative "reverse_adoc/html_converter"
|
12
12
|
|
13
13
|
module ReverseAdoc
|
14
14
|
def self.convert(input, options = {})
|