reverse_adoc 0.3.7 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +4 -3
  3. data/Gemfile +1 -1
  4. data/Rakefile +7 -7
  5. data/exe/reverse_adoc +11 -11
  6. data/exe/w2a +15 -16
  7. data/lib/reverse_adoc/cleaner.rb +18 -19
  8. data/lib/reverse_adoc/config.rb +7 -7
  9. data/lib/reverse_adoc/converters/a.rb +24 -24
  10. data/lib/reverse_adoc/converters/aside.rb +6 -4
  11. data/lib/reverse_adoc/converters/audio.rb +16 -21
  12. data/lib/reverse_adoc/converters/base.rb +79 -5
  13. data/lib/reverse_adoc/converters/blockquote.rb +16 -7
  14. data/lib/reverse_adoc/converters/br.rb +5 -1
  15. data/lib/reverse_adoc/converters/bypass.rb +38 -34
  16. data/lib/reverse_adoc/converters/code.rb +42 -1
  17. data/lib/reverse_adoc/converters/div.rb +7 -3
  18. data/lib/reverse_adoc/converters/drop.rb +6 -2
  19. data/lib/reverse_adoc/converters/em.rb +44 -7
  20. data/lib/reverse_adoc/converters/figure.rb +10 -6
  21. data/lib/reverse_adoc/converters/h.rb +19 -11
  22. data/lib/reverse_adoc/converters/head.rb +7 -2
  23. data/lib/reverse_adoc/converters/hr.rb +5 -1
  24. data/lib/reverse_adoc/converters/ignore.rb +6 -2
  25. data/lib/reverse_adoc/converters/img.rb +29 -19
  26. data/lib/reverse_adoc/converters/li.rb +6 -13
  27. data/lib/reverse_adoc/converters/mark.rb +11 -2
  28. data/lib/reverse_adoc/converters/math.rb +13 -2
  29. data/lib/reverse_adoc/converters/ol.rb +44 -26
  30. data/lib/reverse_adoc/converters/p.rb +13 -7
  31. data/lib/reverse_adoc/converters/pass_through.rb +5 -1
  32. data/lib/reverse_adoc/converters/pre.rb +23 -10
  33. data/lib/reverse_adoc/converters/q.rb +6 -2
  34. data/lib/reverse_adoc/converters/strong.rb +41 -6
  35. data/lib/reverse_adoc/converters/sub.rb +6 -2
  36. data/lib/reverse_adoc/converters/sup.rb +6 -2
  37. data/lib/reverse_adoc/converters/table.rb +28 -23
  38. data/lib/reverse_adoc/converters/td.rb +32 -16
  39. data/lib/reverse_adoc/converters/text.rb +16 -14
  40. data/lib/reverse_adoc/converters/th.rb +4 -6
  41. data/lib/reverse_adoc/converters/tr.rb +7 -7
  42. data/lib/reverse_adoc/converters/video.rb +16 -23
  43. data/lib/reverse_adoc/converters.rb +2 -3
  44. data/lib/reverse_adoc/html_converter.rb +48 -43
  45. data/lib/reverse_adoc/version.rb +1 -1
  46. data/lib/reverse_adoc.rb +9 -9
  47. data/reverse_adoc.gemspec +4 -1
  48. data/spec/assets/basic.html +3 -0
  49. data/spec/bin/reverse_adoc_spec.rb +9 -8
  50. data/spec/bin/w2a_spec.rb +12 -12
  51. data/spec/components/anchors_spec.rb +18 -12
  52. data/spec/components/basic_spec.rb +28 -14
  53. data/spec/components/code_spec.rb +2 -4
  54. data/spec/components/escapables_spec.rb +4 -6
  55. data/spec/components/from_the_wild_spec.rb +2 -4
  56. data/spec/components/html_fragment_spec.rb +2 -3
  57. data/spec/components/lists_spec.rb +12 -8
  58. data/spec/components/paragraphs_spec.rb +2 -3
  59. data/spec/components/quotation_spec.rb +5 -5
  60. data/spec/components/tables_spec.rb +22 -11
  61. data/spec/components/unknown_tags_spec.rb +13 -10
  62. data/spec/lib/reverse_adoc/cleaner_spec.rb +70 -71
  63. data/spec/lib/reverse_adoc/config_spec.rb +5 -6
  64. data/spec/lib/reverse_adoc/converters/aside_spec.rb +2 -3
  65. data/spec/lib/reverse_adoc/converters/audio_spec.rb +3 -5
  66. data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +5 -6
  67. data/spec/lib/reverse_adoc/converters/br_spec.rb +2 -2
  68. data/spec/lib/reverse_adoc/converters/code_spec.rb +3 -5
  69. data/spec/lib/reverse_adoc/converters/div_spec.rb +3 -5
  70. data/spec/lib/reverse_adoc/converters/figure_spec.rb +2 -4
  71. data/spec/lib/reverse_adoc/converters/img_spec.rb +5 -7
  72. data/spec/lib/reverse_adoc/converters/li_spec.rb +2 -4
  73. data/spec/lib/reverse_adoc/converters/mark_spec.rb +4 -4
  74. data/spec/lib/reverse_adoc/converters/p_spec.rb +2 -3
  75. data/spec/lib/reverse_adoc/converters/pre_spec.rb +8 -9
  76. data/spec/lib/reverse_adoc/converters/q_spec.rb +3 -3
  77. data/spec/lib/reverse_adoc/converters/strong_spec.rb +9 -8
  78. data/spec/lib/reverse_adoc/converters/text_spec.rb +13 -14
  79. data/spec/lib/reverse_adoc/converters/video_spec.rb +7 -9
  80. data/spec/lib/reverse_adoc/converters_spec.rb +9 -6
  81. data/spec/lib/reverse_adoc.rb +25 -25
  82. data/spec/spec_helper.rb +11 -11
  83. data/spec/support/shell_helpers.rb +1 -1
  84. metadata +17 -3
