coradoc-html 1.1.7 → 1.1.13

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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/lib/coradoc/html/config.rb +36 -12
  3. data/lib/coradoc/html/converter_base.rb +26 -68
  4. data/lib/coradoc/html/drop/annotation_drop.rb +31 -0
  5. data/lib/coradoc/html/drop/base.rb +77 -0
  6. data/lib/coradoc/html/drop/bibliography_drop.rb +15 -0
  7. data/lib/coradoc/html/drop/bibliography_entry_drop.rb +24 -0
  8. data/lib/coradoc/html/drop/block_drop.rb +69 -0
  9. data/lib/coradoc/html/drop/definition_item_drop.rb +36 -0
  10. data/lib/coradoc/html/drop/definition_list_drop.rb +15 -0
  11. data/lib/coradoc/html/drop/document_drop.rb +52 -0
  12. data/lib/coradoc/html/drop/drop_factory.rb +73 -0
  13. data/lib/coradoc/html/drop/footnote_drop.rb +24 -0
  14. data/lib/coradoc/html/drop/image_drop.rb +35 -0
  15. data/lib/coradoc/html/drop/inline_element_drop.rb +64 -0
  16. data/lib/coradoc/html/drop/list_block_drop.rb +23 -0
  17. data/lib/coradoc/html/drop/list_item_drop.rb +20 -0
  18. data/lib/coradoc/html/drop/table_cell_drop.rb +35 -0
  19. data/lib/coradoc/html/drop/table_drop.rb +15 -0
  20. data/lib/coradoc/html/drop/table_row_drop.rb +23 -0
  21. data/lib/coradoc/html/drop/term_drop.rb +24 -0
  22. data/lib/coradoc/html/drop/text_content_drop.rb +15 -0
  23. data/lib/coradoc/html/drop/toc_drop.rb +15 -0
  24. data/lib/coradoc/html/drop/toc_entry_drop.rb +32 -0
  25. data/lib/coradoc/html/escape.rb +29 -0
  26. data/lib/coradoc/html/input/cleaner.rb +4 -33
  27. data/lib/coradoc/html/input/config.rb +4 -3
  28. data/lib/coradoc/html/input/converters/a.rb +8 -19
  29. data/lib/coradoc/html/input/converters/aside.rb +4 -5
  30. data/lib/coradoc/html/input/converters/audio.rb +8 -35
  31. data/lib/coradoc/html/input/converters/base.rb +29 -27
  32. data/lib/coradoc/html/input/converters/blockquote.rb +4 -2
  33. data/lib/coradoc/html/input/converters/br.rb +4 -4
  34. data/lib/coradoc/html/input/converters/bypass.rb +68 -67
  35. data/lib/coradoc/html/input/converters/code.rb +7 -5
  36. data/lib/coradoc/html/input/converters/div.rb +4 -4
  37. data/lib/coradoc/html/input/converters/dl.rb +3 -25
  38. data/lib/coradoc/html/input/converters/drop.rb +13 -13
  39. data/lib/coradoc/html/input/converters/em.rb +5 -3
  40. data/lib/coradoc/html/input/converters/figure.rb +3 -26
  41. data/lib/coradoc/html/input/converters/h.rb +9 -11
  42. data/lib/coradoc/html/input/converters/head.rb +5 -4
  43. data/lib/coradoc/html/input/converters/hr.rb +4 -5
  44. data/lib/coradoc/html/input/converters/img.rb +4 -9
  45. data/lib/coradoc/html/input/converters/li.rb +3 -1
  46. data/lib/coradoc/html/input/converters/mark.rb +3 -1
  47. data/lib/coradoc/html/input/converters/markup.rb +4 -8
  48. data/lib/coradoc/html/input/converters/math.rb +7 -14
  49. data/lib/coradoc/html/input/converters/media_base.rb +50 -0
  50. data/lib/coradoc/html/input/converters/ol.rb +6 -8
  51. data/lib/coradoc/html/input/converters/p.rb +43 -34
  52. data/lib/coradoc/html/input/converters/pass_through.rb +2 -4
  53. data/lib/coradoc/html/input/converters/positional_formatting.rb +37 -0
  54. data/lib/coradoc/html/input/converters/pre.rb +3 -3
  55. data/lib/coradoc/html/input/converters/q.rb +6 -3
  56. data/lib/coradoc/html/input/converters/strong.rb +4 -2
  57. data/lib/coradoc/html/input/converters/sub.rb +7 -23
  58. data/lib/coradoc/html/input/converters/sup.rb +7 -23
  59. data/lib/coradoc/html/input/converters/table.rb +3 -1
  60. data/lib/coradoc/html/input/converters/td.rb +4 -30
  61. data/lib/coradoc/html/input/converters/text.rb +4 -3
  62. data/lib/coradoc/html/input/converters/tr.rb +3 -2
  63. data/lib/coradoc/html/input/converters/video.rb +14 -36
  64. data/lib/coradoc/html/input/converters.rb +17 -35
  65. data/lib/coradoc/html/input/html_converter.rb +2 -74
  66. data/lib/coradoc/html/input/plugin.rb +8 -50
  67. data/lib/coradoc/html/input/plugins/plateau.rb +4 -19
  68. data/lib/coradoc/html/input/postprocessor.rb +3 -9
  69. data/lib/coradoc/html/input.rb +26 -8
  70. data/lib/coradoc/html/layout_renderer.rb +163 -0
  71. data/lib/coradoc/html/output.rb +6 -12
  72. data/lib/coradoc/html/renderer.rb +84 -350
  73. data/lib/coradoc/html/section_numberable.rb +9 -0
  74. data/lib/coradoc/html/spa.rb +29 -270
  75. data/lib/coradoc/html/static.rb +29 -238
  76. data/lib/coradoc/html/template_caching.rb +31 -0
  77. data/lib/coradoc/html/template_config.rb +11 -70
  78. data/lib/coradoc/html/template_helpers.rb +39 -31
  79. data/lib/coradoc/html/template_locator.rb +17 -11
  80. data/lib/coradoc/html/theme.rb +1 -7
  81. data/lib/coradoc/html/title_text.rb +57 -0
  82. data/lib/coradoc/html/toc_builder.rb +105 -0
  83. data/lib/coradoc/html/toc_serializer.rb +33 -0
  84. data/lib/coradoc/html/transform/from_core_model.rb +13 -12
  85. data/lib/coradoc/html/transform/to_core_model.rb +10 -12
  86. data/lib/coradoc/html/version.rb +1 -1
  87. data/lib/coradoc/html.rb +43 -88
  88. metadata +37 -70
  89. data/lib/coradoc/html/base.rb +0 -157
  90. data/lib/coradoc/html/converters/admonition.rb +0 -180
  91. data/lib/coradoc/html/converters/attribute.rb +0 -68
  92. data/lib/coradoc/html/converters/attribute_reference.rb +0 -60
  93. data/lib/coradoc/html/converters/audio.rb +0 -165
  94. data/lib/coradoc/html/converters/base.rb +0 -615
  95. data/lib/coradoc/html/converters/bibliography.rb +0 -82
  96. data/lib/coradoc/html/converters/bibliography_entry.rb +0 -108
  97. data/lib/coradoc/html/converters/block_image.rb +0 -72
  98. data/lib/coradoc/html/converters/bold.rb +0 -34
  99. data/lib/coradoc/html/converters/break.rb +0 -32
  100. data/lib/coradoc/html/converters/comment_block.rb +0 -42
  101. data/lib/coradoc/html/converters/comment_line.rb +0 -54
  102. data/lib/coradoc/html/converters/cross_reference.rb +0 -59
  103. data/lib/coradoc/html/converters/document.rb +0 -108
  104. data/lib/coradoc/html/converters/example.rb +0 -114
  105. data/lib/coradoc/html/converters/highlight.rb +0 -34
  106. data/lib/coradoc/html/converters/include.rb +0 -68
  107. data/lib/coradoc/html/converters/inline_image.rb +0 -41
  108. data/lib/coradoc/html/converters/italic.rb +0 -34
  109. data/lib/coradoc/html/converters/line_break.rb +0 -31
  110. data/lib/coradoc/html/converters/link.rb +0 -46
  111. data/lib/coradoc/html/converters/list_item.rb +0 -75
  112. data/lib/coradoc/html/converters/listing.rb +0 -99
  113. data/lib/coradoc/html/converters/literal.rb +0 -102
  114. data/lib/coradoc/html/converters/monospace.rb +0 -34
  115. data/lib/coradoc/html/converters/open.rb +0 -78
  116. data/lib/coradoc/html/converters/ordered.rb +0 -53
  117. data/lib/coradoc/html/converters/paragraph.rb +0 -46
  118. data/lib/coradoc/html/converters/quote.rb +0 -113
  119. data/lib/coradoc/html/converters/reviewer_comment.rb +0 -74
  120. data/lib/coradoc/html/converters/reviewer_note.rb +0 -134
  121. data/lib/coradoc/html/converters/section.rb +0 -90
  122. data/lib/coradoc/html/converters/sidebar.rb +0 -113
  123. data/lib/coradoc/html/converters/source.rb +0 -137
  124. data/lib/coradoc/html/converters/source_code.rb +0 -16
  125. data/lib/coradoc/html/converters/span.rb +0 -61
  126. data/lib/coradoc/html/converters/strikethrough.rb +0 -34
  127. data/lib/coradoc/html/converters/subscript.rb +0 -34
  128. data/lib/coradoc/html/converters/superscript.rb +0 -34
  129. data/lib/coradoc/html/converters/table.rb +0 -85
  130. data/lib/coradoc/html/converters/table_cell.rb +0 -203
  131. data/lib/coradoc/html/converters/table_row.rb +0 -45
  132. data/lib/coradoc/html/converters/template_html_converter.rb +0 -105
  133. data/lib/coradoc/html/converters/term.rb +0 -58
  134. data/lib/coradoc/html/converters/text_element.rb +0 -44
  135. data/lib/coradoc/html/converters/underline.rb +0 -34
  136. data/lib/coradoc/html/converters/unordered.rb +0 -47
  137. data/lib/coradoc/html/converters/verse.rb +0 -105
  138. data/lib/coradoc/html/converters/video.rb +0 -179
  139. data/lib/coradoc/html/element_mapping.rb +0 -210
  140. data/lib/coradoc/html/entity.rb +0 -137
  141. data/lib/coradoc/html/input/converters/ignore.rb +0 -22
  142. data/lib/coradoc/html/input/converters/th.rb +0 -20
  143. data/lib/coradoc/html/theme/base.rb +0 -231
  144. data/lib/coradoc/html/theme/classic_renderer.rb +0 -390
  145. data/lib/coradoc/html/theme/modern/components/ui_components.rb +0 -344
  146. data/lib/coradoc/html/theme/modern/css_generator.rb +0 -311
  147. data/lib/coradoc/html/theme/modern/javascript_generator.rb +0 -314
  148. data/lib/coradoc/html/theme/modern/serializers/document_serializer.rb +0 -382
  149. data/lib/coradoc/html/theme/modern/tailwind_config_builder.rb +0 -164
  150. data/lib/coradoc/html/theme/modern/vue_template_generator.rb +0 -374
  151. data/lib/coradoc/html/theme/modern_renderer.rb +0 -250
  152. data/lib/coradoc/html/theme/registry.rb +0 -153
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Input
5
+ module Html
6
+ module Converters
7
+ class MediaBase < Base
8
+ def to_coradoc(node, _state = {})
9
+ src = node['src']
10
+ id = node['id']
11
+ title = extract_title(node)
12
+
13
+ Coradoc::CoreModel::Block.new(
14
+ block_semantic_type: semantic_type,
15
+ content: src,
16
+ title: title,
17
+ id: id,
18
+ element_attributes: build_attributes(node)
19
+ )
20
+ end
21
+
22
+ def extract_title(node)
23
+ track = node.at('./track') || node.at('.//source')
24
+ return '' if track.nil?
25
+
26
+ track['label'] || track['srclang'] || ''
27
+ end
28
+
29
+ private
30
+
31
+ def semantic_type
32
+ raise NotImplementedError
33
+ end
34
+
35
+ def base_attributes(node)
36
+ {
37
+ autoplay: node['autoplay'],
38
+ loop: node['loop'],
39
+ controls: node['controls']
40
+ }.compact
41
+ end
42
+
43
+ def build_attributes(node)
44
+ base_attributes(node)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -5,13 +5,11 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Ol < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, state = {})
9
11
  id = node['id']
