coradoc 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +1 -0
  3. data/.irbrc +1 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +5 -1
  6. data/.rubocop_todo.yml +179 -0
  7. data/Gemfile +11 -0
  8. data/README.adoc +5 -7
  9. data/coradoc.gemspec +5 -16
  10. data/exe/reverse_adoc +1 -1
  11. data/exe/w2a +1 -1
  12. data/flake.lock +114 -0
  13. data/flake.nix +135 -0
  14. data/lib/coradoc/cli.rb +1 -1
  15. data/lib/coradoc/converter.rb +4 -5
  16. data/lib/coradoc/element/attribute.rb +10 -1
  17. data/lib/coradoc/element/attribute_list.rb +4 -3
  18. data/lib/coradoc/element/audio.rb +1 -1
  19. data/lib/coradoc/element/author.rb +2 -2
  20. data/lib/coradoc/element/base.rb +14 -2
  21. data/lib/coradoc/element/bibliography.rb +1 -1
  22. data/lib/coradoc/element/bibliography_entry.rb +1 -1
  23. data/lib/coradoc/element/block/open.rb +1 -1
  24. data/lib/coradoc/element/block.rb +1 -1
  25. data/lib/coradoc/element/document_attributes.rb +8 -2
  26. data/lib/coradoc/element/image/block_image.rb +3 -2
  27. data/lib/coradoc/element/image/core.rb +5 -4
  28. data/lib/coradoc/element/inline/attribute_reference.rb +19 -0
  29. data/lib/coradoc/element/inline/cross_reference.rb +4 -3
  30. data/lib/coradoc/element/inline/footnote.rb +24 -0
  31. data/lib/coradoc/element/inline/small.rb +19 -0
  32. data/lib/coradoc/element/inline/span.rb +37 -0
  33. data/lib/coradoc/element/inline/underline.rb +19 -0
  34. data/lib/coradoc/element/inline.rb +5 -1
  35. data/lib/coradoc/element/list/core.rb +2 -2
  36. data/lib/coradoc/element/list/ordered.rb +1 -0
  37. data/lib/coradoc/element/list/unordered.rb +1 -0
  38. data/lib/coradoc/element/list_item.rb +19 -20
  39. data/lib/coradoc/element/table.rb +4 -2
  40. data/lib/coradoc/element/term.rb +1 -0
  41. data/lib/coradoc/element/text_element.rb +4 -1
  42. data/lib/coradoc/element/title.rb +1 -1
  43. data/lib/coradoc/element/video.rb +2 -2
  44. data/lib/coradoc/input/adoc.rb +20 -18
  45. data/lib/coradoc/input/docx.rb +25 -23
  46. data/lib/coradoc/input/html/README.adoc +1 -1
  47. data/lib/coradoc/input/html/cleaner.rb +121 -117
  48. data/lib/coradoc/input/html/config.rb +58 -56
  49. data/lib/coradoc/input/html/converters/a.rb +44 -39
  50. data/lib/coradoc/input/html/converters/aside.rb +12 -8
  51. data/lib/coradoc/input/html/converters/audio.rb +24 -20
  52. data/lib/coradoc/input/html/converters/base.rb +103 -99
  53. data/lib/coradoc/input/html/converters/blockquote.rb +18 -14
  54. data/lib/coradoc/input/html/converters/br.rb +11 -7
  55. data/lib/coradoc/input/html/converters/bypass.rb +77 -73
  56. data/lib/coradoc/input/html/converters/code.rb +18 -14
  57. data/lib/coradoc/input/html/converters/div.rb +15 -11
  58. data/lib/coradoc/input/html/converters/dl.rb +51 -44
  59. data/lib/coradoc/input/html/converters/drop.rb +21 -17
  60. data/lib/coradoc/input/html/converters/em.rb +16 -12
  61. data/lib/coradoc/input/html/converters/figure.rb +19 -15
  62. data/lib/coradoc/input/html/converters/h.rb +32 -30
  63. data/lib/coradoc/input/html/converters/head.rb +17 -13
  64. data/lib/coradoc/input/html/converters/hr.rb +11 -7
  65. data/lib/coradoc/input/html/converters/ignore.rb +15 -11
  66. data/lib/coradoc/input/html/converters/img.rb +98 -93
  67. data/lib/coradoc/input/html/converters/li.rb +13 -9
  68. data/lib/coradoc/input/html/converters/mark.rb +14 -10
  69. data/lib/coradoc/input/html/converters/markup.rb +22 -18
  70. data/lib/coradoc/input/html/converters/math.rb +26 -19
  71. data/lib/coradoc/input/html/converters/ol.rb +55 -50
  72. data/lib/coradoc/input/html/converters/p.rb +16 -12
  73. data/lib/coradoc/input/html/converters/pass_through.rb +12 -8
  74. data/lib/coradoc/input/html/converters/pre.rb +49 -45
  75. data/lib/coradoc/input/html/converters/q.rb +12 -8
  76. data/lib/coradoc/input/html/converters/strong.rb +15 -11
  77. data/lib/coradoc/input/html/converters/sub.rb +15 -11
  78. data/lib/coradoc/input/html/converters/sup.rb +15 -11
  79. data/lib/coradoc/input/html/converters/table.rb +21 -13
  80. data/lib/coradoc/input/html/converters/td.rb +64 -60
  81. data/lib/coradoc/input/html/converters/text.rb +24 -20
  82. data/lib/coradoc/input/html/converters/th.rb +13 -9
  83. data/lib/coradoc/input/html/converters/tr.rb +17 -13
  84. data/lib/coradoc/input/html/converters/video.rb +24 -20
  85. data/lib/coradoc/input/html/converters.rb +45 -43
  86. data/lib/coradoc/input/html/errors.rb +8 -6
  87. data/lib/coradoc/input/html/html_converter.rb +93 -90
  88. data/lib/coradoc/input/html/plugin.rb +104 -104
  89. data/lib/coradoc/input/html/plugins/plateau.rb +197 -190
  90. data/lib/coradoc/input/html/postprocessor.rb +188 -182
  91. data/lib/coradoc/input/html.rb +34 -32
  92. data/lib/coradoc/oscal.rb +18 -5
  93. data/lib/coradoc/output/adoc.rb +13 -11
  94. data/lib/coradoc/output/coradoc_tree_debug.rb +15 -13
  95. data/lib/coradoc/parser/asciidoc/admonition.rb +6 -6
  96. data/lib/coradoc/parser/asciidoc/attribute_list.rb +43 -27
  97. data/lib/coradoc/parser/asciidoc/base.rb +3 -6
  98. data/lib/coradoc/parser/asciidoc/bibliography.rb +5 -6
  99. data/lib/coradoc/parser/asciidoc/block.rb +30 -31
  100. data/lib/coradoc/parser/asciidoc/citation.rb +11 -29
  101. data/lib/coradoc/parser/asciidoc/content.rb +23 -33
  102. data/lib/coradoc/parser/asciidoc/document_attributes.rb +2 -3
  103. data/lib/coradoc/parser/asciidoc/header.rb +1 -2
  104. data/lib/coradoc/parser/asciidoc/inline.rb +165 -42
  105. data/lib/coradoc/parser/asciidoc/list.rb +27 -27
  106. data/lib/coradoc/parser/asciidoc/paragraph.rb +28 -19
  107. data/lib/coradoc/parser/asciidoc/section.rb +11 -17
  108. data/lib/coradoc/parser/asciidoc/table.rb +5 -5
  109. data/lib/coradoc/parser/asciidoc/term.rb +24 -8
  110. data/lib/coradoc/parser/asciidoc/text.rb +18 -21
  111. data/lib/coradoc/parser/base.rb +0 -3
  112. data/lib/coradoc/reverse_adoc.rb +3 -3
  113. data/lib/coradoc/transformer.rb +167 -137
  114. data/lib/coradoc/version.rb +1 -1
  115. data/lib/reverse_adoc.rb +1 -1
  116. data/utils/inspect_asciidoc.rb +29 -0
  117. data/utils/parser_analyzer.rb +14 -14
  118. data/utils/round_trip.rb +31 -15
  119. metadata +34 -137
  120. data/.hound.yml +0 -5
  121. data/lib/coradoc/element/inline/citation.rb +0 -24
  122. data/todo.md +0 -10
