reverse_adoc 0.3.6 → 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 +19 -19
- 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 +6 -3
- 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 +21 -16
- 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 +20 -6
@@ -1,8 +1,12 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Bypass < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
treat_children_coradoc(node, state)
|
6
|
+
end
|
7
|
+
|
4
8
|
def convert(node, state = {})
|
5
|
-
|
9
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
@@ -13,65 +17,65 @@ module ReverseAdoc
|
|
13
17
|
register :thead, Bypass.new
|
14
18
|
register :tbody, Bypass.new
|
15
19
|
register :tfoot, Bypass.new
|
16
|
-
register :abbr,
|
20
|
+
register :abbr, Bypass.new
|
17
21
|
register :acronym, Bypass.new
|
18
22
|
register :address, Bypass.new
|
19
|
-
register :applet,
|
20
|
-
register :map,
|
21
|
-
register :area,
|
23
|
+
register :applet, Bypass.new
|
24
|
+
register :map, Bypass.new
|
25
|
+
register :area, Bypass.new
|
22
26
|
register :bdi, Bypass.new
|
23
27
|
register :bdo, Bypass.new
|
24
28
|
register :big, Bypass.new
|
25
29
|
register :button, Bypass.new
|
26
30
|
register :canvas, Bypass.new
|
27
|
-
register :data,
|
28
|
-
register :datalist,
|
31
|
+
register :data, Bypass.new
|
32
|
+
register :datalist, Bypass.new
|
29
33
|
register :del, Bypass.new
|
30
34
|
register :ins, Bypass.new
|
31
35
|
register :dfn, Bypass.new
|
32
|
-
register :dialog,
|
33
|
-
register :embed,
|
34
|
-
register :fieldset,
|
35
|
-
register :font,
|
36
|
-
register :footer,
|
37
|
-
register :form,
|
38
|
-
register :frame,
|
39
|
-
register :frameset,
|
36
|
+
register :dialog, Bypass.new
|
37
|
+
register :embed, Bypass.new
|
38
|
+
register :fieldset, Bypass.new
|
39
|
+
register :font, Bypass.new
|
40
|
+
register :footer, Bypass.new
|
41
|
+
register :form, Bypass.new
|
42
|
+
register :frame, Bypass.new
|
43
|
+
register :frameset, Bypass.new
|
40
44
|
register :header, Bypass.new
|
41
45
|
register :iframe, Bypass.new
|
42
46
|
register :input, Bypass.new
|
43
47
|
register :label, Bypass.new
|
44
|
-
register :legend,
|
48
|
+
register :legend, Bypass.new
|
45
49
|
register :main, Bypass.new
|
46
50
|
register :menu, Bypass.new
|
47
|
-
register :menulist,
|
48
|
-
register :meter,
|
49
|
-
register :nav,
|
51
|
+
register :menulist, Bypass.new
|
52
|
+
register :meter, Bypass.new
|
53
|
+
register :nav, Bypass.new
|
50
54
|
register :noframes, Bypass.new
|
51
55
|
register :noscript, Bypass.new
|
52
|
-
register :object,
|
53
|
-
register :optgroup,
|
56
|
+
register :object, Bypass.new
|
57
|
+
register :optgroup, Bypass.new
|
54
58
|
register :option, Bypass.new
|
55
59
|
register :output, Bypass.new
|
56
|
-
register :param,
|
57
|
-
register :picture,
|
58
|
-
register :progress,
|
59
|
-
register :ruby,
|
60
|
+
register :param, Bypass.new
|
61
|
+
register :picture, Bypass.new
|
62
|
+
register :progress, Bypass.new
|
63
|
+
register :ruby, Bypass.new
|
60
64
|
register :rt, Bypass.new
|
61
65
|
register :rp, Bypass.new
|
62
|
-
register :s,
|
63
|
-
register :select,
|
64
|
-
register :small,
|
65
|
-
register :span,
|
66
|
-
register :strike,
|
66
|
+
register :s, Bypass.new
|
67
|
+
register :select, Bypass.new
|
68
|
+
register :small, Bypass.new
|
69
|
+
register :span, Bypass.new
|
70
|
+
register :strike, Bypass.new
|
67
71
|
register :details, Bypass.new
|
68
72
|
register :section, Bypass.new
|
69
73
|
register :summary, Bypass.new
|
70
|
-
register :svg,
|
74
|
+
register :svg, Bypass.new
|
71
75
|
register :template, Bypass.new
|
72
76
|
register :textarea, Bypass.new
|
73
|
-
register :track,
|
74
|
-
register :u,
|
75
|
-
register :wbr,
|
77
|
+
register :track, Bypass.new
|
78
|
+
register :u, Bypass.new
|
79
|
+
register :wbr, Bypass.new
|
76
80
|
end
|
77
81
|
end
|
@@ -1,8 +1,49 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Code < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
content = treat_children_coradoc(node, state)
|
6
|
+
|
7
|
+
if Coradoc::Generator.gen_adoc(content).strip.empty?
|
8
|
+
return ""
|
9
|
+
end
|
10
|
+
|
11
|
+
if node_has_ancestor?(node, ["code", "tt", "kbd", "samp", "var"])
|
12
|
+
return content
|
13
|
+
end
|
14
|
+
|
15
|
+
node.text =~ /^(\s+)/
|
16
|
+
leading_whitespace = $1
|
17
|
+
has_leading_whitespace = !leading_whitespace.nil?
|
18
|
+
|
19
|
+
if has_leading_whitespace
|
20
|
+
first_text = node.at_xpath("./text()[1]")
|
21
|
+
first_text.replace(first_text.text.lstrip)
|
22
|
+
leading_whitespace = " "
|
23
|
+
end
|
24
|
+
|
25
|
+
node.text =~ /(\s+)$/
|
26
|
+
trailing_whitespace = $1
|
27
|
+
has_trailing_whitespace = !trailing_whitespace.nil?
|
28
|
+
|
29
|
+
if has_trailing_whitespace
|
30
|
+
last_text = node.at_xpath("./text()[last()]")
|
31
|
+
last_text.replace(last_text.text.rstrip)
|
32
|
+
trailing_whitespace = " "
|
33
|
+
end
|
34
|
+
|
35
|
+
u_before = unconstrained_before?(node)
|
36
|
+
u_after = unconstrained_after?(node)
|
37
|
+
u = !((!u_before || has_leading_whitespace) && (!u_after || has_trailing_whitespace))
|
38
|
+
e = Coradoc::Element::Inline::Monospace.new(
|
39
|
+
Coradoc::Element::TextElement.new(content), u
|
40
|
+
)
|
41
|
+
|
42
|
+
[leading_whitespace, e, trailing_whitespace]
|
43
|
+
end
|
44
|
+
|
4
45
|
def convert(node, state = {})
|
5
|
-
|
46
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
6
47
|
end
|
7
48
|
end
|
8
49
|
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Div < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
id = node["id"]
|
6
|
+
contents = treat_children_coradoc(node, state)
|
7
|
+
Coradoc::Element::Section.new(nil, id: id, contents: contents)
|
8
|
+
end
|
9
|
+
|
4
10
|
def convert(node, state = {})
|
5
|
-
|
6
|
-
anchor = id ? "[[#{id}]]\n" : ""
|
7
|
-
"\n#{anchor}" << treat_children(node, state) << "\n"
|
11
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
8
12
|
end
|
9
13
|
end
|
10
14
|
|
@@ -1,18 +1,55 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Em < 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_italic: true))
|
7
|
+
|
8
|
+
if Coradoc::Generator.gen_adoc(content).strip.empty?
|
9
|
+
return ""
|
10
|
+
end
|
11
|
+
|
12
|
+
if node_has_ancestor?(node, ["em", "i", "cite"])
|
13
|
+
return content
|
10
14
|
end
|
15
|
+
|
16
|
+
node.text =~ /^(\s+)/
|
17
|
+
leading_whitespace = $1
|
18
|
+
has_leading_whitespace = !leading_whitespace.nil?
|
19
|
+
|
20
|
+
if has_leading_whitespace
|
21
|
+
first_text = node.at_xpath("./text()[1]")
|
22
|
+
first_text.replace(first_text.text.lstrip)
|
23
|
+
leading_whitespace = " "
|
24
|
+
end
|
25
|
+
|
26
|
+
node.text =~ /(\s+)$/
|
27
|
+
trailing_whitespace = $1
|
28
|
+
has_trailing_whitespace = !trailing_whitespace.nil?
|
29
|
+
|
30
|
+
if has_trailing_whitespace
|
31
|
+
last_text = node.at_xpath("./text()[last()]")
|
32
|
+
last_text.replace(last_text.text.rstrip)
|
33
|
+
trailing_whitespace = " "
|
34
|
+
end
|
35
|
+
|
36
|
+
u_before = unconstrained_before?(node)
|
37
|
+
u_after = unconstrained_after?(node)
|
38
|
+
u = !((!u_before || has_leading_whitespace) && (!u_after || has_trailing_whitespace))
|
39
|
+
e = Coradoc::Element::Inline::Italic.new(
|
40
|
+
Coradoc::Element::TextElement.new(content), u
|
41
|
+
)
|
42
|
+
|
43
|
+
[leading_whitespace, e, trailing_whitespace]
|
44
|
+
end
|
45
|
+
|
46
|
+
def convert(node, state = {})
|
47
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
11
48
|
end
|
12
49
|
end
|
13
50
|
|
14
51
|
register :em, Em.new
|
15
52
|
register :i, Em.new
|
16
|
-
register :cite,
|
53
|
+
register :cite, Em.new
|
17
54
|
end
|
18
55
|
end
|
@@ -1,18 +1,22 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Figure < 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
|
-
|
9
|
-
|
7
|
+
content = treat_children_coradoc(node, state)
|
8
|
+
Coradoc::Element::Block::Example.new(title, lines: content, id: id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def convert(node, state = {})
|
12
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
10
13
|
end
|
11
14
|
|
12
15
|
def extract_title(node)
|
13
16
|
title = node.at("./figcaption")
|
14
17
|
return "" if title.nil?
|
15
|
-
|
18
|
+
|
19
|
+
treat_children_coradoc(title, {})
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
@@ -1,25 +1,33 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class H < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
id = node["id"]
|
6
|
+
internal_anchor = treat_children_anchors(node, state)
|
7
|
+
|
8
|
+
if id.to_s.empty? && internal_anchor.size.positive?
|
9
|
+
id = internal_anchor.first.id
|
10
|
+
end
|
11
|
+
|
12
|
+
level = node.name[/\d/].to_i
|
13
|
+
content = treat_children_no_anchors(node, state)
|
14
|
+
|
15
|
+
Coradoc::Element::Title.new(content, level, id: id)
|
16
|
+
end
|
17
|
+
|
4
18
|
def convert(node, state = {})
|
5
|
-
|
6
|
-
anchor = id ? "[[#{id}]]" : ""
|
7
|
-
internal_anchor = treat_children_anchors(node, state) || ""
|
8
|
-
anchor.empty? and anchor = internal_anchor
|
9
|
-
anchor.empty? or anchor += "\n"
|
10
|
-
prefix = '=' * (node.name[/\d/].to_i + 1)
|
11
|
-
["\n", anchor, prefix, ' ', treat_children_no_anchors(node, state), "\n"].join
|
19
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
12
20
|
end
|
13
21
|
|
14
22
|
def treat_children_no_anchors(node, state)
|
15
|
-
node.children.reject { |a| a.name == "a" }.inject(
|
16
|
-
memo <<
|
23
|
+
node.children.reject { |a| a.name == "a" }.inject([]) do |memo, child|
|
24
|
+
memo << treat_coradoc(child, state)
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
28
|
def treat_children_anchors(node, state)
|
21
|
-
node.children.select { |a| a.name == "a" }.inject(
|
22
|
-
memo <<
|
29
|
+
node.children.select { |a| a.name == "a" }.inject([]) do |memo, child|
|
30
|
+
memo << treat_coradoc(child, state)
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -1,14 +1,19 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Head < Base
|
4
|
-
def
|
4
|
+
def to_coradoc(node, _state = {})
|
5
5
|
title = extract_title(node)
|
6
|
-
|
6
|
+
Coradoc::Element::Header.new(title)
|
7
|
+
end
|
8
|
+
|
9
|
+
def convert(node, state = {})
|
10
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
7
11
|
end
|
8
12
|
|
9
13
|
def extract_title(node)
|
10
14
|
title = node.at("./title")
|
11
15
|
return "(???)" if title.nil?
|
16
|
+
|
12
17
|
title.text
|
13
18
|
end
|
14
19
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Hr < Base
|
4
|
+
def to_coradoc(_node, _state = {})
|
5
|
+
Coradoc::Element::Break::ThematicBreak.new
|
6
|
+
end
|
7
|
+
|
4
8
|
def convert(node, state = {})
|
5
|
-
|
9
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
@@ -7,11 +7,10 @@ require "marcel"
|
|
7
7
|
module ReverseAdoc
|
8
8
|
module Converters
|
9
9
|
class Img < Base
|
10
|
-
|
11
10
|
def image_number
|
12
11
|
sprintf(
|
13
12
|
ReverseAdoc.config.image_counter_pattern,
|
14
|
-
ReverseAdoc.config.image_counter
|
13
|
+
ReverseAdoc.config.image_counter,
|
15
14
|
)
|
16
15
|
end
|
17
16
|
|
@@ -20,10 +19,10 @@ module ReverseAdoc
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def datauri2file(src)
|
23
|
-
%r{^data:image/(
|
22
|
+
%r{^data:image/(?:[^;]+);base64,(?<imgdata>.+)$} =~ src
|
24
23
|
|
25
24
|
dest_dir = Pathname.new(ReverseAdoc.config.destination).dirname
|
26
|
-
images_dir = dest_dir
|
25
|
+
images_dir = dest_dir.join("images")
|
27
26
|
FileUtils.mkdir_p(images_dir)
|
28
27
|
|
29
28
|
ext, image_src_path = determine_image_src_path(src, imgdata)
|
@@ -42,11 +41,11 @@ module ReverseAdoc
|
|
42
41
|
return copy_temp_file(imgdata) if imgdata
|
43
42
|
|
44
43
|
ext = File.extname(src).strip.downcase[1..-1]
|
45
|
-
[ext, Pathname.new(ReverseAdoc.config.sourcedir)
|
44
|
+
[ext, Pathname.new(ReverseAdoc.config.sourcedir).join(src)]
|
46
45
|
end
|
47
46
|
|
48
47
|
def copy_temp_file(imgdata)
|
49
|
-
Tempfile.open([
|
48
|
+
Tempfile.open(["radoc", ".jpg"]) do |f|
|
50
49
|
f.binmode
|
51
50
|
f.write(Base64.strict_decode64(imgdata))
|
52
51
|
f.rewind
|
@@ -55,13 +54,13 @@ module ReverseAdoc
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
width = node[
|
63
|
-
height = node[
|
64
|
-
|
57
|
+
def to_coradoc(node, _state = {})
|
58
|
+
id = node["id"]
|
59
|
+
alt = node["alt"]
|
60
|
+
src = node["src"]
|
61
|
+
width = node["width"]
|
62
|
+
height = node["height"]
|
63
|
+
|
65
64
|
title = extract_title(node)
|
66
65
|
|
67
66
|
if ReverseAdoc.config.external_images
|
@@ -69,12 +68,23 @@ module ReverseAdoc
|
|
69
68
|
src = datauri2file(src)
|
70
69
|
end
|
71
70
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
attributes = Coradoc::Element::AttributeList.new
|
72
|
+
# attributes.add_named("id", id) if id
|
73
|
+
if alt # && !alt.to_s.empty?
|
74
|
+
attributes.add_positional(alt)
|
75
|
+
elsif width || height
|
76
|
+
attributes.add_positional("\"\"")
|
77
|
+
end
|
78
|
+
# attributes.add_named("title", title) if title
|
79
|
+
attributes.add_positional(width) if width
|
80
|
+
attributes.add_positional(height) if height
|
81
|
+
|
82
|
+
Coradoc::Element::Image::BlockImage.new(title, id, src,
|
83
|
+
attributes: attributes)
|
84
|
+
end
|
85
|
+
|
86
|
+
def convert(node, state = {})
|
87
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
@@ -1,21 +1,14 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Li < Base
|
4
|
-
def
|
5
|
-
id = node[
|
6
|
-
|
7
|
-
content
|
8
|
-
prefix = prefix_for(node, state)
|
9
|
-
"#{prefix} #{anchor}#{content.chomp}\n"
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
id = node["id"]
|
6
|
+
content = treat_children_coradoc(node, state)
|
7
|
+
Coradoc::Element::ListItem.new(content, id: id)
|
10
8
|
end
|
11
9
|
|
12
|
-
def
|
13
|
-
|
14
|
-
if node.parent.name == 'ol'
|
15
|
-
"." * [length, 0].max
|
16
|
-
else
|
17
|
-
"*" * [length, 0].max
|
18
|
-
end
|
10
|
+
def convert(node, state = {})
|
11
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
19
12
|
end
|
20
13
|
end
|
21
14
|
|
@@ -1,9 +1,18 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Mark < Base
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
content = treat_children(node, state.merge(already_strong: true))
|
6
|
+
|
7
|
+
if content.strip.empty? || state[:already_strong]
|
8
|
+
return content
|
9
|
+
end
|
10
|
+
|
11
|
+
Coradoc::Element::Inline::Highlight.new(content, constrained?(node))
|
12
|
+
end
|
13
|
+
|
4
14
|
def convert(node, state = {})
|
5
|
-
|
6
|
-
"#{content[/^\s*/]}##{content.strip}##{content[/\s*$/]}"
|
15
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
7
16
|
end
|
8
17
|
end
|
9
18
|
|
@@ -7,10 +7,21 @@ require "mathml2asciimath"
|
|
7
7
|
module ReverseAdoc
|
8
8
|
module Converters
|
9
9
|
class Math < Base
|
10
|
-
|
10
|
+
# FIXIT
|
11
|
+
def to_coradoc(node, state = {})
|
12
|
+
convert(node, state)
|
13
|
+
end
|
14
|
+
|
15
|
+
def convert(node, _state = {})
|
11
16
|
stem = node.to_s.gsub(/\n/, " ")
|
12
17
|
stem = MathML2AsciiMath.m2a(stem) if ReverseAdoc.config.mathml2asciimath
|
13
|
-
|
18
|
+
unless stem.nil?
|
19
|
+
stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(
|
20
|
+
/\(\(([^\)]+)\)\)/, "(\\1)"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO: This is to be done in Coradoc
|
14
25
|
" stem:[" << stem << "] "
|
15
26
|
end
|
16
27
|
end
|
@@ -1,41 +1,59 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class Ol < Base
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
# FIXIT
|
5
|
+
def to_coradoc(node, state = {})
|
6
|
+
# convert(node, state)
|
7
|
+
id = node["id"]
|
7
8
|
ol_count = state.fetch(:ol_count, 0) + 1
|
8
9
|
attrs = ol_attrs(node)
|
9
|
-
|
10
|
+
items = treat_children_coradoc(node, state.merge(ol_count: ol_count))
|
11
|
+
|
12
|
+
options = {}.tap do |hash|
|
13
|
+
hash[:id] = id
|
14
|
+
hash[:ol_count] = ol_count
|
15
|
+
hash[:attrs] = attrs
|
16
|
+
end
|
17
|
+
|
18
|
+
case get_list_type(node, state)
|
19
|
+
when :ordered
|
20
|
+
Coradoc::Element::List::Ordered.new(items, options)
|
21
|
+
when :unordered
|
22
|
+
Coradoc::Element::List::Unordered.new(items, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def convert(node, state = {})
|
27
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_list_type(node, _state)
|
31
|
+
case node.name
|
32
|
+
when "ol"
|
33
|
+
:ordered
|
34
|
+
when "ul"
|
35
|
+
:unordered
|
36
|
+
end
|
10
37
|
end
|
11
38
|
|
12
39
|
def number_style(node)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
nil
|
21
|
-
end
|
40
|
+
case node["style"]
|
41
|
+
when "1" then "arabic"
|
42
|
+
when "A" then "upperalpha"
|
43
|
+
when "a" then "loweralpha"
|
44
|
+
when "I" then "upperroman"
|
45
|
+
when "i" then "lowerroman"
|
46
|
+
end
|
22
47
|
end
|
23
48
|
|
24
49
|
def ol_attrs(node)
|
50
|
+
attrs = Coradoc::Element::AttributeList.new
|
25
51
|
style = number_style(node)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
attrs
|
30
|
-
attrs
|
31
|
-
attrs << reversed if reversed
|
32
|
-
attrs << start if start
|
33
|
-
attrs << type if type
|
34
|
-
if attrs.empty?
|
35
|
-
""
|
36
|
-
else
|
37
|
-
"[#{attrs.join(',')}]\n"
|
38
|
-
end
|
52
|
+
attrs.add_positional(style) if style
|
53
|
+
attrs.add_positional("%reversed") if node["reversed"]
|
54
|
+
attrs.add_named("start", node["start"]) if node["start"]
|
55
|
+
attrs.add_named("type", node["type"]) if node["type"]
|
56
|
+
attrs
|
39
57
|
end
|
40
58
|
end
|
41
59
|
|
@@ -1,14 +1,20 @@
|
|
1
1
|
module ReverseAdoc
|
2
2
|
module Converters
|
3
3
|
class P < Base
|
4
|
-
def
|
5
|
-
id = node[
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
def to_coradoc(node, state = {})
|
5
|
+
id = node["id"]
|
6
|
+
content = treat_children_coradoc(node, state)
|
7
|
+
|
8
|
+
options = {}.tap do |hash|
|
9
|
+
hash[:id] = id if id
|
10
|
+
hash[:tdsinglepara] = true if state[:tdsinglepara]
|
11
11
|
end
|
12
|
+
|
13
|
+
Coradoc::Element::Paragraph.new(content, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def convert(node, state = {})
|
17
|
+
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|