coradoc 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +35 -0
  3. data/{.docker/readme.md → README.Docker.adoc} +21 -25
  4. data/README.adoc +121 -0
  5. data/coradoc.gemspec +4 -0
  6. data/docker-compose.yml +14 -0
  7. data/exe/coradoc +5 -0
  8. data/exe/reverse_adoc +24 -34
  9. data/exe/w2a +16 -28
  10. data/lib/coradoc/cli.rb +105 -0
  11. data/lib/coradoc/converter.rb +145 -0
  12. data/lib/coradoc/document.rb +13 -0
  13. data/lib/coradoc/element/admonition.rb +5 -0
  14. data/lib/coradoc/element/attribute_list.rb +1 -1
  15. data/lib/coradoc/element/author.rb +4 -4
  16. data/lib/coradoc/element/bibliography.rb +24 -0
  17. data/lib/coradoc/element/bibliography_entry.rb +24 -0
  18. data/lib/coradoc/element/block/core.rb +6 -4
  19. data/lib/coradoc/element/block/example.rb +1 -0
  20. data/lib/coradoc/element/block/pass.rb +21 -0
  21. data/lib/coradoc/element/block/quote.rb +1 -1
  22. data/lib/coradoc/element/block/reviewer_comment.rb +19 -0
  23. data/lib/coradoc/element/block/side.rb +4 -2
  24. data/lib/coradoc/element/block/sourcecode.rb +1 -0
  25. data/lib/coradoc/element/block.rb +2 -0
  26. data/lib/coradoc/element/comment_block.rb +22 -0
  27. data/lib/coradoc/element/comment_line.rb +18 -0
  28. data/lib/coradoc/element/document_attributes.rb +8 -1
  29. data/lib/coradoc/element/header.rb +1 -1
  30. data/lib/coradoc/element/image/block_image.rb +8 -0
  31. data/lib/coradoc/element/image/core.rb +7 -4
  32. data/lib/coradoc/element/include.rb +18 -0
  33. data/lib/coradoc/element/inline/citation.rb +24 -0
  34. data/lib/coradoc/element/inline/cross_reference.rb +29 -8
  35. data/lib/coradoc/element/inline.rb +1 -0
  36. data/lib/coradoc/element/list/core.rb +16 -3
  37. data/lib/coradoc/element/list/definition.rb +3 -1
  38. data/lib/coradoc/element/list_item.rb +15 -5
  39. data/lib/coradoc/element/paragraph.rb +8 -5
  40. data/lib/coradoc/element/revision.rb +1 -1
  41. data/lib/coradoc/element/section.rb +11 -3
  42. data/lib/coradoc/element/table.rb +6 -1
  43. data/lib/coradoc/element/tag.rb +19 -0
  44. data/lib/coradoc/element/term.rb +21 -0
  45. data/lib/coradoc/element/text_element.rb +9 -1
  46. data/lib/coradoc/element/title.rb +2 -2
  47. data/lib/coradoc/generator.rb +2 -0
  48. data/lib/coradoc/input/adoc.rb +28 -0
  49. data/lib/coradoc/input/docx.rb +35 -0
  50. data/lib/coradoc/{reverse_adoc → input/html}/README.adoc +9 -9
  51. data/lib/coradoc/{reverse_adoc → input/html}/cleaner.rb +19 -6
  52. data/lib/coradoc/input/html/config.rb +75 -0
  53. data/lib/coradoc/{reverse_adoc → input/html}/converters/a.rb +1 -1
  54. data/lib/coradoc/{reverse_adoc → input/html}/converters/aside.rb +1 -1
  55. data/lib/coradoc/{reverse_adoc → input/html}/converters/audio.rb +1 -1
  56. data/lib/coradoc/{reverse_adoc → input/html}/converters/base.rb +1 -1
  57. data/lib/coradoc/{reverse_adoc → input/html}/converters/blockquote.rb +2 -2
  58. data/lib/coradoc/{reverse_adoc → input/html}/converters/br.rb +1 -1
  59. data/lib/coradoc/{reverse_adoc → input/html}/converters/bypass.rb +1 -1
  60. data/lib/coradoc/{reverse_adoc → input/html}/converters/code.rb +1 -1
  61. data/lib/coradoc/{reverse_adoc → input/html}/converters/div.rb +1 -1
  62. data/lib/coradoc/{reverse_adoc → input/html}/converters/dl.rb +1 -1
  63. data/lib/coradoc/{reverse_adoc → input/html}/converters/drop.rb +1 -1
  64. data/lib/coradoc/{reverse_adoc → input/html}/converters/em.rb +1 -1
  65. data/lib/coradoc/{reverse_adoc → input/html}/converters/figure.rb +1 -1
  66. data/lib/coradoc/{reverse_adoc → input/html}/converters/h.rb +1 -1
  67. data/lib/coradoc/{reverse_adoc → input/html}/converters/head.rb +1 -1
  68. data/lib/coradoc/{reverse_adoc → input/html}/converters/hr.rb +1 -1
  69. data/lib/coradoc/{reverse_adoc → input/html}/converters/ignore.rb +1 -1
  70. data/lib/coradoc/{reverse_adoc → input/html}/converters/img.rb +17 -10
  71. data/lib/coradoc/{reverse_adoc → input/html}/converters/li.rb +1 -1
  72. data/lib/coradoc/{reverse_adoc → input/html}/converters/mark.rb +1 -1
  73. data/lib/coradoc/{reverse_adoc → input/html}/converters/markup.rb +1 -1
  74. data/lib/coradoc/{reverse_adoc → input/html}/converters/math.rb +3 -3
  75. data/lib/coradoc/{reverse_adoc → input/html}/converters/ol.rb +1 -1
  76. data/lib/coradoc/{reverse_adoc → input/html}/converters/p.rb +1 -1
  77. data/lib/coradoc/{reverse_adoc → input/html}/converters/pass_through.rb +1 -1
  78. data/lib/coradoc/{reverse_adoc → input/html}/converters/pre.rb +1 -1
  79. data/lib/coradoc/{reverse_adoc → input/html}/converters/q.rb +1 -1
  80. data/lib/coradoc/{reverse_adoc → input/html}/converters/strong.rb +1 -1
  81. data/lib/coradoc/{reverse_adoc → input/html}/converters/sub.rb +1 -1
  82. data/lib/coradoc/{reverse_adoc → input/html}/converters/sup.rb +1 -1
  83. data/lib/coradoc/{reverse_adoc → input/html}/converters/table.rb +36 -11
  84. data/lib/coradoc/{reverse_adoc → input/html}/converters/td.rb +1 -1
  85. data/lib/coradoc/{reverse_adoc → input/html}/converters/text.rb +2 -2
  86. data/lib/coradoc/{reverse_adoc → input/html}/converters/th.rb +1 -1
  87. data/lib/coradoc/{reverse_adoc → input/html}/converters/tr.rb +1 -1
  88. data/lib/coradoc/{reverse_adoc → input/html}/converters/video.rb +1 -1
  89. data/lib/coradoc/input/html/converters.rb +57 -0
  90. data/lib/coradoc/input/html/errors.rb +12 -0
  91. data/lib/coradoc/{reverse_adoc → input/html}/html_converter.rb +37 -22
  92. data/lib/coradoc/{reverse_adoc → input/html}/plugin.rb +6 -6
  93. data/lib/coradoc/{reverse_adoc → input/html}/plugins/plateau.rb +62 -30
  94. data/lib/coradoc/{reverse_adoc → input/html}/postprocessor.rb +13 -9
  95. data/lib/coradoc/input/html.rb +59 -0
  96. data/lib/coradoc/input.rb +12 -0
  97. data/lib/coradoc/output/adoc.rb +17 -0
  98. data/lib/coradoc/output/coradoc_tree_debug.rb +19 -0
  99. data/lib/coradoc/output.rb +11 -0
  100. data/lib/coradoc/parser/asciidoc/admonition.rb +24 -0
  101. data/lib/coradoc/parser/asciidoc/attribute_list.rb +67 -0
  102. data/lib/coradoc/parser/asciidoc/base.rb +101 -13
  103. data/lib/coradoc/parser/asciidoc/bibliography.rb +30 -0
  104. data/lib/coradoc/parser/asciidoc/block.rb +82 -0
  105. data/lib/coradoc/parser/asciidoc/citation.rb +48 -0
  106. data/lib/coradoc/parser/asciidoc/content.rb +15 -120
  107. data/lib/coradoc/parser/asciidoc/document_attributes.rb +12 -5
  108. data/lib/coradoc/parser/asciidoc/header.rb +1 -4
  109. data/lib/coradoc/parser/asciidoc/inline.rb +72 -0
  110. data/lib/coradoc/parser/asciidoc/list.rb +81 -0
  111. data/lib/coradoc/parser/asciidoc/paragraph.rb +33 -0
  112. data/lib/coradoc/parser/asciidoc/section.rb +36 -31
  113. data/lib/coradoc/parser/asciidoc/table.rb +32 -0
  114. data/lib/coradoc/parser/asciidoc/term.rb +23 -0
  115. data/lib/coradoc/parser/base.rb +39 -4
  116. data/lib/coradoc/transformer.rb +353 -82
  117. data/lib/coradoc/util.rb +10 -0
  118. data/lib/coradoc/version.rb +1 -1
  119. data/lib/coradoc.rb +8 -4
  120. data/lib/reverse_adoc.rb +6 -6
  121. data/utils/parser_analyzer.rb +66 -0
  122. data/utils/round_trip.rb +37 -0
  123. metadata +113 -54
  124. data/.docker/Makefile +0 -35
  125. data/.docker/docker-compose.yml +0 -14
  126. data/Makefile +0 -1
  127. data/README.md +0 -73
  128. data/docker-compose.yml +0 -1
  129. data/lib/coradoc/reverse_adoc/config.rb +0 -73
  130. data/lib/coradoc/reverse_adoc/converters.rb +0 -53
  131. data/lib/coradoc/reverse_adoc/errors.rb +0 -10
  132. data/lib/coradoc/reverse_adoc.rb +0 -30
  133. /data/{.docker/Dockerfile → Dockerfile} +0 -0
  134. /data/lib/coradoc/{reverse_adoc → input/html}/LICENSE.txt +0 -0