@@ -1,17 +1,21 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Em < Markup
4
- def coradoc_class
5
- Coradoc::Element::Inline::Italic
6
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Em < Markup
6
+ def coradoc_class
7
+ Coradoc::Element::Inline::Italic
8
+ end
9
+
10
+ def markup_ancestor_tag_names
11
+ %w[em i cite]
12
+ end
13
+ end
7
14
 
8
- def markup_ancestor_tag_names
9
- %w[em i cite]
15
+ register :em, Em.new
16
+ register :i, Em.new
17
+ register :cite, Em.new
10
18
  end
11
19
  end
12
-
13
- register :em, Em.new
14
- register :i, Em.new
15
- register :cite, Em.new
16
20
  end
17
21
  end
@@ -1,21 +1,25 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Figure < Base
4
- def to_coradoc(node, state = {})
5
- id = node["id"]
6
- title = extract_title(node)
7
- content = treat_children_coradoc(node, state)
8
- Coradoc::Element::Block::Example.new(title, lines: content, id: id)
9
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Figure < Base
6
+ def to_coradoc(node, state = {})
7
+ id = node["id"]
8
+ title = extract_title(node)
9
+ content = treat_children_coradoc(node, state)
10
+ Coradoc::Element::Block::Example.new(title, lines: content, id: id)
11
+ end
12
+
13
+ def extract_title(node)
14
+ title = node.at("./figcaption")
15
+ return "" if title.nil?
10
16
 