@@ -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
- treat_children(node, state)
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, Bypass.new
20
+ register :abbr, Bypass.new
17
21
  register :acronym, Bypass.new
18
22
  register :address, Bypass.new
19
- register :applet, Bypass.new
20
- register :map, Bypass.new
21
- register :area, Bypass.new
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, Bypass.new
28
- register :datalist, Bypass.new
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, Bypass.new
33
- register :embed, Bypass.new
34
- register :fieldset, Bypass.new
35
- register :font, Bypass.new
36
- register :footer, Bypass.new
37
- register :form, Bypass.new
38
- register :frame, Bypass.new
39
- register :frameset, Bypass.new
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, Bypass.new
48
+ register :legend, Bypass.new
45
49
  register :main, Bypass.new
46
50
  register :menu, Bypass.new
47
- register :menulist, Bypass.new
48
- register :meter, Bypass.new
49
- register :nav, Bypass.new
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, Bypass.new
53
- register :optgroup, Bypass.new
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, Bypass.new
57
- register :picture, Bypass.new
58
- register :progress, Bypass.new
59
- register :ruby, Bypass.new
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, Bypass.new
63
- register :select, Bypass.new
64
- register :small, Bypass.new
65
- register :span, Bypass.new
66
- register :strike, Bypass.new
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, Bypass.new
74
+ register :svg, Bypass.new
71
75
  register :template, Bypass.new
72
76
  register :textarea, Bypass.new
73
- register :track, Bypass.new
74
- register :u, Bypass.new
75
- register :wbr, Bypass.new
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
- "`#{node.text}`"
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
- id = node['id']
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,8 +1,12 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Drop < Base
4
- def convert(node, state = {})
5
- ''
4
+ def to_coradoc(node, state = {})
5
+ convert(node, state)
6
+ end
7
+
8
+ def convert(_node, _state = {})
9
+ ""
6
10
  end