10
- ol_count = state.fetch(:ol_count, 0) + 1
11
- items = treat_children_coradoc(
12
- node,
13
- state.merge(ol_count: ol_count)
14
- )
12
+ items = treat_children_coradoc(node, state)
15
13
 
16
14
  marker_type = get_list_type(node, state)
17
15
 
@@ -37,9 +35,9 @@ module Coradoc
37
35
  end
38
36
  end
39
37
 
40
- register :ol, Ol.new
41
- register :ul, Ol.new
42
- register :dir, Ol.new
38
+ register :ol, Ol::INSTANCE
39
+ register :ul, Ol::INSTANCE
40
+ register :dir, Ol::INSTANCE
43
41
  end
44
42
  end
45
43
  end
@@ -5,16 +5,15 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class P < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, state = {})
9
11
  id = node['id']
10
12
  content = treat_children_coradoc(node, state)
11
13
 
12
- # Strip full-width spaces from paragraph content
13
14
  content = strip_fullwidth_spaces(content)
14
15
 
15
- Coradoc::CoreModel::Block.new(
16
- block_semantic_type: :paragraph,
17
- element_type: 'paragraph',
16
+ Coradoc::CoreModel::ParagraphBlock.new(
18
17
  children: content,
19
18
  id: id
20
19
  )
@@ -25,38 +24,51 @@ module Coradoc
25
24
  def strip_fullwidth_spaces(content)
26
25
  return content unless content.is_a?(Array)
27
26
 
28
- # Strip full-width spaces from all inline elements
29
27
  content.each do |item|
30
- if item.is_a?(Coradoc::CoreModel::InlineElement) && item.content.is_a?(String)
31
- item.content = item.content.gsub(/\A +| +\z/, '')
32
- elsif item.is_a?(String)
33
- item.gsub(/\A +| +\z/, '')
34
- end
35
- end
28
+ next unless item.is_a?(Coradoc::CoreModel::InlineElement)
29
+ next unless item.content.is_a?(String)
36
30
 
37
- # Strip leading space from first text element
38
- first_text = content.find { |item| item.is_a?(Coradoc::CoreModel::InlineElement) || item.is_a?(String) }
39
- if first_text.is_a?(Coradoc::CoreModel::InlineElement) && first_text.content.is_a?(String)
40
- first_text.content = first_text.content.lstrip
41
- elsif first_text.is_a?(String)
42
- first_text.lstrip
31
+ item.content = item.content.gsub(/\A +| +\z/, '')
43
32
  end
44
33
 
45
- # Strip trailing space from last text element
46
- last_text = content.reverse.find do |item|
47
- item.is_a?(Coradoc::CoreModel::InlineElement) || item.is_a?(String)
34
+ strip_edge_whitespace(content)
35
+ reject_empty_elements(content)
36
+ end
37
+
38
+ def strip_edge_whitespace(content)
39
+ first = content.find { |item| text_element?(item) }
40
+ strip_left(first) if first
41
+
42
+ last = content.reverse.find { |item| text_element?(item) }
43
+ strip_right(last) if last
44
+ end
45
+
46
+ def strip_left(item)
47
+ case item
48
+ when Coradoc::CoreModel::InlineElement
49
+ item.content = item.content.lstrip if item.content.is_a?(String)
50
+ when String
51
+ item.replace(item.lstrip)
48
52
  end
49
- if last_text.is_a?(Coradoc::CoreModel::InlineElement) && last_text.content.is_a?(String)
50
- last_text.content = last_text.content.rstrip
51
- elsif last_text.is_a?(String)
52
- last_text.rstrip
53
+ end
54
+
55
+ def strip_right(item)
56
+ case item
57
+ when Coradoc::CoreModel::InlineElement
58
+ item.content = item.content.rstrip if item.content.is_a?(String)
59
+ when String
60
+ item.replace(item.rstrip)
53
61
  end
62
+ end
54
63
 
55
- # Remove empty text elements after stripping
56
- # But keep InlineElements that have nested_elements (e.g., bold with nested text)
64
+ def text_element?(item)
65
+ item.is_a?(Coradoc::CoreModel::InlineElement) || item.is_a?(String)
66
+ end
67
+
68
+ def reject_empty_elements(content)
57
69
  content.reject do |item|
58
70
  if item.is_a?(Coradoc::CoreModel::InlineElement)
59
- item.content.to_s.empty? && !item_has_nested_content?(item)
71
+ item.content.to_s.empty? && !has_nested_content?(item)
60
72
  elsif item.is_a?(String)
61
73
  item.empty?
62
74
  else
@@ -65,16 +77,13 @@ module Coradoc
65
77
  end
66
78
  end
67
79
 
68
- # Check if InlineElement has meaningful nested content
69
- def item_has_nested_content?(item)
70
- return false unless item.is_a?(Coradoc::CoreModel::InlineElement)
71
- return false if item.nested_elements.nil? || item.nested_elements.empty?
72
-
73
- true
80
+ def has_nested_content?(item)
81
+ item.is_a?(Coradoc::CoreModel::InlineElement) &&
82
+ item.nested_elements && !item.nested_elements.empty?
74
83
  end
75
84
  end
76
85
 
77
- register :p, P.new
86
+ register :p, P::INSTANCE
78
87
  end
79
88
  end
80
89
  end
@@ -5,13 +5,11 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class PassThrough < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, _state = {})
9
11
  node.to_s