11
- def extract_title(node)
12
- title = node.at("./figcaption")
13
- return "" if title.nil?
17
+ treat_children_coradoc(title, {})
18
+ end
19
+ end
14
20
 
15
- treat_children_coradoc(title, {})
21
+ register :figure, Figure.new
16
22
  end
17
23
  end
18
-
19
- register :figure, Figure.new
20
24
  end
21
25
  end
@@ -1,40 +1,42 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class H < Base
4
- def to_coradoc(node, state = {})
5
- id = node["id"]
6
- internal_anchor = treat_children_anchors(node, state)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class H < Base
6
+ def to_coradoc(node, state = {})
7
+ id = node["id"]
8
+ internal_anchor = treat_children_anchors(node, state)
7
9
 
8
- if id.to_s.empty? && internal_anchor.size.positive?
9
- if internal_anchor.first.respond_to? :id
10
- id = internal_anchor.first.id
11
- end
12
- end
10
+ if id.to_s.empty? && internal_anchor.size.positive? && internal_anchor.first.respond_to?(:id)
11
+ id = internal_anchor.first.id
12
+ end
13
13
 
14
- level = node.name[/\d/].to_i
15
- content = treat_children_no_anchors(node, state)
14
+ level = node.name[/\d/].to_i
15
+ content = treat_children_no_anchors(node, state)
16
16
 
17
- Coradoc::Element::Title.new(content, level, id: id)
18
- end
17
+ Coradoc::Element::Title.new(content, level, id: id)
18
+ end
19
19
 
20
- def treat_children_no_anchors(node, state)
21
- node.children.reject { |a| a.name == "a" }.map do |child|
22
- treat_coradoc(child, state)
23
- end
24
- end
20
+ def treat_children_no_anchors(node, state)
21
+ node.children.reject { |a| a.name == "a" }.map do |child|
22
+ treat_coradoc(child, state)
23
+ end
24
+ end
25
25
 
26
- def treat_children_anchors(node, state)
27
- node.children.select { |a| a.name == "a" }.map do |child|
28
- treat_coradoc(child, state)
26
+ def treat_children_anchors(node, state)
27
+ node.children.select { |a| a.name == "a" }.map do |child|
28
+ treat_coradoc(child, state)
29
+ end
30
+ end
29
31
  end
32
+
33
+ register :h1, H.new
34
+ register :h2, H.new
35
+ register :h3, H.new
36
+ register :h4, H.new
37
+ register :h5, H.new
38
+ register :h6, H.new
30
39
  end
31
40
  end
32
-
33
- register :h1, H.new
34
- register :h2, H.new
35
- register :h3, H.new
36
- register :h4, H.new
37
- register :h5, H.new
38
- register :h6, H.new
39
41
  end
40
42
  end
@@ -1,19 +1,23 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Head < Base
4
- def to_coradoc(node, _state = {})
5
- title = extract_title(node)
6
- Coradoc::Element::Header.new(title)
7
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Head < Base
6
+ def to_coradoc(node, _state = {})
7
+ title = extract_title(node)
8
+ Coradoc::Element::Header.new(title)
9
+ end
10
+
11
+ def extract_title(node)
12
+ title = node.at("./title")
13
+ return "(???)" if title.nil?
8
14
 
9
- def extract_title(node)
10
- title = node.at("./title")
11
- return "(???)" if title.nil?
15
+ title.text
16
+ end
17
+ end
12
18
 
13
- title.text
19
+ register :head, Head.new
14
20
  end
15
21
  end
16
-
17
- register :head, Head.new
18
22
  end
