coradoc 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) 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 +6 -5
  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 +10 -2
  37. data/lib/coradoc/element/list_item.rb +7 -5
  38. data/lib/coradoc/element/paragraph.rb +8 -5
  39. data/lib/coradoc/element/revision.rb +1 -1
  40. data/lib/coradoc/element/section.rb +6 -4
  41. data/lib/coradoc/element/table.rb +2 -2
  42. data/lib/coradoc/element/tag.rb +19 -0
  43. data/lib/coradoc/element/term.rb +21 -0
  44. data/lib/coradoc/element/text_element.rb +9 -1
  45. data/lib/coradoc/element/title.rb +1 -1
  46. data/lib/coradoc/generator.rb +2 -0
  47. data/lib/coradoc/input/adoc.rb +28 -0
  48. data/lib/coradoc/input/docx.rb +35 -0
  49. data/lib/coradoc/{reverse_adoc → input/html}/README.adoc +9 -9
  50. data/lib/coradoc/{reverse_adoc → input/html}/cleaner.rb +18 -4
  51. data/lib/coradoc/input/html/config.rb +75 -0
  52. data/lib/coradoc/{reverse_adoc → input/html}/converters/a.rb +1 -1
  53. data/lib/coradoc/{reverse_adoc → input/html}/converters/aside.rb +1 -1
  54. data/lib/coradoc/{reverse_adoc → input/html}/converters/audio.rb +1 -1
  55. data/lib/coradoc/{reverse_adoc → input/html}/converters/base.rb +7 -7
  56. data/lib/coradoc/{reverse_adoc → input/html}/converters/blockquote.rb +2 -2
  57. data/lib/coradoc/{reverse_adoc → input/html}/converters/br.rb +1 -1
  58. data/lib/coradoc/{reverse_adoc → input/html}/converters/bypass.rb +1 -1
  59. data/lib/coradoc/{reverse_adoc → input/html}/converters/code.rb +1 -1
  60. data/lib/coradoc/{reverse_adoc → input/html}/converters/div.rb +1 -1
  61. data/lib/coradoc/{reverse_adoc → input/html}/converters/dl.rb +1 -1
  62. data/lib/coradoc/{reverse_adoc → input/html}/converters/drop.rb +1 -1
  63. data/lib/coradoc/{reverse_adoc → input/html}/converters/em.rb +1 -1
  64. data/lib/coradoc/{reverse_adoc → input/html}/converters/figure.rb +1 -1
  65. data/lib/coradoc/{reverse_adoc → input/html}/converters/h.rb +8 -6
  66. data/lib/coradoc/{reverse_adoc → input/html}/converters/head.rb +1 -1
  67. data/lib/coradoc/{reverse_adoc → input/html}/converters/hr.rb +1 -1
  68. data/lib/coradoc/{reverse_adoc → input/html}/converters/ignore.rb +1 -1
  69. data/lib/coradoc/{reverse_adoc → input/html}/converters/img.rb +7 -7
  70. data/lib/coradoc/{reverse_adoc → input/html}/converters/li.rb +1 -1
  71. data/lib/coradoc/{reverse_adoc → input/html}/converters/mark.rb +1 -1
  72. data/lib/coradoc/{reverse_adoc → input/html}/converters/markup.rb +1 -1
  73. data/lib/coradoc/{reverse_adoc → input/html}/converters/math.rb +3 -3
  74. data/lib/coradoc/{reverse_adoc → input/html}/converters/ol.rb +1 -1
  75. data/lib/coradoc/{reverse_adoc → input/html}/converters/p.rb +1 -1
  76. data/lib/coradoc/{reverse_adoc → input/html}/converters/pass_through.rb +1 -1
  77. data/lib/coradoc/{reverse_adoc → input/html}/converters/pre.rb +1 -1
  78. data/lib/coradoc/{reverse_adoc → input/html}/converters/q.rb +1 -1
  79. data/lib/coradoc/{reverse_adoc → input/html}/converters/strong.rb +1 -1
  80. data/lib/coradoc/{reverse_adoc → input/html}/converters/sub.rb +1 -1
  81. data/lib/coradoc/{reverse_adoc → input/html}/converters/sup.rb +1 -1
  82. data/lib/coradoc/{reverse_adoc → input/html}/converters/table.rb +4 -4
  83. data/lib/coradoc/{reverse_adoc → input/html}/converters/td.rb +1 -1
  84. data/lib/coradoc/{reverse_adoc → input/html}/converters/text.rb +2 -2
  85. data/lib/coradoc/{reverse_adoc → input/html}/converters/th.rb +1 -1
  86. data/lib/coradoc/{reverse_adoc → input/html}/converters/tr.rb +1 -1
  87. data/lib/coradoc/{reverse_adoc → input/html}/converters/video.rb +1 -1
  88. data/lib/coradoc/input/html/converters.rb +57 -0
  89. data/lib/coradoc/input/html/errors.rb +12 -0
  90. data/lib/coradoc/{reverse_adoc → input/html}/html_converter.rb +37 -22
  91. data/lib/coradoc/{reverse_adoc → input/html}/plugin.rb +6 -6
  92. data/lib/coradoc/{reverse_adoc → input/html}/plugins/plateau.rb +3 -3
  93. data/lib/coradoc/{reverse_adoc → input/html}/postprocessor.rb +3 -3
  94. data/lib/coradoc/input/html.rb +59 -0
  95. data/lib/coradoc/input.rb +12 -0
  96. data/lib/coradoc/output/adoc.rb +17 -0
  97. data/lib/coradoc/output/coradoc_tree_debug.rb +19 -0
  98. data/lib/coradoc/output.rb +11 -0
  99. data/lib/coradoc/parser/asciidoc/admonition.rb +24 -0
  100. data/lib/coradoc/parser/asciidoc/attribute_list.rb +67 -0
  101. data/lib/coradoc/parser/asciidoc/base.rb +101 -13
  102. data/lib/coradoc/parser/asciidoc/bibliography.rb +30 -0
  103. data/lib/coradoc/parser/asciidoc/block.rb +82 -0
  104. data/lib/coradoc/parser/asciidoc/citation.rb +48 -0
  105. data/lib/coradoc/parser/asciidoc/content.rb +15 -120
  106. data/lib/coradoc/parser/asciidoc/document_attributes.rb +12 -5
  107. data/lib/coradoc/parser/asciidoc/header.rb +1 -4
  108. data/lib/coradoc/parser/asciidoc/inline.rb +72 -0
  109. data/lib/coradoc/parser/asciidoc/list.rb +81 -0
  110. data/lib/coradoc/parser/asciidoc/paragraph.rb +33 -0
  111. data/lib/coradoc/parser/asciidoc/section.rb +36 -31
  112. data/lib/coradoc/parser/asciidoc/table.rb +32 -0
  113. data/lib/coradoc/parser/asciidoc/term.rb +23 -0
  114. data/lib/coradoc/parser/base.rb +39 -4
  115. data/lib/coradoc/reverse_adoc.rb +16 -28
  116. data/lib/coradoc/transformer.rb +353 -82
  117. data/lib/coradoc/util.rb +1 -1
  118. data/lib/coradoc/version.rb +1 -1
  119. data/lib/coradoc.rb +8 -5
  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 +112 -53
  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 -55
  131. data/lib/coradoc/reverse_adoc/errors.rb +0 -10
  132. /data/{.docker/Dockerfile → Dockerfile} +0 -0
  133. /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
 