@@ -4,18 +4,18 @@ require "tempfile"
4
4
  require "base64"
5
5
  require "marcel"
6
6
 
7
- module Coradoc::ReverseAdoc
7
+ module Coradoc::Input::HTML
8
8
  module Converters
9
9
  class Img < Base
10
10
  def image_number
11
11
  sprintf(
12
- Coradoc::ReverseAdoc.config.image_counter_pattern,
13
- Coradoc::ReverseAdoc.config.image_counter,
12
+ Coradoc::Input::HTML.config.image_counter_pattern,
13
+ Coradoc::Input::HTML.config.image_counter,
14
14
  )
15
15
  end
16
16
 
17
17
  def image_number_increment
18
- Coradoc::ReverseAdoc.config.image_counter += 1
18
+ Coradoc::Input::HTML.config.image_counter += 1
19
19
  end
20
20
 
21
21
  def datauri2file(src)
@@ -23,7 +23,7 @@ module Coradoc::ReverseAdoc
23
23
 
24
24
  %r{^data:image/(?:[^;]+);base64,(?<imgdata>.+)$} =~ src
25
25
 
26
- dest_dir = Pathname.new(Coradoc::ReverseAdoc.config.destination).dirname
26
+ dest_dir = Pathname.new(Coradoc::Input::HTML.config.destination).dirname
27
27
  images_dir = dest_dir.join("images")