19
23
  end
@@ -1,11 +1,15 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Hr < Base
4
- def to_coradoc(_node, _state = {})
5
- Coradoc::Element::Break::ThematicBreak.new
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Hr < Base
6
+ def to_coradoc(_node, _state = {})
7
+ Coradoc::Element::Break::ThematicBreak.new
8
+ end
9
+ end
10
+
11
+ register :hr, Hr.new
6
12
  end
7
13
  end
8
-
9
- register :hr, Hr.new
10
14
  end
11
15
  end
@@ -1,16 +1,20 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Ignore < Base
4
- def to_coradoc(node, state = {})
5
- convert(node, state)
6
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Ignore < Base
6
+ def to_coradoc(node, state = {})
7
+ convert(node, state)
8
+ end
9
+
10
+ def convert(_node, _state = {})
11
+ "" # noop
12
+ end
13
+ end
7
14
 
8
- def convert(_node, _state = {})
9
- "" # noop
15
+ register :colgroup, Ignore.new
16
+ register :col, Ignore.new
10
17
  end
11
18
  end
12
-
13
- register :colgroup, Ignore.new
14
- register :col, Ignore.new
15
19
  end
16
20
  end
@@ -4,102 +4,107 @@ require "tempfile"
4
4
  require "base64"
5
5
  require "marcel"
6
6
 
7
- module Coradoc::Input::HTML
8
- module Converters
9
- class Img < Base
10
- def image_number
11
- sprintf(
12
- Coradoc::Input::HTML.config.image_counter_pattern,
13
- Coradoc::Input::HTML.config.image_counter,
14
- )
15
- end
16
-
17
- def image_number_increment
18
- Coradoc::Input::HTML.config.image_counter += 1
19
- end
20
-
21
- def datauri2file(src)
22
- return unless src
23
-
24
- %r{^data:image/(?:[^;]+);base64,(?<imgdata>.+)$} =~ src
25
-
26
- dest_dir = Pathname.new(Coradoc::Input::HTML.config.destination).dirname
27
- images_dir = dest_dir.join("images")
28
- FileUtils.mkdir_p(images_dir)
29
-
30
- ext, image_src_path, tempfile = determine_image_src_path(src, imgdata)
31
- image_dest_path = images_dir + "#{image_number}.#{ext}"
32
-
33
- # puts "image_dest_path: #{image_dest_path.to_s}"
34
- # puts "image_src_path: #{image_src_path.to_s}"
35
-
36
- if File.exist?(image_src_path)
37
- FileUtils.cp(image_src_path, image_dest_path)
38
- else
39
- @annotate_missing = image_src_path
40
- Kernel.warn "Image #{image_src_path} does not exist"
7
+ module Coradoc
8
+ module Input
9
+ module Html
10
+ module Converters
11
+ class Img < Base
12
+ def image_number
13
+ sprintf(
14
+ Coradoc::Input::Html.config.image_counter_pattern,
15
+ Coradoc::Input::Html.config.image_counter,
16
+ )
17
+ end
18
+
19
+ def image_number_increment
20
+ Coradoc::Input::Html.config.image_counter += 1
21
+ end
22
+
23
+ def datauri2file(src)
24
+ return unless src
25
+
26
+ %r{^data:image/(?:[^;]+);base64,(?<imgdata>.+)$} =~ src
27
+
28
+ dest_dir = Pathname.new(Coradoc::Input::Html.config.destination).dirname
29
+ images_dir = dest_dir.join("images")
30
+ FileUtils.mkdir_p(images_dir)
31
+
32
+ ext, image_src_path, tempfile = determine_image_src_path(src,
33
+ imgdata)
34
+ image_dest_path = images_dir + "#{image_number}.#{ext}"
35
+
36
+ # puts "image_dest_path: #{image_dest_path.to_s}"
37
+ # puts "image_src_path: #{image_src_path.to_s}"
38
+
39
+ if File.exist?(image_src_path)
40
+ FileUtils.cp(image_src_path, image_dest_path)
41
+ else
42
+ @annotate_missing = image_src_path
43
+ Kernel.warn "Image #{image_src_path} does not exist"
44
+ end
45
+
46
+ image_number_increment
47
+
48
+ image_dest_path.relative_path_from(dest_dir)
49
+ ensure
50
+ tempfile&.close!
51
+ end
52
+
53
+ def determine_image_src_path(src, imgdata)
54
+ return copy_temp_file(imgdata) if imgdata
55
+
56
+ ext = File.extname(src).strip.downcase[1..]
57
+ [ext, Pathname.new(Coradoc::Input::Html.config.sourcedir).join(src)]
58
+ end
59
+
60
+ def copy_temp_file(imgdata)
61
+ f = Tempfile.open(["radoc", ".jpg"])
62
+ f.binmode
63
+ f.write(Base64.strict_decode64(imgdata))
64
+ f.rewind
65
+ ext = Marcel::MimeType.for(f).sub(%r{^[^/]+/}, "")
66
+ ext = "svg" if ext == "svg+xml"
67
+ [ext, f.path, f]
68
+ end
69
+
70
+ def to_coradoc(node, _state = {})
71
+ id = node["id"]
72
+ alt = node["alt"]
73
+ src = node["src"]
74
+ width = node["width"]
75
+ height = node["height"]
76
+
77
+ width = width.to_i if width&.match?(/\A\d+\z/)
78
+ height = height.to_i if height&.match?(/\A\d+\z/)
79
+
80
+ title = extract_title(node)
81
+
82
+ if Coradoc::Input::Html.config.external_images
83
+ # puts "external image conversion #{id}, #{src}"
84
+ src = datauri2file(src)
85
+ end
86
+
87
+ attributes = Coradoc::Element::AttributeList.new
88
+ # attributes.add_named("id", id) if id
89
+ if alt # && !alt.to_s.empty?
90
+ attributes.add_positional(alt)
91
+ elsif width || height
92
+ attributes.add_positional(nil)
93
+ end
94
+ attributes.add_named("title", title) if title && !title.empty?
95
+ attributes.add_positional(width) if width
96
+ attributes.add_positional(height) if height
97
+
98
+ if src
99
+ Coradoc::Element::Image::BlockImage.new(title, id, src,
100
+ attributes: attributes,
101
+ annotate_missing: @annotate_missing)
102
+ end
103
+ end
41
104
  end