10
12
  end
11
-
12
- def convert(node, state = {})
13
- to_coradoc(node, state)
14
- end
15
13
  end
16
14
  end
17
15
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Input
5
+ module Html
6
+ module Converters
7
+ # Shared logic for superscript/subscript converters.
8
+ #
9
+ # Subclasses must implement `element_class` returning the
10
+ # CoreModel class (e.g., SuperscriptElement, SubscriptElement).
11
+ module PositionalFormatting
12
+ def to_coradoc(node, state = {})
13
+ leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)
14
+
15
+ content = treat_children_coradoc(node, state)
16
+
17
+ return nil if content_empty?(content)
18
+
19
+ e = element_class.new(content: content)
20
+ result = [leading_whitespace, e, trailing_whitespace].compact
21
+ result.length == 1 ? result.first : result
22
+ end
23
+
24
+ private
25
+
26
+ def content_empty?(content)
27
+ return true if content.nil?
28
+ return content.strip.empty? if content.is_a?(String)
29
+ return content.empty? if content.is_a?(Array)
30
+
31
+ false
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -5,6 +5,8 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Pre < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, _state = {})
9
11
  id = node['id']
10
12
  lang = language(node)
@@ -12,14 +14,12 @@ module Coradoc
12
14
 
13
15
  if lang