28
28
  FileUtils.mkdir_p(images_dir)
29
29
 
@@ -33,7 +33,13 @@ module Coradoc::ReverseAdoc
33
33
  # puts "image_dest_path: #{image_dest_path.to_s}"
34
34
  # puts "image_src_path: #{image_src_path.to_s}"
35
35
 
36
- FileUtils.cp(image_src_path, image_dest_path)
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"
41
+ end
42
+
37
43
  image_number_increment
38
44
 
39
45
  image_dest_path.relative_path_from(dest_dir)
@@ -45,7 +51,7 @@ module Coradoc::ReverseAdoc
45
51
  return copy_temp_file(imgdata) if imgdata
46
52
 
47
53
  ext = File.extname(src).strip.downcase[1..-1]
48
- [ext, Pathname.new(Coradoc::ReverseAdoc.config.sourcedir).join(src)]
54
+ [ext, Pathname.new(Coradoc::Input::HTML.config.sourcedir).join(src)]
49
55
  end
50
56
 
51
57
  def copy_temp_file(imgdata)
@@ -70,7 +76,7 @@ module Coradoc::ReverseAdoc
70
76
 
71
77
  title = extract_title(node)
72
78
 
73
- if Coradoc::ReverseAdoc.config.external_images
79
+ if Coradoc::Input::HTML.config.external_images
74
80
  # puts "external image conversion #{id}, #{src}"