42
105
 
43
- image_number_increment
44
-
45
- image_dest_path.relative_path_from(dest_dir)
46
- ensure
47
- tempfile&.close!
48
- end
49
-
50
- def determine_image_src_path(src, imgdata)
51
- return copy_temp_file(imgdata) if imgdata
52
-
53
- ext = File.extname(src).strip.downcase[1..-1]
54
- [ext, Pathname.new(Coradoc::Input::HTML.config.sourcedir).join(src)]
55
- end
56
-
57
- def copy_temp_file(imgdata)
58
- f = Tempfile.open(["radoc", ".jpg"])
59
- f.binmode
60
- f.write(Base64.strict_decode64(imgdata))
61
- f.rewind
62
- ext = Marcel::MimeType.for(f).sub(%r{^[^/]+/}, "")
63
- ext = "svg" if ext == "svg+xml"
64
- [ext, f.path, f]
65
- end
66
-
67
- def to_coradoc(node, _state = {})
68
- id = node["id"]
69
- alt = node["alt"]
70
- src = node["src"]
71
- width = node["width"]
72
- height = node["height"]
73
-
74
- width = width.to_i if width&.match?(/\A\d+\z/)
75
- height = height.to_i if height&.match?(/\A\d+\z/)
76
-
77
- title = extract_title(node)
78
-
79
- if Coradoc::Input::HTML.config.external_images
80
- # puts "external image conversion #{id}, #{src}"
81
- src = datauri2file(src)
82
- end
83
-
84
- attributes = Coradoc::Element::AttributeList.new
85
- # attributes.add_named("id", id) if id
86
- if alt # && !alt.to_s.empty?
87
- attributes.add_positional(alt)
88
- elsif width || height
89
- attributes.add_positional(nil)
90
- end
91
- attributes.add_named("title", title) if title && !title.empty?
92
- attributes.add_positional(width) if width
93
- attributes.add_positional(height) if height
94
-
95
- if src
96
- Coradoc::Element::Image::BlockImage.new(title, id, src,
97
- attributes: attributes,
98
- annotate_missing: @annotate_missing)
99
- end
106
+ register :img, Img
100
107
  end
101
108
  end
102
-
103
- register :img, Img
104
109
  end
105
110
  end
@@ -1,13 +1,17 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Li < Base
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)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Li < Base
6
+ def to_coradoc(node, state = {})
7
+ id = node["id"]
8
+ content = treat_children_coradoc(node, state)
9
+ Coradoc::Element::ListItem.new(content, id: id)
10
+ end
11
+ end
12
+
13
+ register :li, Li.new
8
14
  end