7
11
  end
8
12
 
@@ -1,18 +1,55 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Em < Base
4
- def convert(node, state = {})
5
- content = treat_children(node, state.merge(already_italic: true))
6
- if content.strip.empty? || state[:already_italic]
7
- content
8
- else
9
- "#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
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, Em.new
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 convert(node, state = {})
5
- id = node['id']
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
- "\n\n#{anchor}#{title}====\n" << treat_children(node, state).strip << "\n====\n\n"
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
- treat_children(title, {})
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
- id = node['id']
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('') do |memo, child|
16
- memo << treat(child, state)
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('') do |memo, child|
22
- memo << treat(child, state)
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 convert(node, state = {})
4
+ def to_coradoc(node, _state = {})
5
5
  title = extract_title(node)
6
- "= #{title}\n:stem:\n\n"
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
- "\n* * *\n"
9
+ Coradoc::Generator.gen_adoc(to_coradoc(node, state))
6
10
  end
7
11
  end
8
12
 
@@ -1,8 +1,12 @@
1
1
  module ReverseAdoc
2
2
  module Converters
3
3
  class Ignore < Base
4
- def convert(node, state = {})
5
- '' # noop
4
+ def to_coradoc(node, state = {})
5
+ convert(node, state)
6
+ end
7
+
8
+ def convert(_node, _state = {})
9
+ "" # noop
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/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ src
22
+ %r{^data:image/(?:[^;]+);base64,(?<imgdata>.+)$} =~ src
24
23
 
25
24
  dest_dir = Pathname.new(ReverseAdoc.config.destination).dirname
26
- images_dir = dest_dir + 'images'
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) + src]
44
+ [ext, Pathname.new(ReverseAdoc.config.sourcedir).join(src)]
46
45
  end
47
46
 
48
47
  def copy_temp_file(imgdata)
49
- Tempfile.open(['radoc', '.jpg']) do |f|
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 convert(node, state = {})
59
- alt = node['alt']
60
- src = node['src']
61
- id = node['id']
62
- width = node['width']
63
- height = node['height']
64
- anchor = id ? "[[#{id}]]\n" : ""
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
- title = ".#{title}\n" unless title.empty?
73
- attrs = alt
74
- attrs = "\"\"" if (width || height) && alt.nil?
75
- attrs += ",#{width}" if width
76
- attrs += ",#{height}" if width && height
77
- [anchor, title, "image::", src, "[", attrs, "]"].join("")
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 convert(node, state = {})
5
- id = node['id']
6
- anchor = id ? "[[#{id}]]" : ""
7
- content = treat_children(node, state)
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 prefix_for(node, state)
13
- length = state.fetch(:ol_count, 0)
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
- content = treat_children(node, state)
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
- def convert(node, state = {})
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
- stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(/\(\(([^\)]+)\)\)/, "(\\1)") unless stem.nil?
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
- def convert(node, state = {})
5
- id = node['id']
6
- anchor = id ? "[[#{id}]]\n" : ""
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
- "\n#{anchor}#{attrs}" << treat_children(node, state.merge(ol_count: ol_count))
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
- style = case node["style"]
14
- when "1" then "arabic"
15
- when "A" then "upperalpha"
16
- when "a" then "loweralpha"
17
- when "I" then "upperroman"
18
- when "i" then "lowerroman"
19
- else
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
- reversed = "%reversed" if node["reversed"]
27
- start = "start=#{node['start']}" if node["start"]
28
- type = "type=#{node['type']}" if node["type"]
29
- attrs = []
30
- attrs << style if style
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 convert(node, state = {})
5
- id = node['id']
6
- anchor = id ? "[[#{id}]]\n" : ""
7
- if state[:tdsinglepara]
8
- "#{anchor}" << treat_children(node, state).strip
9
- else
10
- "\n\n#{anchor}" << treat_children(node, state).strip << "\n\n"
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