75
81
  src = datauri2file(src)
76
82
  end
@@ -88,11 +94,12 @@ module Coradoc::ReverseAdoc
88
94
 
89
95
  if src
90
96
  Coradoc::Element::Image::BlockImage.new(title, id, src,
91
- attributes: attributes)
97
+ attributes: attributes,
98
+ annotate_missing: @annotate_missing)
92
99
  end
93
100
  end
94
101
  end
95
102
 
96
- register :img, Img.new
103
+ register :img, Img
97
104
  end
98
105
  end
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Li < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Mark < Markup
4
4
  def coradoc_class
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Markup < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,10 +1,10 @@
1
- # Unless run with Coradoc::ReverseAdoc.config.mathml2asciimath,
1
+ # Unless run with Coradoc::Input::HTML.config.mathml2asciimath,
2
2
  # this is cheating: we're injecting MathML into Asciidoctor, but
3
3
  # Asciidoctor only understands AsciiMath or LaTeX
4
4
 
5
5
  require "mathml2asciimath"
6
6
 
7
- module Coradoc::ReverseAdoc
7
+ module Coradoc::Input::HTML
8
8
  module Converters
9
9
  class Math < Base
10
10
  # FIXIT
@@ -14,7 +14,7 @@ module Coradoc::ReverseAdoc
14
14
 
15
15
  def convert(node, _state = {})
16
16
  stem = node.to_s.gsub(/\n/, " ")
17
- stem = MathML2AsciiMath.m2a(stem) if Coradoc::ReverseAdoc.config.mathml2asciimath
17
+ stem = MathML2AsciiMath.m2a(stem) if Coradoc::Input::HTML.config.mathml2asciimath
18
18
  unless stem.nil?
19
19
  stem = stem.gsub(/\[/, "\\[").gsub(/\]/, "\\]").gsub(
20
20
  /\(\(([^\)]+)\)\)/, "(\\1)"
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Ol < Base
4
4
  # FIXIT
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class P < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class PassThrough < Base
4
4
  def to_coradoc(node, _state = {})
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Pre < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Q < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Strong < Markup
4
4
  def coradoc_class
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Sub < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Sup < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,12 +1,12 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Table < Base
4
4
  def to_coradoc(node, state = {})
5
5
  id = node["id"]
6
6
  title = extract_title(node)
7
- attrs = style(node)
7
+ attributes = style(node)
8
8
  content = treat_children_coradoc(node, state)
9
- Coradoc::Element::Table.new(title, content, { id: id, attrs: attrs })
9
+ Coradoc::Element::Table.new(title, content, { id: id, attributes: attributes })
10
10
  end
11
11
 
12
12
  def extract_title(node)
@@ -53,13 +53,17 @@ module Coradoc::ReverseAdoc
53
53
  rules_attr = rules(node)