14
16
  Coradoc::CoreModel::SourceBlock.new(
15
- element_type: 'source',
16
17
  content: content,
17
18
  id: id,
18
19
  language: lang
19
20
  )
20
21
  else
21
22
  Coradoc::CoreModel::LiteralBlock.new(
22
- element_type: 'literal',
23
23
  content: content,
24
24
  id: id
25
25
  )
@@ -52,7 +52,7 @@ module Coradoc
52
52
  end
53
53
  end
54
54
 
55
- register :pre, Pre.new
55
+ register :pre, Pre::INSTANCE
56
56
  end
57
57
  end
58
58
  end
@@ -5,19 +5,22 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Q < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, state = {})
9
11
  content = treat_children_coradoc(node, state)
10
12
  cite = node['cite']
11
13
 
12
14
  Coradoc::CoreModel::InlineElement.new(
13
15
  format_type: 'quotation',
14
- content: content,
15
- metadata: cite ? { cite: cite } : {}
16
+ nested_elements: content,
17
+ content: extract_text_from_content(content),
18
+ target: cite
16
19
  )
17
20
  end
18
21
  end
19
22
 
20
- register :q, Q.new
23
+ register :q, Q::INSTANCE
21
24
  end
22
25
  end
23
26
  end
@@ -5,6 +5,8 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Strong < Markup
8
+ INSTANCE = new
9
+
8
10
  def coradoc_format_type