@@ -51,7 +51,7 @@ module Coradoc::ReverseAdoc
51
51
  return copy_temp_file(imgdata) if imgdata
52
52
 
53
53
  ext = File.extname(src).strip.downcase[1..-1]
54
- [ext, Pathname.new(Coradoc::ReverseAdoc.config.sourcedir).join(src)]
54
+ [ext, Pathname.new(Coradoc::Input::HTML.config.sourcedir).join(src)]
55
55
  end
56
56
 
57
57
  def copy_temp_file(imgdata)
@@ -76,7 +76,7 @@ module Coradoc::ReverseAdoc
76
76
 
77
77
  title = extract_title(node)
78
78
 
79
- if Coradoc::ReverseAdoc.config.external_images
79
+ if Coradoc::Input::HTML.config.external_images
80
80
  # puts "external image conversion #{id}, #{src}"
81
81
  src = datauri2file(src)
82
82
  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)
@@ -238,7 +238,7 @@ module Coradoc::ReverseAdoc
238
238
  end
239
239
  end
240
240
 
241
- document_width = Coradoc::ReverseAdoc.config.doc_width.to_r
241
+ document_width = Coradoc::Input::HTML.config.doc_width.to_r
242
242
 
243
243
  column_sizes += [nil] * (cpr.first - column_sizes.length)
244
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
@@ -1,10 +1,10 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  class Plugin
3
3
  # This plugin enhances documents from the PLATEAU project
4
4
  # to extract more data.
5
5
  #
6
6
  # Usage:
7
- # reverse_adoc -rcoradoc/reverse_adoc/plugins/plateau
7
+ # reverse_adoc -rcoradoc/input/html/plugins/plateau
8
8
  # --external-images -u raise --output _out/index.adoc index.html
9
9
  class Plateau < Plugin
10
10
  def name
@@ -203,4 +203,4 @@ module Coradoc::ReverseAdoc
203
203
  end
204
204
  end
205
205
 
206
- Coradoc::ReverseAdoc.config.plugins << Coradoc::ReverseAdoc::Plugin::Plateau
206
+ Coradoc::Input::HTML.config.plugins << Coradoc::Input::HTML::Plugin::Plateau
@@ -1,4 +1,4 @@
1
- module Coradoc::ReverseAdoc
1
+ module Coradoc::Input::HTML
2
2
  # Postprocessor's aim is to convert a Coradoc tree from
3
3
  # a mess that has been created from HTML into a tree that