54
54
  attrs.add_named("rules", rules_attr) if rules_attr
55
55
 
56
- cols = ensure_row_column_integrity_and_get_column_sizes(node)
57
- attrs.add_named("cols", cols)
56
+ # We can't, and shouldn't do those calculation if the table we are
57
+ # processing is empty.
58
+ unless empty?(node)
59
+ cols = ensure_row_column_integrity_and_get_column_sizes(node)
60
+ attrs.add_named("cols", cols)
58
61
 
59
- # Header first rows can't span multiple riws - drop header if they do.
60
- header = node.at_xpath(".//tr")
61
- unless header.xpath("./td | ./th").all? { |i| [nil, "1", ""].include? i["rowspan"] }
62
- attrs.add_named("options", ["noheader"])
62
+ # Header first rows can't span multiple riws - drop header if they do.
63
+ header = node.at_xpath(".//tr")
64
+ unless header.xpath("./td | ./th").all? { |i| [nil, "1", ""].include? i["rowspan"] }
65
+ attrs.add_named("options", ["noheader"])
66
+ end
63
67
  end
64
68
 
65
69
  # This line should be removed.
@@ -68,6 +72,10 @@ module Coradoc::ReverseAdoc
68
72
  attrs
69
73
  end
70
74
 
75
+ def empty?(node)
76
+ !node.at_xpath(".//td | .//th")
77
+ end
78
+
71
79
  def ensure_row_column_integrity_and_get_column_sizes(node)
72
80
  rows = node.xpath(".//tr")
73
81
  num_rows = rows.length
@@ -173,7 +181,9 @@ module Coradoc::ReverseAdoc
173
181
 
174
182
  row_obj = row.last.first.parent
175
183
  doc = row_obj.document
176
- row_obj.add_child(Nokogiri::XML::Node.new("td", doc))
184
+ added_node = Nokogiri::XML::Node.new("td", doc)
185
+ added_node["x-added"] = "x-added"
186
+ row_obj.add_child(added_node)
177
187
 
178
188
  modified = true
179
189
  end
@@ -194,6 +204,21 @@ module Coradoc::ReverseAdoc
194
204
  end
195
205
 
196
206
  unless cell_matrix_correct
207
+ # It may be a special case that we need to add virtual cells at the
208
+ # beginning not the end of a row.
209
+ needs_recompute = false
210
+ cell_matrix.each do |row|
211
+ if row.compact.length != row.length
212
+ last_cell = row.last
213
+ if last_cell["x-added"]
214
+ last_cell.parent.prepend_child(last_cell)
215
+ needs_recompute = true
216
+ end
217
+ end
218
+ end
219
+ recompute.() if needs_recompute
220
+
221
+ # But otherwise... we've got a really nasty table.
197
222
  warn <<~WARNING.gsub("\n", " ")
198
223
  **** Couldn't construct a valid image of a table on line
199
224
  #{node.line}. We need that to reliably compute column
@@ -213,7 +238,7 @@ module Coradoc::ReverseAdoc
213
238
  end
214
239
  end
215
240
 
216
- document_width = Coradoc::ReverseAdoc.config.doc_width.to_r
241
+ document_width = Coradoc::Input::HTML.config.doc_width.to_r
217
242
 
218
243
  column_sizes += [nil] * (cpr.first - column_sizes.length)
219
244
 
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Td < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,10 +1,10 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Text < Base
4
4
  def to_coradoc(node, state = {})
5
5
  return treat_empty(node, state) if node.text.strip.empty?
6
6
 
7
- Coradoc::Element::TextElement.new(node.text)
7
+ Coradoc::Element::TextElement.new(node.text, html_cleanup: true)
8
8
  end
9
9
 
10
10
  private
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Th < Td
4
4
  def cellstyle(node)
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Tr < Base
4
4
  def to_coradoc(node, state = {})
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  module Converters
3
3
  class Video < Base
4
4
  def to_coradoc(node, _state = {})
