coradoc-html 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 (124) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/lib/coradoc/html/base.rb +157 -0
  4. data/lib/coradoc/html/config.rb +467 -0
  5. data/lib/coradoc/html/converter_base.rb +177 -0
  6. data/lib/coradoc/html/converters/admonition.rb +180 -0
  7. data/lib/coradoc/html/converters/attribute.rb +68 -0
  8. data/lib/coradoc/html/converters/attribute_reference.rb +60 -0
  9. data/lib/coradoc/html/converters/audio.rb +165 -0
  10. data/lib/coradoc/html/converters/base.rb +615 -0
  11. data/lib/coradoc/html/converters/bibliography.rb +82 -0
  12. data/lib/coradoc/html/converters/bibliography_entry.rb +108 -0
  13. data/lib/coradoc/html/converters/block_image.rb +72 -0
  14. data/lib/coradoc/html/converters/bold.rb +34 -0
  15. data/lib/coradoc/html/converters/break.rb +32 -0
  16. data/lib/coradoc/html/converters/comment_block.rb +42 -0
  17. data/lib/coradoc/html/converters/comment_line.rb +54 -0
  18. data/lib/coradoc/html/converters/cross_reference.rb +59 -0
  19. data/lib/coradoc/html/converters/document.rb +108 -0
  20. data/lib/coradoc/html/converters/example.rb +114 -0
  21. data/lib/coradoc/html/converters/highlight.rb +34 -0
  22. data/lib/coradoc/html/converters/include.rb +68 -0
  23. data/lib/coradoc/html/converters/inline_image.rb +41 -0
  24. data/lib/coradoc/html/converters/italic.rb +34 -0
  25. data/lib/coradoc/html/converters/line_break.rb +31 -0
  26. data/lib/coradoc/html/converters/link.rb +46 -0
  27. data/lib/coradoc/html/converters/list_item.rb +75 -0
  28. data/lib/coradoc/html/converters/listing.rb +99 -0
  29. data/lib/coradoc/html/converters/literal.rb +102 -0
  30. data/lib/coradoc/html/converters/monospace.rb +34 -0
  31. data/lib/coradoc/html/converters/open.rb +78 -0
  32. data/lib/coradoc/html/converters/ordered.rb +53 -0
  33. data/lib/coradoc/html/converters/paragraph.rb +46 -0
  34. data/lib/coradoc/html/converters/quote.rb +113 -0
  35. data/lib/coradoc/html/converters/reviewer_comment.rb +74 -0
  36. data/lib/coradoc/html/converters/reviewer_note.rb +134 -0
  37. data/lib/coradoc/html/converters/section.rb +90 -0
  38. data/lib/coradoc/html/converters/sidebar.rb +113 -0
  39. data/lib/coradoc/html/converters/source.rb +137 -0
  40. data/lib/coradoc/html/converters/source_code.rb +16 -0
  41. data/lib/coradoc/html/converters/span.rb +61 -0
  42. data/lib/coradoc/html/converters/strikethrough.rb +34 -0
  43. data/lib/coradoc/html/converters/subscript.rb +34 -0
  44. data/lib/coradoc/html/converters/superscript.rb +34 -0
  45. data/lib/coradoc/html/converters/table.rb +85 -0
  46. data/lib/coradoc/html/converters/table_cell.rb +203 -0
  47. data/lib/coradoc/html/converters/table_row.rb +45 -0
  48. data/lib/coradoc/html/converters/template_html_converter.rb +105 -0
  49. data/lib/coradoc/html/converters/term.rb +58 -0
  50. data/lib/coradoc/html/converters/text_element.rb +44 -0
  51. data/lib/coradoc/html/converters/underline.rb +34 -0
  52. data/lib/coradoc/html/converters/unordered.rb +47 -0
  53. data/lib/coradoc/html/converters/verse.rb +105 -0
  54. data/lib/coradoc/html/converters/video.rb +179 -0
  55. data/lib/coradoc/html/element_mapping.rb +210 -0
  56. data/lib/coradoc/html/entity.rb +137 -0
  57. data/lib/coradoc/html/input/cleaner.rb +163 -0
  58. data/lib/coradoc/html/input/config.rb +79 -0
  59. data/lib/coradoc/html/input/converters/a.rb +90 -0
  60. data/lib/coradoc/html/input/converters/aside.rb +23 -0
  61. data/lib/coradoc/html/input/converters/audio.rb +50 -0
  62. data/lib/coradoc/html/input/converters/base.rb +116 -0
  63. data/lib/coradoc/html/input/converters/blockquote.rb +25 -0
  64. data/lib/coradoc/html/input/converters/br.rb +19 -0
  65. data/lib/coradoc/html/input/converters/bypass.rb +83 -0
  66. data/lib/coradoc/html/input/converters/code.rb +25 -0
  67. data/lib/coradoc/html/input/converters/div.rb +25 -0
  68. data/lib/coradoc/html/input/converters/dl.rb +106 -0
  69. data/lib/coradoc/html/input/converters/drop.rb +28 -0
  70. data/lib/coradoc/html/input/converters/em.rb +23 -0
  71. data/lib/coradoc/html/input/converters/figure.rb +58 -0
  72. data/lib/coradoc/html/input/converters/h.rb +76 -0
  73. data/lib/coradoc/html/input/converters/head.rb +30 -0
  74. data/lib/coradoc/html/input/converters/hr.rb +20 -0
  75. data/lib/coradoc/html/input/converters/ignore.rb +22 -0
  76. data/lib/coradoc/html/input/converters/img.rb +110 -0
  77. data/lib/coradoc/html/input/converters/li.rb +35 -0
  78. data/lib/coradoc/html/input/converters/mark.rb +21 -0
  79. data/lib/coradoc/html/input/converters/markup.rb +107 -0
  80. data/lib/coradoc/html/input/converters/math.rb +46 -0
  81. data/lib/coradoc/html/input/converters/ol.rb +46 -0
  82. data/lib/coradoc/html/input/converters/p.rb +81 -0
  83. data/lib/coradoc/html/input/converters/pass_through.rb +19 -0
  84. data/lib/coradoc/html/input/converters/pre.rb +59 -0
  85. data/lib/coradoc/html/input/converters/q.rb +24 -0
  86. data/lib/coradoc/html/input/converters/strong.rb +22 -0
  87. data/lib/coradoc/html/input/converters/sub.rb +40 -0
  88. data/lib/coradoc/html/input/converters/sup.rb +40 -0
  89. data/lib/coradoc/html/input/converters/table.rb +64 -0
  90. data/lib/coradoc/html/input/converters/td.rb +70 -0
  91. data/lib/coradoc/html/input/converters/text.rb +67 -0
  92. data/lib/coradoc/html/input/converters/th.rb +20 -0
  93. data/lib/coradoc/html/input/converters/tr.rb +28 -0
  94. data/lib/coradoc/html/input/converters/video.rb +53 -0
  95. data/lib/coradoc/html/input/converters.rb +122 -0
  96. data/lib/coradoc/html/input/errors.rb +22 -0
  97. data/lib/coradoc/html/input/html_converter.rb +170 -0
  98. data/lib/coradoc/html/input/plugin.rb +169 -0
  99. data/lib/coradoc/html/input/plugins/plateau.rb +229 -0
  100. data/lib/coradoc/html/input/postprocessor.rb +31 -0
  101. data/lib/coradoc/html/input.rb +68 -0
  102. data/lib/coradoc/html/output.rb +95 -0
  103. data/lib/coradoc/html/renderer.rb +409 -0
  104. data/lib/coradoc/html/spa.rb +309 -0
  105. data/lib/coradoc/html/static.rb +293 -0
  106. data/lib/coradoc/html/template_config.rb +151 -0
  107. data/lib/coradoc/html/template_helpers.rb +58 -0
  108. data/lib/coradoc/html/template_locator.rb +114 -0
  109. data/lib/coradoc/html/theme/base.rb +231 -0
  110. data/lib/coradoc/html/theme/classic_renderer.rb +390 -0
  111. data/lib/coradoc/html/theme/modern/components/ui_components.rb +344 -0
  112. data/lib/coradoc/html/theme/modern/css_generator.rb +311 -0
  113. data/lib/coradoc/html/theme/modern/javascript_generator.rb +314 -0
  114. data/lib/coradoc/html/theme/modern/serializers/document_serializer.rb +382 -0
  115. data/lib/coradoc/html/theme/modern/tailwind_config_builder.rb +164 -0
  116. data/lib/coradoc/html/theme/modern/vue_template_generator.rb +374 -0
  117. data/lib/coradoc/html/theme/modern_renderer.rb +250 -0
  118. data/lib/coradoc/html/theme/registry.rb +153 -0
  119. data/lib/coradoc/html/theme.rb +13 -0
  120. data/lib/coradoc/html/transform/from_core_model.rb +32 -0
  121. data/lib/coradoc/html/transform/to_core_model.rb +39 -0
  122. data/lib/coradoc/html/version.rb +7 -0
  123. data/lib/coradoc/html.rb +255 -0
  124. metadata +264 -0
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Input
5
+ module Html
6
+ class Plugin
7
+ #### Plugin system general
8
+
9
+ # Allow building plugins with a shorthand syntax:
10
+ # plugin = Coradoc::Html::Input::Plugin.new do
11
+ # def name = "Test"
12
+ # end
13
+
14
+ def self.new(&block)
15
+ if self == Plugin
16
+ Class.new(Plugin, &block)
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ @html_tree_hooks_pre = {}
24
+ @html_tree_hooks_post = {}
25
+ end
26
+
27
+ # define name to name a Plugin
28
+ def name
29
+ self.class.name
30
+ end
31
+
32
+ #### HTML Tree functionalities
33
+
34
+ attr_accessor :html_tree, :coremodel_tree, :output_string
35
+
36
+ # Legacy accessors for backward compatibility
37
+ # @deprecated Use coremodel_tree instead. Will be removed in v2.0.
38
+ def coradoc_tree
39
+ warn '[DEPRECATION] `coradoc_tree` is deprecated. Use `coremodel_tree` instead.'
40
+ coremodel_tree
41
+ end
42
+
43
+ def coradoc_tree=(value)
44
+ warn '[DEPRECATION] `coradoc_tree=` is deprecated. Use `coremodel_tree=` instead.'
45
+ self.coremodel_tree = value
46
+ end
47
+
48
+ # @deprecated Use output_string instead. Will be removed in v2.0.
49
+ def asciidoc_string
50
+ warn '[DEPRECATION] `asciidoc_string` is deprecated. Use `output_string` instead.'
51
+ output_string
52
+ end
53
+
54
+ def asciidoc_string=(value)
55
+ warn '[DEPRECATION] `asciidoc_string=` is deprecated. Use `output_string=` instead.'
56
+ self.output_string = value
57
+ end
58
+
59
+ def html_tree_change_tag_name_by_css(css, new_name)
60
+ html_tree.css(css).each do |e|
61
+ e.name = new_name
62
+ end
63
+ end
64
+
65
+ def html_tree_change_properties_by_css(css, properties)
66
+ html_tree.css(css).each do |e|
67
+ properties.each do |k, v|
68
+ e[k.to_s] = v
69
+ end
70
+ end
71
+ end
72
+
73
+ def html_tree_remove_by_css(css)
74
+ html_tree.css(css).each(&:remove)
75
+ end
76
+
77
+ def html_tree_replace_with_children_by_css(css)
78
+ html_tree.css(css).each do |e|
79
+ e.replace(e.children)
80
+ end
81
+ end
82
+
83
+ def html_tree_process_to_coremodel(tree, state = {})
84
+ Coradoc::Html::Input::Converters.process_coradoc(tree, state)
85
+ end
86
+
87
+ # @deprecated Use html_tree_process_to_coremodel instead. Will be removed in v2.0.
88
+ def html_tree_process_to_coradoc(tree, state = {})
89
+ warn '[DEPRECATION] `html_tree_process_to_coradoc` is deprecated. Use `html_tree_process_to_coremodel` instead.'
90
+ html_tree_process_to_coremodel(tree, state)
91
+ end
92
+
93
+ def html_tree_preview
94
+ Tempfile.open(%w[coradoc .html]) do |i|
95
+ i << html_tree.to_html
96
+ system 'chromium-browser', '--no-sandbox', i.path
97
+ end
98
+ end
99
+
100
+ # define preprocess_html_tree to process HTML trees
101
+
102
+ # Creates a hook to be called instead of converting an element
103
+ # to a CoreModel node.
104
+ #
105
+ # proc |html_node, state|
106
+ # coremodel_node
107
+ # end
108
+ def html_tree_add_hook_pre(element, &block)
109
+ @html_tree_hooks_pre[element] = block
110
+ end
111
+
112
+ def html_tree_add_hook_pre_by_css(css, &block)
113
+ html_tree.css(css).each do |e|
114
+ html_tree_add_hook_pre(e, &block)
115
+ end
116
+ end
117
+
118
+ # Creates a hook to be called after converting an element
119
+ # to a CoreModel node.
120
+ #
121
+ # proc |html_node, coremodel_node, state|
122
+ # coremodel_node
123
+ # end
124
+ def html_tree_add_hook_post(element, &block)
125
+ @html_tree_hooks_post[element] = block
126
+ end
127
+
128
+ def html_tree_add_hook_post_by_css(css, &block)
129
+ html_tree.css(css).each do |e|
130
+ html_tree_add_hook_post(e, &block)
131
+ end
132
+ end
133
+
134
+ def html_tree_run_hooks(node, state, &_block)
135
+ hook_pre = @html_tree_hooks_pre[node]
136
+ hook_post = @html_tree_hooks_post[node]
137
+
138
+ coremodel = hook_pre.call(node, state) if hook_pre
139
+ coremodel ||= yield node, state
140
+
141
+ coremodel = hook_post.call(node, coremodel, state) if hook_post
142
+
143
+ coremodel
144
+ end
145
+
146
+ #### CoreModel tree functionalities
147
+
148
+ # define postprocess_coremodel_tree to change CoreModel tree
149
+
150
+ # @deprecated Use postprocess_coremodel_tree instead. Will be removed in v2.0.
151
+ def postprocess_coradoc_tree
152
+ warn '[DEPRECATION] `postprocess_coradoc_tree` is deprecated. Use `postprocess_coremodel_tree` instead.'
153
+ postprocess_coremodel_tree if public_methods.include?(:postprocess_coremodel_tree)
154
+ end
155
+
156
+ #### Output string functionalities
157
+
158
+ # define postprocess_output_string to change the output string
159
+ # (regardless of target format)
160
+
161
+ # @deprecated Use postprocess_output_string instead. Will be removed in v2.0.
162
+ def postprocess_asciidoc_string
163
+ warn '[DEPRECATION] `postprocess_asciidoc_string` is deprecated. Use `postprocess_output_string` instead.'
164
+ postprocess_output_string if public_methods.include?(:postprocess_output_string)
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Input
5
+ module Html
6
+ class Plugin
7
+ # This plugin enhances documents from the PLATEAU project
8
+ # to extract more data.
9
+ #
10
+ # Usage:
11
+ # coradoc convert -rcoradoc/input/html/plugins/plateau
12
+ # --external-images -u raise --output _out/index.adoc index.html
13
+ class Plateau < Plugin
14
+ def name
15
+ 'PLATEAU'
16
+ end
17
+
18
+ def preprocess_html_tree
19
+ # Let's simplify the tree by removing what's extraneous
20
+ # html_tree_remove_by_css("script, style, img.container_imagebox:not([src])")
21
+ # html_tree_replace_with_children_by_css("div.container_box")
22
+ # html_tree_replace_with_children_by_css("div.col.col-12")
23
+ # html_tree_replace_with_children_by_css(".tabledatatext, .tabledatatextY")
24
+ # html_tree_replace_with_children_by_css("div.row")
25
+ #
26
+ # We can remove that, but it messes up the images and paragraphs.
27
+
28
+ # Remove side menu, so we can generate TOC ourselves
29
+ html_tree_remove_by_css('.sideMenu')
30
+
31
+ # Correct non-semantic classes into semantic HTML tags
32
+ html_tree_change_tag_name_by_css('.titledata', 'h1')
33
+ html_tree_change_tag_name_by_css('.subtitledata', 'h2')
34
+ html_tree_change_tag_name_by_css('.pitemdata', 'h3')
35
+ html_tree_change_tag_name_by_css('.sitemdata', 'h4')
36
+ html_tree_change_tag_name_by_css('td[bgcolor="#D0CECE"]', 'th')
37
+ html_tree_change_tag_name_by_css('td[bgcolor="#d0cece"]', 'th')
38
+ html_tree_change_tag_name_by_css(
39
+ '.framedata, .frame_container_box',
40
+ 'aside'
41
+ )
42
+ html_tree_change_tag_name_by_css('.frame2data', 'pre')
43
+ # Assumption that all code snippets in those documents are XML...
44
+ html_tree_change_properties_by_css(
45
+ '.frame2data',
46
+ class: 'brush:xml;'
47
+ )
48
+
49
+ # Remove some CSS ids that are not important to us
50
+ html_tree_change_properties_by_css('#__nuxt', id: nil)
51
+ html_tree_change_properties_by_css('#__layout', id: nil)
52
+ html_tree_change_properties_by_css('#app', id: nil)
53
+
54
+ # Handle lists of document 02
55
+ html_tree_replace_with_children_by_css('.list_num-wrap')
56
+
57
+ # Convert table/img caption to become a caption
58
+ html_tree.css('.imagedata').each do |e|
59
+ table = e.parent.next&.children&.first
60
+ if table&.name == 'table'
61
+ e.name = 'caption'
62
+ table.prepend_child(e)
63
+ next
64
+ end
65
+
66
+ img = e.parent.previous&.children&.first
67
+ next unless img&.name == 'img' && img['src']
68
+
69
+ title = e.text.strip
70
+ img['title'] = title
71
+ e.remove
72
+ next
73
+ end
74
+
75
+ # Add hooks for H1, H2, H3, H4
76
+ html_tree_add_hook_post_by_css(
77
+ 'h1, h2, h3',
78
+ &method(:handle_headers)
79
+ )
80
+ html_tree_add_hook_post_by_css('h4', &method(:handle_headers_h4))
81
+
82
+ # Table cells aligned to center
83
+ html_tree_change_properties_by_css(
84
+ '.tableTopCenter',
85
+ align: 'center'
86
+ )
87
+
88
+ # Handle non-semantic lists and indentation
89
+ html_tree_add_hook_pre_by_css '.text2data' do |node,|
90
+ text = html_tree_process_to_adoc(node).strip
91
+ next '' if text.empty? || text == "\u3000"
92
+
93
+ if text.start_with?(/\d+\./)
94
+ text = text.sub(/\A\d+.\s*/, '')
95
+ ".. #{text}\n"
96
+ else
97
+ text = text.gsub(/^/, '** ')
98
+ "\n\n//-PT2D\n#{text}\n//-ENDPT2D\n\n"
99
+ end
100
+ end
101
+
102
+ (3..4).each do |i|
103
+ html_tree_add_hook_pre_by_css ".text#{i}data" do |node,|
104
+ text = html_tree_process_to_adoc(node).strip
105
+ next '' if text.empty? || text == "\u3000"
106
+
107
+ text = text.strip.gsub(/^/, "#{'*' * i} ")
108
+ "\n\n//-PT#{i}D\n#{text}\n//-ENDPT#{i}D\n\n"
109
+ end
110
+ end
111
+
112
+ (2..3).each do |i|
113
+ html_tree_add_hook_pre_by_css ".text#{i}data_point ul" do |node,|
114
+ text = html_tree_process_to_adoc(node.children.first.children).strip
115
+
116
+ "#{'*' * i} #{text}\n"
117
+ end
118
+ end
119
+
120
+ (1..20).each do |i|
121
+ html_tree_add_hook_pre_by_css ".numtextdata_num .list_num#{i}" do |node,|
122
+ text = html_tree_process_to_adoc(node).strip
123
+
124
+ "[start=#{i}]\n. #{text}\n"
125
+ end
126
+ end
127
+
128
+ # html_tree_preview
129
+ end
130
+
131
+ IM = /[A-Z0-9]{1,3}/
132
+
133
+ def handle_headers(node, coradoc, _state)
134
+ content = coradoc.content.map(&:content).join
135
+
136
+ if %w[toc0 toc_0].any? { |i| coradoc.id&.start_with?(i) }
137
+ # Special content
138
+ case content.strip
139
+ when 'はじめに' # Introduction
140
+ coradoc.style = 'abstract' # The older version document has ".preface"
141
+ coradoc.level_int = 1
142
+ when '改定の概要' # Revision overview
143
+ coradoc.style = 'abstract' # The older version document has ".preface"
144
+ coradoc.level_int = 1
145
+ when '参考文献' # Bibliography
146
+ coradoc.style = 'bibliography'
147
+ coradoc.level_int = 1
148
+ when '改訂履歴' # Document history
149
+ coradoc.style = 'appendix'
150
+ coradoc.level_int = 1
151
+ when '0 概要' # Overview
152
+ coradoc.style = 'abstract' # I'm not sure this is correct
153
+ coradoc.level_int = 1
154
+ when '索引' # Index
155
+ coradoc.style = 'index' # I'm not sure this is correct
156
+ coradoc.level_int = 1
157
+ else
158
+ warn "Unknown section #{content.inspect}"
159
+ end
160
+ end
161
+
162
+ if node.name == 'h1' && content.start_with?('Annex')
163
+ coradoc.style = 'appendix'
164
+ coradoc.content.first.content.sub!(/\AAnnex [A-Z]/, '')
165
+ end
166
+
167
+ # Remove numbers
168
+ coradoc.content.first.content.sub!(
169
+ /\A(#{IM}\.)*#{IM}[[:space:]]/o,
170
+ ''
171
+ )
172
+
173
+ coradoc
174
+ end
175
+
176
+ def handle_headers_h4(_node, coradoc, _state)
177
+ title = Coradoc.strip_unicode(coradoc.content.first.content)
178
+ case title
179
+ when /\A\(\d+\)(.*)/
180
+ coradoc.level_int = 4
181
+ coradoc.content.first.content = ::Regexp.last_match(1).strip
182
+ coradoc
183
+ when /\A\d+\)(.*)/
184
+ coradoc.level_int = 5
185
+ coradoc.content.first.content = ::Regexp.last_match(1).strip
186
+ coradoc
187
+ when /\A#{IM}\.#{IM}\.#{IM}\.#{IM}(.*)/o
188
+ coradoc.level_int = 4
189
+ coradoc.content.first.content = ::Regexp.last_match(1).strip
190
+ else
191
+ if title.empty?
192
+ # Strip instances of faulty empty paragraphs
193
+ nil
194
+ else
195
+ ["// Unhandled h4 content\n", coradoc]
196
+ end
197
+ end
198
+ end
199
+
200
+ def postprocess_output_string
201
+ str = output_string
202
+
203
+ ### Custom indentation handling
204
+ # If there's a step up, add [none]
205
+ str = str.gsub(%r{\s+//-ENDPT2D\s+//-PT3D\s+}, "\n[none]\n")
206
+ str = str.gsub(%r{\s+//-ENDPT2D\s+//-PT4D\s+}, "\n[none]\n")
207
+ str = str.gsub(%r{\s+//-ENDPT3D\s+//-PT4D\s+}, "\n[none]\n")
208
+ # Collapse blocks of text[2,3]data
209
+ str = str.gsub(%r{\s+//-ENDPT[234]D\s+//-PT[234]D\s+}, "\n\n")
210
+ # In the beginning, add [none]
211
+ str = str.gsub(%r{\s+//-PT[234]D\s+}, "\n\n[none]\n")
212
+ # If following with another list, ensure we readd styling
213
+ str = str.gsub(%r{\s+//-ENDPT[234]D\s+\*}, "\n\n[disc]\n*")
214
+ # Otherwise, clean up
215
+ str = str.gsub(%r{\s+//-ENDPT[234]D\s+}, "\n\n")
216
+
217
+ self.output_string = str
218
+ end
219
+
220
+ # Legacy alias for backward compatibility
221
+ # @deprecated Use postprocess_output_string instead. Will be removed in v2.0.
222
+ alias postprocess_asciidoc_string postprocess_output_string
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
228
+
229
+ Coradoc::Input::Html.config.plugins << Coradoc::Input::Html::Plugin::Plateau
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Input
5
+ module Html
6
+ # Postprocessor's aim is to convert a Coradoc tree from
7
+ # a mess that has been created from HTML into a tree that
8
+ # is compatible with what we would get out of Coradoc, if
9
+ # it parsed it directly.
10
+ #
11
+ # Now operates on CoreModel types exclusively.
12
+ class Postprocessor
13
+ def self.process(coradoc)
14
+ new(coradoc).process
15
+ end
16
+
17
+ def initialize(coradoc)
18
+ @tree = coradoc
19
+ end
20
+
21
+ # Main processing entry point
22
+ def process
23
+ # For now, just return the tree as-is since CoreModel
24
+ # structure is already clean and well-formed.
25
+ # Future: implement CoreModel-based postprocessing
26
+ @tree
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'nokogiri'
5
+ require 'coradoc/input'
6
+
7
+ module Coradoc
8
+ module Input
9
+ module Html
10
+ # Autoload all components
11
+ autoload :Errors, 'coradoc/html/input/errors'
12
+ autoload :Cleaner, 'coradoc/html/input/cleaner'
13
+ autoload :Config, 'coradoc/html/input/config'
14
+ autoload :Plugin, 'coradoc/html/input/plugin'
15
+ autoload :Postprocessor, 'coradoc/html/input/postprocessor'
16
+ autoload :Converters, 'coradoc/html/input/converters'
17
+ autoload :HtmlConverter, 'coradoc/html/input/html_converter'
18
+
19
+ def self.convert(input, options = {})
20
+ HtmlConverter.convert(input, options)
21
+ end
22
+
23
+ def self.to_coradoc(input, options = {})
24
+ HtmlConverter.to_coradoc(input, options)
25
+ end
26
+
27
+ def self.config
28
+ @config ||= Config.new
29
+ yield @config if block_given?
30
+ @config
31
+ end
32
+
33
+ def self.cleaner
34
+ @cleaner ||= Cleaner.new
35
+ end
36
+
37
+ def self.processor_id
38
+ :html
39
+ end
40
+
41
+ def self.processor_match?(filename)
42
+ %w[.html .htm].any? { |i| filename.downcase.end_with?(i) }
43
+ end
44
+
45
+ def self.processor_execute(input, options = {})
46
+ to_coradoc(input, options)
47
+ end
48
+
49
+ def self.processor_postprocess(data, options)
50
+ if options[:output_processor] == :adoc
51
+ data.transform_values do |v|
52
+ Input::Html::HtmlConverter.cleanup_result(v, options)
53
+ end
54
+ else
55
+ data
56
+ end
57
+ end
58
+
59
+ Coradoc::Input.define(self)
60
+ end
61
+ end
62
+
63
+ # Backward compatibility alias
64
+ # Some legacy code references Coradoc::Html::Input instead of Coradoc::Input::Html
65
+ module Html
66
+ Input = Coradoc::Input::Html
67
+ end
68
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'coradoc/output'
4
+
5
+ module Coradoc
6
+ module Output
7
+ # Static HTML output processor
8
+ #
9
+ # Generates static HTML documents from CoreModel using the classic
10
+ # rendering approach without JavaScript frameworks.
11
+ #
12
+ # @example Using the processor directly
13
+ # html = Coradoc::Output::HtmlStatic.processor_execute({ "doc.html" => document }, {})
14
+ #
15
+ # @example Using through Output module
16
+ # result = Coradoc::Output.process(document, format: :html_static)
17
+ #
18
+ class HtmlStatic
19
+ class << self
20
+ # Processor identifier for registration
21
+ # @return [Symbol] the processor ID
22
+ def processor_id
23
+ :html_static
24
+ end
25
+
26
+ # Check if this processor matches a given filename
27
+ # @param filename [String] the filename to check
28
+ # @return [Boolean] true if this processor handles the file type
29
+ def processor_match?(filename)
30
+ %w[.html .htm].any? { |ext| filename.downcase.end_with?(ext) }
31
+ end
32
+
33
+ # Process documents to static HTML
34
+ # @param input [Hash<String, Object>] mapping of filenames to documents
35
+ # @param options [Hash] processing options
36
+ # @return [Hash<String, String>] mapping of filenames to HTML output
37
+ def processor_execute(input, options = {})
38
+ result = {}
39
+ input.each do |filename, document|
40
+ html = Coradoc::Html::Static.convert(document, options)
41
+ result[filename] = html
42
+ end
43
+ result
44
+ end
45
+ end
46
+ end
47
+
48
+ # SPA (Single Page Application) HTML output processor
49
+ #
50
+ # Generates modern Vue.js + Tailwind CSS HTML documents from CoreModel.
51
+ #
52
+ # @example Using the processor directly
53
+ # html = Coradoc::Output::HtmlSpa.processor_execute({ "doc.html" => document }, {})
54
+ #
55
+ # @example Using through Output module
56
+ # result = Coradoc::Output.process(document, format: :html_spa)
57
+ #
58
+ class HtmlSpa
59
+ class << self
60
+ # Processor identifier for registration
61
+ # @return [Symbol] the processor ID
62
+ def processor_id
63
+ :html_spa
64
+ end
65
+
66
+ # Check if this processor matches a given filename
67
+ # @param filename [String] the filename to check
68
+ # @return [Boolean] true if this processor handles the file type
69
+ def processor_match?(filename)
70
+ %w[.html .htm].any? { |ext| filename.downcase.end_with?(ext) }
71
+ end
72
+
73
+ # Process documents to SPA HTML
74
+ # @param input [Hash<String, Object>] mapping of filenames to documents
75
+ # @param options [Hash] processing options
76
+ # @return [Hash<String, String>] mapping of filenames to SPA HTML output
77
+ def processor_execute(input, options = {})
78
+ result = {}
79
+ input.each do |filename, document|
80
+ html = Coradoc::Html::Spa.convert(document, options)
81
+ result[filename] = html
82
+ end
83
+ result
84
+ end
85
+ end
86
+ end
87
+
88
+ # Alias for HtmlSpa
89
+ Spa = HtmlSpa
90
+ end
91
+ end
92
+
93
+ # Register processors with the Output module
94
+ Coradoc::Output.define(Coradoc::Output::HtmlStatic)
95
+ Coradoc::Output.define(Coradoc::Output::HtmlSpa)