4
4
  # is compatible with what we would get out of Coradoc, if
@@ -73,7 +73,7 @@ module Coradoc::ReverseAdoc
73
73
  end
74
74
 
75
75
  def split_sections
76
- max_level = Coradoc::ReverseAdoc.config.split_sections
76
+ max_level = Coradoc::Input::HTML.config.split_sections
77
77
 
78
78
  return unless max_level
79
79
 
@@ -111,7 +111,7 @@ module Coradoc::ReverseAdoc
111
111
  # we can compute numbers
112
112
  previous_sections[elem] = parent_sections[title.level_int]
113
113
  parent_sections[title.level_int] = elem
114
- parent_sections[(title.level_int+1)..nil] = nil
114
+ parent_sections[(title.level_int + 1)..nil] = nil
115
115
 
116
116
  elem
117
117
  else
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "nokogiri"
5
+ require "coradoc/input"
6
+ require_relative "html/errors"
7
+ require_relative "html/cleaner"
8
+ require_relative "html/config"
9
+ require_relative "html/converters"
10
+ require_relative "html/converters/base"
11
+ require_relative "html/html_converter"
12
+ require_relative "html/plugin"
13
+ require_relative "html/postprocessor"
14
+
15
+ module Coradoc
16
+ module Input::HTML
17
+ def self.convert(input, options = {})
18
+ Coradoc::Input::HTML::HtmlConverter.convert(input, options)
19
+ end
20
+
21
+ def self.to_coradoc(input, options = {})
22
+ Input::HTML::HtmlConverter.to_coradoc(input, options)
23
+ end
24
+
25
+ def self.config
26
+ @config ||= Config.new
27
+ yield @config if block_given?
28
+ @config
29
+ end
30
+
31
+ def self.cleaner
32
+ @cleaner ||= Cleaner.new
33
+ end
34
+
35
+ def self.processor_id
36
+ :html
37
+ end
38
+
39
+ def self.processor_match?(filename)
40
+ %w[.html .htm].any? { |i| filename.downcase.end_with?(i) }
41
+ end
42
+
43
+ def self.processor_execute(input, options = {})
44
+ to_coradoc(input, options)
45
+ end
46
+
47
+ def self.processor_postprocess(data, options)
48
+ if options[:output_processor] == :adoc
49
+ data.transform_values do |v|
50
+ Input::HTML::HtmlConverter.cleanup_result(v, options)
51
+ end
52
+ else
53
+ data
54
+ end
55
+ end
56
+
57
+ Coradoc::Input.define(self)
58
+ end
59
+ end
@@ -0,0 +1,12 @@
1
+ require "coradoc"
2
+
3
+ module Coradoc
4
+ module Input
5
+ @processors = {}
6
+ extend Converter::CommonInputOutputMethods
7
+ end
8
+ end
9
+
10
+ require "coradoc/input/adoc"
11
+ require "coradoc/input/docx"
12
+ require "coradoc/input/html"
@@ -0,0 +1,17 @@
1
+ module Coradoc
2
+ module Output::Adoc
3
+ def self.processor_id
4
+ :adoc
5
+ end
6
+
7
+ def self.processor_match?(filename)
8
+ %w[.adoc].any? { |i| filename.downcase.end_with?(i) }
9
+ end
10
+
11
+ def self.processor_execute(input, _options = {})
12
+ input.transform_values { |i| Coradoc::Generator.gen_adoc(i) }
13
+ end
14
+
15
+ Coradoc::Output.define(self)
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Coradoc
2
+ module Output::CoradocTreeDebug
3
+ def self.processor_id
4
+ :coradoc_tree_debug
5
+ end
6
+
7
+ def self.processor_match?(filename)
8
+ false
9
+ end
10
+
11
+ def self.processor_execute(input, _options = {})
12
+ out = StringIO.new
13
+ PP.pp(input, out)
14
+ { nil => out.string }
15
+ end
16
+
17
+ Coradoc::Output.define(self)
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require "coradoc"
2
+
3
+ module Coradoc
4
+ module Output
5
+ @processors = {}
6
+ extend Converter::CommonInputOutputMethods
7
+ end
8
+ end
9
+
10
+ require "coradoc/output/adoc"
11
+ require "coradoc/output/coradoc_tree_debug"
@@ -0,0 +1,24 @@
1
+ module Coradoc
2
+ module Parser
3
+ module Asciidoc
4
+ module Admonition
5
+ def admonition_type
6
+ str('NOTE') | str('TIP') | str('EDITOR') |
7
+ str('IMPORTANT') | str('WARNING') | str('CAUTION') |
8
+ str('TODO')
9
+ # requires atypical syntax for access?
10
+ # | str('DANGER')
11
+ # | str('SAFETY PRECAUTION')
12
+ end
13
+ def admonition_line
14
+ admonition_type.as(:admonition_type) >> str(': ') >>
15
+ (
16
+ (text.as(:text) >>
17
+ line_ending.as(:line_break)
18
+ ).repeat(1)
19
+ ).as(:content)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end