coradoc 2.0.1 → 2.0.3
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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +77 -146
- data/coradoc-adoc/lib/coradoc/asciidoc/model/base.rb +4 -3
- data/coradoc-adoc/lib/coradoc/asciidoc/model/document.rb +1 -1
- data/coradoc-adoc/lib/coradoc/asciidoc/model/include.rb +1 -1
- data/coradoc-adoc/lib/coradoc/asciidoc/model/resolver.rb +2 -2
- data/coradoc-adoc/lib/coradoc/asciidoc/model/serialization/asciidoc_transform.rb +3 -3
- data/coradoc-adoc/lib/coradoc/asciidoc/model/table_row.rb +1 -1
- data/coradoc-adoc/lib/coradoc/asciidoc/model/text_element.rb +4 -8
- data/coradoc-adoc/lib/coradoc/asciidoc/parse_error.rb +6 -6
- data/coradoc-adoc/lib/coradoc/asciidoc/serializer/adoc_serializer.rb +5 -10
- data/coradoc-adoc/lib/coradoc/asciidoc/serializer/formatter.rb +4 -3
- data/coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/base.rb +8 -20
- data/coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/block/core.rb +1 -1
- data/coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/document.rb +3 -6
- data/coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/inline/strikethrough.rb +1 -1
- data/coradoc-adoc/lib/coradoc/asciidoc/serializer/serializers/list/item.rb +5 -9
- data/coradoc-adoc/lib/coradoc/asciidoc/transform/from_core_model.rb +26 -34
- data/coradoc-adoc/lib/coradoc/asciidoc/transform/from_core_model_registrations.rb +18 -18
- data/coradoc-adoc/lib/coradoc/asciidoc/transform/to_core_model.rb +96 -123
- data/coradoc-adoc/lib/coradoc/asciidoc/transform/to_core_model_registrations.rb +10 -6
- data/coradoc-adoc/lib/coradoc/asciidoc/transformer/header_rules.rb +5 -5
- data/coradoc-adoc/lib/coradoc/asciidoc/transformer/list_rules.rb +2 -2
- data/coradoc-adoc/lib/coradoc/asciidoc/transformer/structural_rules.rb +1 -1
- data/coradoc-adoc/lib/coradoc/asciidoc/transformer.rb +5 -5
- data/coradoc-adoc/lib/coradoc/asciidoc.rb +1 -1
- data/coradoc-adoc/lib/coradoc/util/asciidoc.rb +4 -3
- data/coradoc-adoc/spec/coradoc/asciidoc/transform/from_core_model_spec.rb +4 -2
- data/coradoc-docx/lib/coradoc/docx/transform/context.rb +1 -1
- data/coradoc-docx/lib/coradoc/docx/transform/from_core_model.rb +13 -6
- data/coradoc-docx/lib/coradoc/docx/transform/numbering_resolver.rb +9 -7
- data/coradoc-docx/lib/coradoc/docx/transform/ordered_content.rb +2 -2
- data/coradoc-docx/lib/coradoc/docx/transform/rules/image_rule.rb +4 -1
- data/coradoc-docx/lib/coradoc/docx/transform/rules/math_rule.rb +2 -1
- data/coradoc-docx/lib/coradoc/docx/transform/rules/run_rule.rb +20 -30
- data/coradoc-docx/lib/coradoc/docx/transform/rules/simple_field_rule.rb +7 -5
- data/coradoc-docx/lib/coradoc/docx/transform/rules/table_rule.rb +3 -5
- data/coradoc-docx/lib/coradoc/docx/transform/style_resolver.rb +19 -24
- data/coradoc-docx/lib/coradoc/docx/transform/to_core_model.rb +18 -11
- data/coradoc-docx/lib/coradoc/docx.rb +6 -4
- data/coradoc-docx/spec/coradoc/docx/transform/from_core_model_spec.rb +5 -2
- data/coradoc-docx/spec/coradoc/docx/transform/rules/rule_unit_spec.rb +27 -7
- data/coradoc-docx/spec/coradoc/docx/transform/to_core_model_spec.rb +6 -2
- data/coradoc-html/lib/coradoc/html/base.rb +3 -7
- data/coradoc-html/lib/coradoc/html/converter_base.rb +5 -15
- data/coradoc-html/lib/coradoc/html/converters/base.rb +22 -28
- data/coradoc-html/lib/coradoc/html/converters/comment_line.rb +2 -2
- data/coradoc-html/lib/coradoc/html/converters/link.rb +1 -1
- data/coradoc-html/lib/coradoc/html/converters/list_item.rb +3 -3
- data/coradoc-html/lib/coradoc/html/converters/ordered.rb +1 -1
- data/coradoc-html/lib/coradoc/html/converters/span.rb +2 -2
- data/coradoc-html/lib/coradoc/html/converters/table.rb +3 -3
- data/coradoc-html/lib/coradoc/html/converters/table_cell.rb +14 -28
- data/coradoc-html/lib/coradoc/html/converters/table_row.rb +2 -2
- data/coradoc-html/lib/coradoc/html/converters/text_element.rb +1 -5
- data/coradoc-html/lib/coradoc/html/input/converters/a.rb +2 -2
- data/coradoc-html/lib/coradoc/html/input/converters/dl.rb +1 -1
- data/coradoc-html/lib/coradoc/html/input/converters/figure.rb +2 -2
- data/coradoc-html/lib/coradoc/html/input/converters/markup.rb +3 -3
- data/coradoc-html/lib/coradoc/html/input/converters/p.rb +1 -1
- data/coradoc-html/lib/coradoc/html/input/converters/td.rb +1 -1
- data/coradoc-html/lib/coradoc/html/input/converters.rb +1 -2
- data/coradoc-html/lib/coradoc/html/input/html_converter.rb +3 -3
- data/coradoc-html/lib/coradoc/html/input/plugin.rb +2 -2
- data/coradoc-html/lib/coradoc/html/renderer.rb +4 -6
- data/coradoc-html/lib/coradoc/html/theme/base.rb +2 -3
- data/coradoc-html/lib/coradoc/html/theme/classic_renderer.rb +9 -12
- data/coradoc-html/lib/coradoc/html/theme/modern/serializers/document_serializer.rb +3 -3
- data/coradoc-html/lib/coradoc/html.rb +1 -1
- data/coradoc-markdown/lib/coradoc/markdown/model/base.rb +6 -5
- data/coradoc-markdown/lib/coradoc/markdown/serializer.rb +2 -2
- data/coradoc-markdown/lib/coradoc/markdown/toc_generator.rb +4 -5
- data/coradoc-markdown/lib/coradoc/markdown/transform/from_core_model.rb +2 -2
- data/coradoc-markdown/lib/coradoc/markdown/transformer.rb +5 -3
- data/coradoc-markdown/lib/coradoc/markdown.rb +1 -1
- data/lib/coradoc/configurable.rb +6 -2
- data/lib/coradoc/coradoc.rb +18 -16
- data/lib/coradoc/core_model/base.rb +3 -3
- data/lib/coradoc/core_model/list_item.rb +3 -3
- data/lib/coradoc/core_model/toc_generator.rb +1 -1
- data/lib/coradoc/document_manipulator.rb +9 -13
- data/lib/coradoc/format_module.rb +16 -4
- data/lib/coradoc/input.rb +1 -1
- data/lib/coradoc/output.rb +1 -1
- data/lib/coradoc/query.rb +38 -186
- data/lib/coradoc/registry.rb +5 -7
- data/lib/coradoc/serializer/registry.rb +3 -5
- data/lib/coradoc/validation.rb +40 -21
- data/lib/coradoc/version.rb +1 -1
- metadata +1 -1
|
@@ -11,7 +11,7 @@ module Coradoc
|
|
|
11
11
|
attrs[:id] = model.id if model.id
|
|
12
12
|
|
|
13
13
|
# Get title from metadata
|
|
14
|
-
if model.
|
|
14
|
+
if model.metadata && model.metadata[:title]
|
|
15
15
|
attrs[:title] =
|
|
16
16
|
model.metadata[:title]
|
|
17
17
|
end
|
|
@@ -50,18 +50,18 @@ module Coradoc
|
|
|
50
50
|
parts = []
|
|
51
51
|
|
|
52
52
|
# Convert main content - check children first (mixed content), then content
|
|
53
|
-
content_to_render = model.
|
|
53
|
+
content_to_render = model.children&.any? ? model.children : model.content
|
|
54
54
|
parts << convert_content_to_html(content_to_render, state) if content_to_render
|
|
55
55
|
|
|
56
56
|
# Convert attached content
|
|
57
|
-
if model.
|
|
57
|
+
if model.attached && !model.attached.empty?
|
|
58
58
|
model.attached.each do |attached_item|
|
|
59
59
|
parts << convert_content_to_html(attached_item, state)
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
# Convert nested list
|
|
64
|
-
parts << convert_content_to_html(model.nested, state) if model.
|
|
64
|
+
parts << convert_content_to_html(model.nested, state) if model.nested
|
|
65
65
|
|
|
66
66
|
attrs = {}
|
|
67
67
|
attrs[:id] = model.id if model.id
|
|
@@ -42,7 +42,7 @@ module Coradoc
|
|
|
42
42
|
attrs[:id] = model.id if model.id
|
|
43
43
|
|
|
44
44
|
# Add start attribute if not starting from 1
|
|
45
|
-
attrs[:start] = model.start if model.
|
|
45
|
+
attrs[:start] = model.start if model.start && model.start != 1
|
|
46
46
|
|
|
47
47
|
build_element('ol', "\n#{items_html}\n", attrs)
|
|
48
48
|
end
|
|
@@ -39,7 +39,7 @@ module Coradoc
|
|
|
39
39
|
# @return [String] HTML string
|
|
40
40
|
def to_html(model, state = {})
|
|
41
41
|
# Prefer children for mixed content, fall back to content
|
|
42
|
-
content = if model.
|
|
42
|
+
content = if model.children&.any?
|
|
43
43
|
model.children.map { |c| convert_content_to_html(c, state) }.join
|
|
44
44
|
else
|
|
45
45
|
escape_html(model.content || '')
|
|
@@ -47,7 +47,7 @@ module Coradoc
|
|
|
47
47
|
|
|
48
48
|
# Build attributes from metadata
|
|
49
49
|
attrs = {}
|
|
50
|
-
if model.
|
|
50
|
+
if model.metadata && model.metadata[:class]
|
|
51
51
|
attrs[:class] =
|
|
52
52
|
model.metadata[:class]
|
|
53
53
|
end
|
|
@@ -48,16 +48,16 @@ module Coradoc
|
|
|
48
48
|
attrs = []
|
|
49
49
|
|
|
50
50
|
# Add ID if present
|
|
51
|
-
attrs << %( id="#{escape_attribute(table.id)}") if table.
|
|
51
|
+
attrs << %( id="#{escape_attribute(table.id)}") if table.id
|
|
52
52
|
|
|
53
53
|
# CoreModel::Table with frame attribute
|
|
54
|
-
attrs << %( class="frame-#{escape_attribute(table.frame)}") if table.
|
|
54
|
+
attrs << %( class="frame-#{escape_attribute(table.frame)}") if table.frame
|
|
55
55
|
|
|
56
56
|
attrs.join
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def self.build_caption(table)
|
|
60
|
-
return nil unless table.
|
|
60
|
+
return nil unless table.title
|
|
61
61
|
|
|
62
62
|
caption_text = table.title.to_s
|
|
63
63
|
return nil if caption_text.empty?
|
|
@@ -13,7 +13,7 @@ module Coradoc
|
|
|
13
13
|
return '' unless cell
|
|
14
14
|
|
|
15
15
|
# Check if this is a header cell
|
|
16
|
-
is_header = cell.
|
|
16
|
+
is_header = cell.header == true
|
|
17
17
|
tag = is_header ? 'th' : 'td'
|
|
18
18
|
|
|
19
19
|
# Build cell attributes
|
|
@@ -52,33 +52,19 @@ module Coradoc
|
|
|
52
52
|
def self.build_attributes(cell)
|
|
53
53
|
attrs = []
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
attrs << %( id="#{escape_attribute(cell.id)}") if cell.respond_to?(:id) && cell.id
|
|
55
|
+
attrs << %( id="#{escape_attribute(cell.id)}") if cell.id
|
|
57
56
|
|
|
58
|
-
#
|
|
59
|
-
attrs << %(
|
|
60
|
-
attrs << %( rowspan="#{cell.rowspan}") if cell.respond_to?(:rowspan) && cell.rowspan
|
|
57
|
+
attrs << %( colspan="#{cell.colspan}") if cell.colspan
|
|
58
|
+
attrs << %( rowspan="#{cell.rowspan}") if cell.rowspan
|
|
61
59
|
|
|
62
|
-
# Build style attribute for alignment, colors, etc.
|
|
63
60
|
style_parts = []
|
|
64
61
|
|
|
65
|
-
#
|
|
66
|
-
style_parts << "
|
|
67
|
-
|
|
68
|
-
#
|
|
69
|
-
style_parts << "
|
|
70
|
-
|
|
71
|
-
# Background color
|
|
72
|
-
style_parts << "background-color: #{escape_attribute(cell.bgcolor)}" if cell.respond_to?(:bgcolor) && cell.bgcolor
|
|
73
|
-
|
|
74
|
-
# Text color
|
|
75
|
-
style_parts << "color: #{escape_attribute(cell.color)}" if cell.respond_to?(:color) && cell.color
|
|
76
|
-
|
|
77
|
-
# Width
|
|
78
|
-
style_parts << "width: #{escape_attribute(cell.width)}" if cell.respond_to?(:width) && cell.width
|
|
79
|
-
|
|
80
|
-
# Height
|
|
81
|
-
style_parts << "height: #{escape_attribute(cell.height)}" if cell.respond_to?(:height) && cell.height
|
|
62
|
+
style_parts << "text-align: #{escape_attribute(cell.alignment)}" if cell.alignment
|
|
63
|
+
style_parts << "vertical-align: #{escape_attribute(cell.vertical_alignment)}" if cell.vertical_alignment
|
|
64
|
+
style_parts << "background-color: #{escape_attribute(cell.bgcolor)}" if cell.bgcolor
|
|
65
|
+
style_parts << "color: #{escape_attribute(cell.color)}" if cell.color
|
|
66
|
+
style_parts << "width: #{escape_attribute(cell.width)}" if cell.width
|
|
67
|
+
style_parts << "height: #{escape_attribute(cell.height)}" if cell.height
|
|
82
68
|
|
|
83
69
|
# Add style attribute if we have any styles
|
|
84
70
|
attrs << %( style="#{style_parts.join('; ')}") if style_parts.any?
|
|
@@ -88,7 +74,7 @@ module Coradoc
|
|
|
88
74
|
|
|
89
75
|
# Wrap content with style tags based on cell style
|
|
90
76
|
def self.wrap_with_style(content, cell)
|
|
91
|
-
return content unless cell.
|
|
77
|
+
return content unless cell.style
|
|
92
78
|
|
|
93
79
|
case cell.style.to_s.downcase
|
|
94
80
|
when 'strong', 's'
|
|
@@ -112,11 +98,11 @@ module Coradoc
|
|
|
112
98
|
return '' if cell.nil?
|
|
113
99
|
|
|
114
100
|
# Use renderable_content if available (prefers children over content)
|
|
115
|
-
content = if cell.
|
|
101
|
+
content = if cell.renderable_content
|
|
116
102
|
cell.renderable_content
|
|
117
|
-
elsif cell.
|
|
103
|
+
elsif cell.children.any?
|
|
118
104
|
cell.children
|
|
119
|
-
elsif cell.
|
|
105
|
+
elsif cell.content
|
|
120
106
|
cell.content
|
|
121
107
|
else
|
|
122
108
|
cell
|
|
@@ -9,7 +9,7 @@ module Coradoc
|
|
|
9
9
|
return '' unless row
|
|
10
10
|
|
|
11
11
|
# CoreModel::TableRow uses cells
|
|
12
|
-
cells = row.
|
|
12
|
+
cells = row.cells || []
|
|
13
13
|
columns_html = cells.map do |cell|
|
|
14
14
|
TableCell.to_html(cell)
|
|
15
15
|
end.join("\n")
|
|
@@ -35,7 +35,7 @@ module Coradoc
|
|
|
35
35
|
attrs = []
|
|
36
36
|
|
|
37
37
|
# Add ID if present
|
|
38
|
-
attrs << %( id="#{escape_attribute(row.id)}") if row.
|
|
38
|
+
attrs << %( id="#{escape_attribute(row.id)}") if row.id
|
|
39
39
|
|
|
40
40
|
attrs.join
|
|
41
41
|
end
|
|
@@ -23,11 +23,7 @@ module Coradoc
|
|
|
23
23
|
# @return [String] Plain text (escaped)
|
|
24
24
|
def to_html(model, state = {})
|
|
25
25
|
# Handle both string and model with content attribute
|
|
26
|
-
content =
|
|
27
|
-
model.content
|
|
28
|
-
else
|
|
29
|
-
model
|
|
30
|
-
end
|
|
26
|
+
content = model.content || model
|
|
31
27
|
|
|
32
28
|
return '' if content.nil?
|
|
33
29
|
|
|
@@ -33,7 +33,7 @@ module Coradoc
|
|
|
33
33
|
ref_id = href.sub(/^#/, '').gsub(/\s/, '').gsub(/__+/, '_')
|
|
34
34
|
# Convert content to string
|
|
35
35
|
content_str = if content.is_a?(Array)
|
|
36
|
-
content.map { |c| c.
|
|
36
|
+
content.map { |c| c.is_a?(Coradoc::CoreModel::Base) ? c.content : c.to_s }.join
|
|
37
37
|
else
|
|
38
38
|
content.to_s
|
|
39
39
|
end
|
|
@@ -52,7 +52,7 @@ module Coradoc
|
|
|
52
52
|
|
|
53
53
|
# Convert content to string for the link
|
|
54
54
|
content_str = if content.is_a?(Array)
|
|
55
|
-
content.map { |c| c.
|
|
55
|
+
content.map { |c| c.is_a?(Coradoc::CoreModel::Base) && c.content ? c.content : c.to_s }.join
|
|
56
56
|
else
|
|
57
57
|
content.to_s
|
|
58
58
|
end
|
|
@@ -38,9 +38,9 @@ module Coradoc
|
|
|
38
38
|
when Coradoc::CoreModel::InlineElement
|
|
39
39
|
item.content.to_s
|
|
40
40
|
when Coradoc::CoreModel::Base
|
|
41
|
-
if item.
|
|
41
|
+
if item.content
|
|
42
42
|
item.content.to_s
|
|
43
|
-
elsif item.
|
|
43
|
+
elsif item.title
|
|
44
44
|
item.title.to_s
|
|
45
45
|
else
|
|
46
46
|
''
|
|
@@ -85,11 +85,11 @@ module Coradoc
|
|
|
85
85
|
def extract_text_from_model(model)
|
|
86
86
|
return '' if model.nil?
|
|
87
87
|
|
|
88
|
-
if model.
|
|
88
|
+
if model.is_a?(Coradoc::CoreModel::Base) && model.content.is_a?(String)
|
|
89
89
|
model.content
|
|
90
|
-
elsif model.
|
|
90
|
+
elsif model.is_a?(Coradoc::CoreModel::StructuralElement) && model.children.is_a?(Array)
|
|
91
91
|
model.children.map { |c| extract_text_from_model(c) }.join
|
|
92
|
-
elsif model.
|
|
92
|
+
elsif model.is_a?(Coradoc::CoreModel::Base) && model.title.is_a?(String)
|
|
93
93
|
model.title
|
|
94
94
|
else
|
|
95
95
|
model.to_s
|
|
@@ -66,7 +66,7 @@ module Coradoc
|
|
|
66
66
|
|
|
67
67
|
# Check if InlineElement has meaningful nested content
|
|
68
68
|
def item_has_nested_content?(item)
|
|
69
|
-
return false unless item.
|
|
69
|
+
return false unless item.is_a?(Coradoc::CoreModel::InlineElement)
|
|
70
70
|
return false if item.nested_elements.nil? || item.nested_elements.empty?
|
|
71
71
|
|
|
72
72
|
true
|
|
@@ -74,8 +74,7 @@ module Coradoc
|
|
|
74
74
|
def self.lookup(tag_name)
|
|
75
75
|
ensure_converters_loaded
|
|
76
76
|
converter = @@converters[tag_name.to_sym] || default_converter(tag_name)
|
|
77
|
-
converter
|
|
78
|
-
converter
|
|
77
|
+
converter.is_a?(Class) ? converter.new : converter
|
|
79
78
|
end
|
|
80
79
|
|
|
81
80
|
# NOTE: process won't run plugin hooks
|
|
@@ -41,7 +41,7 @@ module Coradoc
|
|
|
41
41
|
|
|
42
42
|
plugin_instances.each do |plugin|
|
|
43
43
|
plugin.html_tree = root
|
|
44
|
-
if plugin.
|
|
44
|
+
if plugin.public_methods.include?(:preprocess_html_tree)
|
|
45
45
|
track_time "Preprocessing document with #{plugin.name} plugin" do
|
|
46
46
|
plugin.preprocess_html_tree
|
|
47
47
|
end
|
|
@@ -61,7 +61,7 @@ module Coradoc
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
plugin_instances.each do |plugin|
|
|
64
|
-
next unless plugin.
|
|
64
|
+
next unless plugin.public_methods.include?(:postprocess_coremodel_tree)
|
|
65
65
|
|
|
66
66
|
plugin.coremodel_tree = coremodel
|
|
67
67
|
track_time "Postprocessing CoreModel tree with #{plugin.name} plugin" do
|
|
@@ -131,7 +131,7 @@ module Coradoc
|
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
plugin_instances.each do |plugin|
|
|
134
|
-
next unless plugin.
|
|
134
|
+
next unless plugin.public_methods.include?(:postprocess_output_string)
|
|
135
135
|
|
|
136
136
|
plugin.output_string = result
|
|
137
137
|
track_time "Postprocessing output string with #{plugin.name} plugin" do
|
|
@@ -150,7 +150,7 @@ module Coradoc
|
|
|
150
150
|
# @deprecated Use postprocess_coremodel_tree instead. Will be removed in v2.0.
|
|
151
151
|
def postprocess_coradoc_tree
|
|
152
152
|
warn '[DEPRECATION] `postprocess_coradoc_tree` is deprecated. Use `postprocess_coremodel_tree` instead.'
|
|
153
|
-
postprocess_coremodel_tree if
|
|
153
|
+
postprocess_coremodel_tree if public_methods.include?(:postprocess_coremodel_tree)
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
#### Output string functionalities
|
|
@@ -161,7 +161,7 @@ module Coradoc
|
|
|
161
161
|
# @deprecated Use postprocess_output_string instead. Will be removed in v2.0.
|
|
162
162
|
def postprocess_asciidoc_string
|
|
163
163
|
warn '[DEPRECATION] `postprocess_asciidoc_string` is deprecated. Use `postprocess_output_string` instead.'
|
|
164
|
-
postprocess_output_string if
|
|
164
|
+
postprocess_output_string if public_methods.include?(:postprocess_output_string)
|
|
165
165
|
end
|
|
166
166
|
end
|
|
167
167
|
end
|
|
@@ -179,22 +179,20 @@ module Coradoc
|
|
|
179
179
|
# (lutaml-model may not create drops if Liquid was loaded after the model class)
|
|
180
180
|
def ensure_drop_class(element)
|
|
181
181
|
klass = element.class
|
|
182
|
-
if klass.
|
|
183
|
-
klass.
|
|
182
|
+
if klass.public_methods.include?(:register_class_if_liquid_defined) &&
|
|
183
|
+
klass.public_methods.include?(:base_drop_class) && !klass.base_drop_class
|
|
184
184
|
klass.register_class_if_liquid_defined
|
|
185
185
|
end
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
# Ensure all CoreModel drop classes are registered
|
|
189
|
-
# (lutaml-model only creates drops when Liquid is already loaded at class definition time)
|
|
190
188
|
def ensure_core_model_drops
|
|
191
189
|
return unless defined?(Coradoc::CoreModel)
|
|
192
190
|
|
|
193
191
|
CoreModel.constants(false).each do |const_name|
|
|
194
192
|
klass = CoreModel.const_get(const_name)
|
|
195
193
|
next unless klass.is_a?(Class)
|
|
196
|
-
next unless klass.
|
|
197
|
-
next if klass.
|
|
194
|
+
next unless klass.public_methods.include?(:register_class_if_liquid_defined)
|
|
195
|
+
next if klass.public_methods.include?(:base_drop_class) && klass.base_drop_class
|
|
198
196
|
|
|
199
197
|
klass.register_class_if_liquid_defined
|
|
200
198
|
rescue StandardError
|
|
@@ -158,11 +158,10 @@ module Coradoc
|
|
|
158
158
|
#
|
|
159
159
|
# @return [String] Document title
|
|
160
160
|
def extract_document_title
|
|
161
|
-
|
|
162
|
-
if @document.respond_to?(:title) && @document.title
|
|
161
|
+
if @document.is_a?(Coradoc::CoreModel::StructuralElement) && @document.title
|
|
163
162
|
title = @document.title
|
|
164
163
|
return title if title.is_a?(String)
|
|
165
|
-
return title.text if title.
|
|
164
|
+
return title.text if title.is_a?(Coradoc::CoreModel::Base) && title.text
|
|
166
165
|
|
|
167
166
|
return title.to_s
|
|
168
167
|
end
|
|
@@ -235,9 +235,9 @@ module Coradoc
|
|
|
235
235
|
# @return [Array] Array of section objects
|
|
236
236
|
def extract_sections(doc)
|
|
237
237
|
sections = []
|
|
238
|
-
return sections unless doc.
|
|
238
|
+
return sections unless doc.is_a?(Coradoc::CoreModel::StructuralElement)
|
|
239
239
|
|
|
240
|
-
collect_sections(doc.
|
|
240
|
+
collect_sections(doc.children, sections, 1)
|
|
241
241
|
sections
|
|
242
242
|
end
|
|
243
243
|
|
|
@@ -260,10 +260,7 @@ module Coradoc
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
# Recursively collect subsections
|
|
263
|
-
|
|
264
|
-
collect_sections(item.sections, section_data[:children],
|
|
265
|
-
level + 1)
|
|
266
|
-
end
|
|
263
|
+
collect_sections(item.children, section_data[:children], level + 1)
|
|
267
264
|
|
|
268
265
|
sections << section_data
|
|
269
266
|
end
|
|
@@ -274,14 +271,14 @@ module Coradoc
|
|
|
274
271
|
# @param section [Coradoc::CoreModel::StructuralElement] Section to extract title from
|
|
275
272
|
# @return [String] Section title
|
|
276
273
|
def extract_section_title(section)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if title.
|
|
274
|
+
title = section.title
|
|
275
|
+
if title
|
|
276
|
+
if title.is_a?(Coradoc::CoreModel::Base) && title.text
|
|
280
277
|
title.text
|
|
281
|
-
elsif title.
|
|
278
|
+
elsif title.is_a?(Coradoc::CoreModel::Base) && title.content
|
|
282
279
|
Coradoc::Html::Converters::Base.get_text_content(title)
|
|
283
280
|
elsif title.is_a?(Array)
|
|
284
|
-
title.map { |t| t.
|
|
281
|
+
title.map { |t| t.is_a?(Coradoc::CoreModel::Base) && t.text ? t.text : t.to_s }.join
|
|
285
282
|
else
|
|
286
283
|
title.to_s
|
|
287
284
|
end
|
|
@@ -295,7 +292,7 @@ module Coradoc
|
|
|
295
292
|
# @param section [Coradoc::CoreModel::StructuralElement] Section to extract ID from
|
|
296
293
|
# @return [String] Section ID
|
|
297
294
|
def extract_section_id(section)
|
|
298
|
-
if section.
|
|
295
|
+
if section.id
|
|
299
296
|
section.id
|
|
300
297
|
else
|
|
301
298
|
# Generate ID from title
|
|
@@ -235,7 +235,7 @@ module Coradoc
|
|
|
235
235
|
def serialize_table_row(row)
|
|
236
236
|
{
|
|
237
237
|
type: 'table_row',
|
|
238
|
-
header: row.
|
|
238
|
+
header: row.is_a?(Coradoc::CoreModel::TableRow) && row.header,
|
|
239
239
|
cells: (row.cells || []).map do |cell|
|
|
240
240
|
serialize_table_cell(cell)
|
|
241
241
|
end
|
|
@@ -318,10 +318,10 @@ module Coradoc
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
# Add link-specific attributes
|
|
321
|
-
result[:href] = element.target if element.inline_type == 'link' && element.
|
|
321
|
+
result[:href] = element.target if element.inline_type == 'link' && element.target
|
|
322
322
|
|
|
323
323
|
# Add cross-ref specific attributes
|
|
324
|
-
result[:target] = element.target if element.inline_type == 'xref' && element.
|
|
324
|
+
result[:target] = element.target if element.inline_type == 'xref' && element.target
|
|
325
325
|
|
|
326
326
|
result
|
|
327
327
|
end
|
|
@@ -14,7 +14,7 @@ module Coradoc
|
|
|
14
14
|
# Register with the main coradoc registry
|
|
15
15
|
Coradoc.register_format(:html, self,
|
|
16
16
|
aliases: %w[html htm],
|
|
17
|
-
extensions: %w[.html .htm])
|
|
17
|
+
extensions: %w[.html .htm])
|
|
18
18
|
|
|
19
19
|
@registered = true
|
|
20
20
|
end
|
|
@@ -26,11 +26,12 @@ module Coradoc
|
|
|
26
26
|
return element if element.nil?
|
|
27
27
|
|
|
28
28
|
element = yield element, :pre
|
|
29
|
-
element =
|
|
29
|
+
element = case element
|
|
30
|
+
when self
|
|
30
31
|
element.visit(&block)
|
|
31
|
-
|
|
32
|
+
when Array
|
|
32
33
|
element.map { |child| visit(child, &block) }.flatten.compact
|
|
33
|
-
|
|
34
|
+
when Hash
|
|
34
35
|
result = {}
|
|
35
36
|
element.each { |k, v| result[k] = visit(v, &block) }
|
|
36
37
|
result
|
|
@@ -59,12 +60,12 @@ module Coradoc
|
|
|
59
60
|
when nil
|
|
60
61
|
''
|
|
61
62
|
else
|
|
62
|
-
if content.
|
|
63
|
+
if content.is_a?(Base)
|
|
63
64
|
content.to_md
|
|
64
65
|
else
|
|
65
66
|
raise ArgumentError,
|
|
66
67
|
"Cannot serialize #{content.class.name} to Markdown. " \
|
|
67
|
-
'Expected String or
|
|
68
|
+
'Expected String or Base subclass.'
|
|
68
69
|
end
|
|
69
70
|
end
|
|
70
71
|
end
|
|
@@ -102,12 +102,12 @@ module Coradoc
|
|
|
102
102
|
when Emphasis, Strong, Code, Link, Image, FootnoteReference, Math, Extension, Strikethrough, Highlight
|
|
103
103
|
serialize(element)
|
|
104
104
|
else
|
|
105
|
-
if element.
|
|
105
|
+
if element.is_a?(Base)
|
|
106
106
|
element.to_md
|
|
107
107
|
else
|
|
108
108
|
raise ArgumentError,
|
|
109
109
|
"Cannot serialize inline content of type #{element.class}. " \
|
|
110
|
-
'Expected String, known inline model, or
|
|
110
|
+
'Expected String, known inline model, or Base subclass.'
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
end
|
|
@@ -128,13 +128,12 @@ module Coradoc
|
|
|
128
128
|
# Extract headings from document blocks
|
|
129
129
|
def extract_headings(document)
|
|
130
130
|
headings = []
|
|
131
|
-
return headings unless document.
|
|
131
|
+
return headings unless document.is_a?(Coradoc::Markdown::Document)
|
|
132
132
|
|
|
133
133
|
Array(document.blocks).each do |block|
|
|
134
134
|
if block.is_a?(Coradoc::Markdown::Heading)
|
|
135
135
|
headings << block if within_level_range?(block.level)
|
|
136
|
-
elsif block.
|
|
137
|
-
# Recursively search nested blocks
|
|
136
|
+
elsif block.is_a?(Coradoc::Markdown::Base) && block.class.attributes.key?(:blocks)
|
|
138
137
|
headings.concat(extract_headings_from_nested(block))
|
|
139
138
|
end
|
|
140
139
|
end
|
|
@@ -144,12 +143,12 @@ module Coradoc
|
|
|
144
143
|
|
|
145
144
|
def extract_headings_from_nested(block)
|
|
146
145
|
headings = []
|
|
147
|
-
return headings unless block.
|
|
146
|
+
return headings unless block.is_a?(Coradoc::Markdown::Base) && block.class.attributes.key?(:blocks)
|
|
148
147
|
|
|
149
148
|
Array(block.blocks).each do |nested|
|
|
150
149
|
if nested.is_a?(Coradoc::Markdown::Heading)
|
|
151
150
|
headings << nested if within_level_range?(nested.level)
|
|
152
|
-
elsif nested.
|
|
151
|
+
elsif nested.is_a?(Coradoc::Markdown::Base) && nested.class.attributes.key?(:blocks)
|
|
153
152
|
headings.concat(extract_headings_from_nested(nested))
|
|
154
153
|
end
|
|
155
154
|
end
|
|
@@ -189,13 +189,13 @@ module Coradoc
|
|
|
189
189
|
|
|
190
190
|
# Check if first row has header cells
|
|
191
191
|
if first_row_cells.any?(&:header)
|
|
192
|
-
headers = first_row_cells.map
|
|
192
|
+
headers = first_row_cells.map(&:flat_text)
|
|
193
193
|
table_rows = table_rows[1..] || []
|
|
194
194
|
end
|
|
195
195
|
|
|
196
196
|
# Convert remaining rows to pipe-separated strings
|
|
197
197
|
rows = table_rows.map do |row|
|
|
198
|
-
Array(row.cells).map
|
|
198
|
+
Array(row.cells).map(&:flat_text).join(' | ')
|
|
199
199
|
end
|
|
200
200
|
end
|
|
201
201
|
|
|
@@ -41,7 +41,7 @@ module Coradoc
|
|
|
41
41
|
rule(block_quote: subtree(:content)) do
|
|
42
42
|
# Recursively transform block quote content
|
|
43
43
|
transformed = content.is_a?(Array) ? content.map { |c| transform_element(c) } : [transform_element(content)]
|
|
44
|
-
text = transformed.map { |c| c.
|
|
44
|
+
text = transformed.map { |c| c.is_a?(Base) && c.class.attributes.key?(:text) ? c.text : c.to_s }.join("\n")
|
|
45
45
|
Blockquote.new(content: text)
|
|
46
46
|
end
|
|
47
47
|
|
|
@@ -134,7 +134,7 @@ module Coradoc
|
|
|
134
134
|
|
|
135
135
|
# Fallback for unmatched elements
|
|
136
136
|
rule(simple(:value)) do
|
|
137
|
-
Text.new(content: value.to_s)
|
|
137
|
+
Text.new(content: value.to_s)
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
class << self
|
|
@@ -268,7 +268,9 @@ module Coradoc
|
|
|
268
268
|
if element.key?(:block_quote)
|
|
269
269
|
content = element[:block_quote]
|
|
270
270
|
transformed = content.is_a?(Array) ? content.map { |c| transform_element(c) } : [transform_element(content)]
|
|
271
|
-
text = transformed.compact.map
|
|
271
|
+
text = transformed.compact.map do |c|
|
|
272
|
+
c.is_a?(Base) && c.class.attributes.key?(:text) ? c.text : c.to_s
|
|
273
|
+
end.join("\n")
|
|
272
274
|
blockquote = Blockquote.new(content: text)
|
|
273
275
|
apply_ial_to_element(blockquote, element[:ial]) if element.key?(:ial)
|
|
274
276
|
return blockquote
|
|
@@ -186,5 +186,5 @@ module Coradoc
|
|
|
186
186
|
# Register the Markdown format with Coradoc
|
|
187
187
|
register_format(:markdown, Markdown,
|
|
188
188
|
aliases: %w[md markdown mdown mkd],
|
|
189
|
-
extensions: %w[.md .markdown .mdown .mkd])
|
|
189
|
+
extensions: %w[.md .markdown .mdown .mkd])
|
|
190
190
|
end
|
data/lib/coradoc/configurable.rb
CHANGED
|
@@ -45,9 +45,12 @@ module Coradoc
|
|
|
45
45
|
# @param options [Hash] Configuration options
|
|
46
46
|
def initialize(options = {})
|
|
47
47
|
@options = symbolize_keys(options)
|
|
48
|
-
after_initialize
|
|
48
|
+
after_initialize
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
# Hook for subclass initialization
|
|
52
|
+
def after_initialize; end
|
|
53
|
+
|
|
51
54
|
# Get a configuration value
|
|
52
55
|
#
|
|
53
56
|
# @param key [Symbol] Configuration key
|
|
@@ -95,7 +98,8 @@ module Coradoc
|
|
|
95
98
|
# Override in subclasses for custom handling
|
|
96
99
|
def apply_options(options)
|
|
97
100
|
options.each do |key, value|
|
|
98
|
-
|
|
101
|
+
setter = "#{key}="
|
|
102
|
+
instance_variable_set("@#{key}", value) if public_methods.include?(setter.to_sym)
|
|
99
103
|
end
|
|
100
104
|
end
|
|
101
105
|
end
|