9
11
  'bold'
10
12
  end
@@ -14,8 +16,8 @@ module Coradoc
14
16
  end
15
17
  end
16
18
 
17
- register :strong, Strong.new
18
- register :b, Strong.new
19
+ register :strong, Strong::INSTANCE
20
+ register :b, Strong::INSTANCE
19
21
  end
20
22
  end
21
23
  end
@@ -1,39 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'positional_formatting'
4
+
3
5
  module Coradoc
4
6
  module Input
5
7
  module Html
6
8
  module Converters
7
9
  class Sub < Base
8
- def to_coradoc(node, state = {})
9
- leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)
10
-
11
- content = treat_children_coradoc(node, state)
12
-
13
- # Check if content is empty
14
- return nil if content_empty?(content)
15
-
16
- # Create CoreModel::InlineElement with format_type "subscript"
17
- e = Coradoc::CoreModel::InlineElement.new(
18
- format_type: 'subscript',
19
- content: content
20
- )
21
- result = [leading_whitespace, e, trailing_whitespace].compact
22
- result.length == 1 ? result.first : result
23
- end
10
+ INSTANCE = new
11
+ include PositionalFormatting
24
12
 
25
13
  private
26
14
 
27
- def content_empty?(content)
28
- return true if content.nil?
29
- return content.strip.empty? if content.is_a?(String)
30
- return content.empty? if content.is_a?(Array)
31
-
32
- false
15
+ def element_class
16
+ Coradoc::CoreModel::SubscriptElement
33
17
  end