@@ -0,0 +1,57 @@
1
+ module Coradoc
2
+ module Input::HTML
3
+ module Converters
4
+ def self.register(tag_name, converter)
5
+ @@converters ||= {}
6
+ @@converters[tag_name.to_sym] = converter
7
+ end
8
+
9
+ def self.unregister(tag_name)
10
+ @@converters.delete(tag_name.to_sym)
11
+ end
12
+
13
+ def self.lookup(tag_name)
14
+ converter = @@converters[tag_name.to_sym] || default_converter(tag_name)
15
+ converter = converter.new if converter.respond_to? :new
16
+ converter
17
+ end
18
+
19
+ # Note: process won't run plugin hooks
20
+ def self.process(node, state)
21
+ node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
22
+ return node.map { |i| process(i, state) }.join if node.is_a? Array
23
+
24
+ lookup(node.name).convert(node, state)
25
+ end
26
+
27
+ def self.process_coradoc(node, state)
28
+ node = node.to_a if node.is_a? Nokogiri::XML::NodeSet
29
+ return node.map { |i| process_coradoc(i, state) } if node.is_a? Array
30
+
31
+ plugins = state[:plugin_instances] || {}
32
+ process = proc { lookup(node.name).to_coradoc(node, state) }
33
+ plugins.each do |i|
34
+ prev_process = process
35
+ process = proc { i.html_tree_run_hooks(node, state, &prev_process) }
36
+ end
37
+ process.(node, state)
38
+ end
39
+
40
+ def self.default_converter(tag_name)
41
+ case Coradoc::Input::HTML.config.unknown_tags.to_sym
42
+ when :pass_through
43
+ Coradoc::Input::HTML::Converters::PassThrough.new
44
+ when :drop
45
+ Coradoc::Input::HTML::Converters::Drop.new
46
+ when :bypass
47
+ Coradoc::Input::HTML::Converters::Bypass.new
48
+ when :raise
49
+ raise UnknownTagError, "unknown tag: #{tag_name}"
50
+ else
51
+ raise InvalidConfigurationError,
52
+ "unknown value #{Coradoc::Input::HTML.config.unknown_tags.inspect} for Coradoc::Input::HTML.config.unknown_tags"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ module Coradoc
2
+ module Input::HTML
3
+ class Error < StandardError
4
+ end
5
+
6
+ class UnknownTagError < Error
7
+ end
8
+
9
+ class InvalidConfigurationError < Error
10
+ end
11
+ end
12
+ end
@@ -37,12 +37,11 @@ require_relative "converters/video"
37
37
  require_relative "converters/math"
38
38
 
39
39
  module Coradoc
40
- module ReverseAdoc
40
+ module Input::HTML
41
41
  class HtmlConverter
42
42
  def self.to_coradoc(input, options = {})
43
- plugin_instances = options.delete(:plugin_instances)
44
- ReverseAdoc.config.with(options) do
45
- plugin_instances ||= Coradoc::ReverseAdoc.config.plugins.map(&:new)
43
+ Input::HTML.config.with(options) do
44
+ plugin_instances = prepare_plugin_instances(options)
46
45
 
47
46
  root = track_time "Loading input HTML document" do
48
47
  case input
@@ -85,52 +84,68 @@ module Coradoc
85
84
  end
86
85
  end
87
86
 
87
+ options[:plugin_instances] = plugin_instances unless options.frozen?
88
+
88
89
  coradoc
89
90
  end
90
91
  end
91
92
 
92
93
  def self.convert(input, options = {})
93
- ReverseAdoc.config.with(options) do
94
- plugin_instances = Coradoc::ReverseAdoc.config.plugins.map(&:new)
95
-
96
- options = options.merge(plugin_instances: plugin_instances)
94
+ Input::HTML.config.with(options) do
95
+ plugin_instances = prepare_plugin_instances(options)
97
96
 
98
97
  coradoc = to_coradoc(input, options)
99
98
 
100
99
  if coradoc.is_a?(Hash)
101
100
  coradoc.to_h do |file, tree|