9
15
  end
10
-
11
- register :li, Li.new
12
16
  end
13
17
  end
@@ -1,15 +1,19 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Mark < Markup
4
- def coradoc_class
5
- Coradoc::Element::Inline::Highlight
6
- end
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Mark < Markup
6
+ def coradoc_class
7
+ Coradoc::Element::Inline::Highlight
8
+ end
9
+
10
+ def markup_ancestor_tag_names
11
+ %w[mark]
12
+ end
13
+ end
7
14
 
8
- def markup_ancestor_tag_names
9
- %w[mark]
15
+ register :mark, Mark.new
10
16
  end
11
17
  end
12
-
13
- register :mark, Mark.new
14
18
  end
15
19
  end
@@ -1,25 +1,29 @@
1
- module Coradoc::Input::HTML
2
- module Converters
3
- class Markup < Base
4
- def to_coradoc(node, state = {})
5
- u_before = unconstrained_before?(node)
6
- u_after = unconstrained_after?(node)
1
+ module Coradoc
2
+ module Input
3
+ module Html
4
+ module Converters
5
+ class Markup < Base
6
+ def to_coradoc(node, state = {})
7
+ u_before = unconstrained_before?(node)
8
+ u_after = unconstrained_after?(node)
7
9
 
8
- leading_whitespace, trailing_whitespace =
9
- extract_leading_trailing_whitespace(node)
10
+ leading_whitespace, trailing_whitespace =
11
+ extract_leading_trailing_whitespace(node)
10
12
 
11
- content = treat_children_coradoc(node, state)
13
+ content = treat_children_coradoc(node, state)
12
14
 
13
- if node_has_ancestor?(node, markup_ancestor_tag_names)
14
- content
15
- elsif node.children.empty?
16
- leading_whitespace.to_s
17
- else
18
- u = (u_before && leading_whitespace.nil?) ||
19
- (u_after && trailing_whitespace.nil?)
15
+ if node_has_ancestor?(node, markup_ancestor_tag_names)
16
+ content
17
+ elsif node.children.empty?
18
+ leading_whitespace.to_s
19
+ else
20
+ u = (u_before && leading_whitespace.nil?) ||
21
+ (u_after && trailing_whitespace.nil?)
20
22
 
21
- e = coradoc_class.new(content, unconstrained: u)
22
- [leading_whitespace, e, trailing_whitespace]
23
+ e = coradoc_class.new(content, unconstrained: u)
24
+ [leading_whitespace, e, trailing_whitespace]
25
+ end
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -2,30 +2,37 @@
2
2
  # this is cheating: we're injecting MathML into Asciidoctor, but
3
3
  # Asciidoctor only understands AsciiMath or LaTeX
4
4
 
5
- require "mathml2asciimath"
5
+ require "plurimath"
6
6
 
7
- module Coradoc::Input::HTML
8
- module Converters
9
- class Math < Base
10
- # FIXIT
11
- def to_coradoc(node, state = {})
12
- convert(node, state)
13
- end
7
+ module Coradoc
8
+ module Input
9
+ module Html
10
+ module Converters
11
+ class Math < Base
12
+ # FIXIT
13
+ def to_coradoc(node, state = {})
14
+ convert(node, state)
15
+ end
16
+
17
+ def convert(node, _state = {})
18
+ stem = node.to_s.tr("\n", " ")
19
+ if Coradoc::Input::Html.config.mathml2asciimath
20
+ stem = Plurimath::Math.parse(stem, :mathml).to_asciimath
21
+ end
14
22
 
15
- def convert(node, _state = {})
16
- stem = node.to_s.gsub(/\n/, " ")
17
- stem = MathML2AsciiMath.m2a(stem) if Coradoc::Input::HTML.config.mathml2asciimath
18
- unless stem.nil?
19
- stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(
20
- /\(\(([^\)]+)\)\)/, "(\\1)"
21
- )
23
+ unless stem.nil?
24
+ stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(
25
+ /\(\(([^\)]+)\)\)/, "(\\1)"
26
+ )
27
+ end
28
+
29
+ # TODO: This is to be done in Coradoc
30
+ " stem:[" << stem << "] "
31
+ end
22
32
  end
23
33
 
24
- # TODO: This is to be done in Coradoc
25
- " stem:[" << stem << "] "
34
+ register :math, Math.new
26
35
  end
27
36
  end
28
-
29
- register :math, Math.new
30
37
  end
31
38
  end