34
18
  end
35
19
 
36
- register :sub, Sub.new
20
+ register :sub, Sub::INSTANCE
37
21
  end
38
22
  end
39
23
  end
@@ -1,39 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'positional_formatting'
4
+
3
5
  module Coradoc
4
6
  module Input
5
7
  module Html
6
8
  module Converters
7
9
  class Sup < Base
8
- def to_coradoc(node, state = {})
9
- leading_whitespace, trailing_whitespace = extract_leading_trailing_whitespace(node)
10
-
11
- content = treat_children_coradoc(node, state)
12
-
13
- # Check if content is empty
14
- return nil if content_empty?(content)
15
-
16
- # Create CoreModel::InlineElement with format_type "superscript"
17
- e = Coradoc::CoreModel::InlineElement.new(
18
- format_type: 'superscript',
19
- content: content
20
- )
21
- result = [leading_whitespace, e, trailing_whitespace].compact
22
- result.length == 1 ? result.first : result
23
- end
10
+ INSTANCE = new
11
+ include PositionalFormatting
24
12
 
25
13
  private
26
14
 
27
- def content_empty?(content)
28
- return true if content.nil?
29
- return content.strip.empty? if content.is_a?(String)
30
- return content.empty? if content.is_a?(Array)
31
-
32
- false
15
+ def element_class
16
+ Coradoc::CoreModel::SuperscriptElement
33
17
  end
34
18
  end
35
19
 
36
- register :sup, Sup.new
20
+ register :sup, Sup::INSTANCE
37
21
  end
38
22
  end
39
23
  end
@@ -5,6 +5,8 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Table < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, state = {})
9
11
  id = node['id']
10
12
  title = extract_title(node)
@@ -57,7 +59,7 @@ module Coradoc
57
59
  end
58
60
  end
59
61
 
60
- register :table, Table.new
62
+ register :table, Table::INSTANCE
61
63
  end
62
64
  end
63
65
  end
@@ -5,8 +5,9 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Td < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, state = {})
9
- node['id']
10
11
  colspan = node['colspan']&.to_i
11
12
  rowspan = node['rowspan']&.to_i
12
13
  alignment = extract_alignment(node)
@@ -16,7 +17,6 @@ module Coradoc
16
17
 
17
18
  content = treat_children_coradoc(node, state)
18
19
 