102
101
  track_time "Converting file #{file || 'main'}" do
103
- [file, convert_single_coradoc_to_adoc(file, tree, plugin_instances)]
102
+ [file,
103
+ convert_single_coradoc_to_adoc(file, tree, options)]
104
104
  end
105
105
  end
106
106
  else
107
- convert_single_coradoc_to_adoc(nil, coradoc, plugin_instances)
107
+ convert_single_coradoc_to_adoc(nil, coradoc, options)
108
108
  end
109
109
  end
110
110
  end
111
111
 
112
- def self.convert_single_coradoc_to_adoc(_file, coradoc, plugin_instances)
112
+ def self.convert_single_coradoc_to_adoc(_file, coradoc, options)
113
+ plugin_instances = prepare_plugin_instances(options)
114
+
113
115
  result = track_time "Converting Coradoc tree into Asciidoc" do
114
116
  Coradoc::Generator.gen_adoc(coradoc)
115
117
  end
116
- result = track_time "Cleaning up the result" do
117
- ReverseAdoc.cleaner.tidy(result)
118
- end
119
- plugin_instances.each do |plugin|
120
- if plugin.respond_to?(:postprocess_asciidoc_string)
121
- plugin.asciidoc_string = result
122
- track_time "Postprocessing AsciiDoc string with #{plugin.name} plugin" do
123
- plugin.postprocess_asciidoc_string
118
+ cleanup_result(result, options)
119
+ end
120
+
121
+ def self.cleanup_result(result, options)
122
+ Input::HTML.config.with(options) do
123
+ plugin_instances = prepare_plugin_instances(options)
124
+
125
+ result = track_time "Cleaning up the result" do
126
+ Input::HTML.cleaner.tidy(result)
127
+ end
128
+ plugin_instances.each do |plugin|
129
+ if plugin.respond_to?(:postprocess_asciidoc_string)
130
+ plugin.asciidoc_string = result
131
+ track_time "Postprocessing AsciiDoc string with #{plugin.name} plugin" do
132
+ plugin.postprocess_asciidoc_string
133
+ end
134
+ result = plugin.asciidoc_string
124
135
  end
125
- result = plugin.asciidoc_string
126
136
  end
137
+
138
+ result
127
139
  end
128
- result
140
+ end
141
+
142
+ def self.prepare_plugin_instances(options)
143
+ options[:plugin_instances] || Coradoc::Input::HTML.config.plugins.map(&:new)
129
144
  end
130
145
 
131
146
  @track_time_indentation = 0
132
147
  def self.track_time(task)
133
- if ReverseAdoc.config.track_time
148
+ if Input::HTML.config.track_time
134
149
  warn " " * @track_time_indentation +
135
150
  "* #{task} is starting..."
136
151
  @track_time_indentation += 1
@@ -1,9 +1,9 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  class Plugin
3
3
  #### Plugin system general
4
4
 
5
5
  # Allow building plugins with a shorthand syntax:
6
- # plugin = Coradoc::ReverseAdoc::Plugin.new do
6
+ # plugin = Coradoc::Input::HTML::Plugin.new do
7
7
  # def name = "Test"
8
8
  # end
9
9
 
@@ -53,12 +53,12 @@ module Coradoc::ReverseAdoc
53
53
  end
54
54
  end
55
55
 
56
- def html_tree_process_to_coradoc(tree, state={})
57
- Coradoc::ReverseAdoc::Converters.process_coradoc(tree, state)
56
+ def html_tree_process_to_coradoc(tree, state = {})
57
+ Coradoc::Input::HTML::Converters.process_coradoc(tree, state)
58
58
  end
59
59
 
60
- def html_tree_process_to_adoc(tree, state={})
61
- Coradoc::ReverseAdoc::Converters.process(tree, state)
60
+ def html_tree_process_to_adoc(tree, state = {})
61
+ Coradoc::Input::HTML::Converters.process(tree, state)
62
62
  end
63
63
 
64
64
  def html_tree_preview