19
- # Use CoreModel::TableCell
20
20
  Coradoc::CoreModel::TableCell.new(
21
21
  content: extract_text_from_content(content),
22
22
  alignment: alignment,
@@ -28,42 +28,16 @@ module Coradoc
28
28
 
29
29
  def extract_alignment(node)
30
30
  align = node['align']
31
- node['valign']
32
- # Combine horizontal and vertical alignment
33
31
  case align
34
32
  when 'left' then 'left'
35
33
  when 'center' then 'center'
36
34
  when 'right' then 'right'
37
35
  end
38
- # Return alignment string (can be extended to include vertical)
39
- end
40
-
41
- # Extract text from content array
42
- def extract_text_from_content(content)
43
- return content if content.is_a?(String)
44
- return '' if content.nil?
45
-
46
- content.map do |item|
47
- case item
48
- when String
49
- item
50
- when Coradoc::CoreModel::InlineElement
51
- item.content.to_s
52
- when Coradoc::CoreModel::Base
53
- if item.content
54
- item.content.to_s
55
- else
56
- ''
57
- end
58
- else
59
- item.to_s
60
- end
61
- end.join
62
36
  end
63
37
  end
64
38
 
65
- register :td, Td.new
66
- register :th, Td.new
39
+ register :td, Td::INSTANCE
40
+ register :th, Td::INSTANCE
67
41
  end
68
42
  end
69
43
  end
@@ -5,6 +5,8 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Text < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, state = {})
9
11
  return treat_empty(node, state) if node.text.strip.empty?
10
12
 
@@ -12,8 +14,7 @@ module Coradoc
12
14
  cleaned_content = cleanup_html_text(node.text)
13
15
 
14
16
  # Return as CoreModel::InlineElement with format_type "text"
15
- Coradoc::CoreModel::InlineElement.new(
16
- format_type: 'text',
17
+ Coradoc::CoreModel::TextElement.new(
17
18
  content: cleaned_content
18
19
  )
19
20
  end
@@ -60,7 +61,7 @@ module Coradoc
60
61
  end
61
62
  end
62
63
 
63
- register :text, Text.new
64
+ register :text, Text::INSTANCE
64
65
  end
65
66
  end
66
67
  end
@@ -5,6 +5,8 @@ module Coradoc
5
5
  module Html
6
6
  module Converters
7
7
  class Tr < Base
8
+ INSTANCE = new
9
+
8
10
  def to_coradoc(node, state = {})
9
11
  content = treat_children_coradoc(node, state)
10
12
  header = table_header_row?(node)
@@ -16,12 +18,11 @@ module Coradoc
16
18
  end
17
19
 
18
20
  def table_header_row?(node)
19
- # node.element_children.all? {|child| child.name.to_sym == :th}
20
21
  node.previous_element.nil?
21
22
  end
22
23
  end
23
24
 
24
- register :tr, Tr.new
25
+ register :tr, Tr::INSTANCE
25
26
  end
26
27
  end
27
28
  end
@@ -1,52 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'media_base'
4
+
3
5
  module Coradoc
4
6
  module Input
5
7
  module Html
6
8
  module Converters
7
- class Video < Base
8
- def to_coradoc(node, _state = {})
9
- src = node['src']
10
- id = node['id']
11
- title = extract_title(node)
12
- options(node)
9
+ class Video < MediaBase
10
+ INSTANCE = new
13
11
 
14
- # Use Block with custom attributes to store video info
15
- # CoreModel doesn't have a specific Video type, so we use Block
16
- # with element_attributes to store video-specific data
17
- Coradoc::CoreModel::Block.new(
18
- element_type: 'video',
19
- block_semantic_type: :video,
20
- content: src,
21
- title: title,
22
- id: id,
23
- width: node['width'],
24
- height: node['height'],
25
- element_attributes: {
26
- autoplay: node['autoplay'],
27
- loop: node['loop'],
28
- controls: node['controls'],
29
- poster: node['poster']
30
- }.compact
31
- )
32
- end
12
+ private
33
13
 
34
- def extract_title(node)
35
- title = node.at('./track') || node.at('.//source')
36
- return '' if title.nil?
37
-
38
- title['label'] || title['srclang'] || ''
14
+ def semantic_type
15
+ :video
39
16
  end
40
17
 
41
- def options(node)
42
- autoplay = node['autoplay']
43
- loop_attr = node['loop']
44
- controls = node['controls']
45
- [autoplay, loop_attr, controls].compact
18
+ def build_attributes(node)
19
+ base_attributes(node).merge(
20
+ poster: node['poster'],
21
+ width: node['width'],
22
+ height: node['height']
23
+ ).compact
46
24
  end
47
25
  end
48
26
 
49
- register :video, Video.new
27
+ register :video, Video::INSTANCE
50
28
  end
51
29
  end
52
30
  end