ceradoc 3.0.1

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 +7 -0
  2. data/.rspec +3 -0
  3. data/Rakefile +8 -0
  4. data/exe/ceradoc +24 -0
  5. data/lib/ceradoc/binding_inflater.rb +118 -0
  6. data/lib/ceradoc/ceradoc.rb +164 -0
  7. data/lib/ceradoc/cli.rb +311 -0
  8. data/lib/ceradoc/configurable.rb +530 -0
  9. data/lib/ceradoc/core_model/abstract_block.rb +11 -0
  10. data/lib/ceradoc/core_model/annotation_block.rb +57 -0
  11. data/lib/ceradoc/core_model/attribute_reference_resolver.rb +155 -0
  12. data/lib/ceradoc/core_model/base.rb +281 -0
  13. data/lib/ceradoc/core_model/bibliography.rb +41 -0
  14. data/lib/ceradoc/core_model/bibliography_entry.rb +48 -0
  15. data/lib/ceradoc/core_model/block.rb +69 -0
  16. data/lib/ceradoc/core_model/callout.rb +32 -0
  17. data/lib/ceradoc/core_model/callout_text.rb +35 -0
  18. data/lib/ceradoc/core_model/children_content.rb +72 -0
  19. data/lib/ceradoc/core_model/comment_block.rb +16 -0
  20. data/lib/ceradoc/core_model/comment_line.rb +23 -0
  21. data/lib/ceradoc/core_model/definition_item.rb +68 -0
  22. data/lib/ceradoc/core_model/definition_list.rb +28 -0
  23. data/lib/ceradoc/core_model/element_attribute.rb +14 -0
  24. data/lib/ceradoc/core_model/example_block.rb +12 -0
  25. data/lib/ceradoc/core_model/footnote.rb +92 -0
  26. data/lib/ceradoc/core_model/frontmatter/codec.rb +151 -0
  27. data/lib/ceradoc/core_model/frontmatter/field_transform.rb +75 -0
  28. data/lib/ceradoc/core_model/frontmatter/frontmatter_entry.rb +22 -0
  29. data/lib/ceradoc/core_model/frontmatter/frontmatter_value.rb +78 -0
  30. data/lib/ceradoc/core_model/frontmatter/schema_resolver.rb +57 -0
  31. data/lib/ceradoc/core_model/frontmatter/text_splitter.rb +75 -0
  32. data/lib/ceradoc/core_model/frontmatter.rb +72 -0
  33. data/lib/ceradoc/core_model/has_children.rb +23 -0
  34. data/lib/ceradoc/core_model/horizontal_rule_block.rb +16 -0
  35. data/lib/ceradoc/core_model/id_generator.rb +23 -0
  36. data/lib/ceradoc/core_model/image.rb +76 -0
  37. data/lib/ceradoc/core_model/include.rb +43 -0
  38. data/lib/ceradoc/core_model/include_level_offset.rb +71 -0
  39. data/lib/ceradoc/core_model/include_options.rb +101 -0
  40. data/lib/ceradoc/core_model/inline_content.rb +78 -0
  41. data/lib/ceradoc/core_model/inline_element.rb +209 -0
  42. data/lib/ceradoc/core_model/list_block.rb +137 -0
  43. data/lib/ceradoc/core_model/list_item.rb +129 -0
  44. data/lib/ceradoc/core_model/listing_block.rb +19 -0
  45. data/lib/ceradoc/core_model/literal_block.rb +16 -0
  46. data/lib/ceradoc/core_model/metadata.rb +71 -0
  47. data/lib/ceradoc/core_model/open_block.rb +12 -0
  48. data/lib/ceradoc/core_model/output_artifact.rb +48 -0
  49. data/lib/ceradoc/core_model/paragraph_block.rb +16 -0
  50. data/lib/ceradoc/core_model/partintro_block.rb +11 -0
  51. data/lib/ceradoc/core_model/pass_block.rb +16 -0
  52. data/lib/ceradoc/core_model/quote_block.rb +14 -0
  53. data/lib/ceradoc/core_model/raw_inline_element.rb +16 -0
  54. data/lib/ceradoc/core_model/reviewer_block.rb +12 -0
  55. data/lib/ceradoc/core_model/sidebar_block.rb +12 -0
  56. data/lib/ceradoc/core_model/source_block.rb +16 -0
  57. data/lib/ceradoc/core_model/stem_block.rb +25 -0
  58. data/lib/ceradoc/core_model/structural_element.rb +157 -0
  59. data/lib/ceradoc/core_model/table.rb +148 -0
  60. data/lib/ceradoc/core_model/term.rb +53 -0
  61. data/lib/ceradoc/core_model/text_content.rb +26 -0
  62. data/lib/ceradoc/core_model/toc.rb +99 -0
  63. data/lib/ceradoc/core_model/toc_generator.rb +151 -0
  64. data/lib/ceradoc/core_model/verse_block.rb +14 -0
  65. data/lib/ceradoc/core_model.rb +92 -0
  66. data/lib/ceradoc/dispatch.rb +96 -0
  67. data/lib/ceradoc/errors.rb +387 -0
  68. data/lib/ceradoc/format_catalog.rb +102 -0
  69. data/lib/ceradoc/format_module.rb +78 -0
  70. data/lib/ceradoc/hooks.rb +176 -0
  71. data/lib/ceradoc/include_resolver/filesystem.rb +84 -0
  72. data/lib/ceradoc/include_resolver.rb +67 -0
  73. data/lib/ceradoc/include_selectors/indent.rb +54 -0
  74. data/lib/ceradoc/include_selectors/level_offset.rb +84 -0
  75. data/lib/ceradoc/include_selectors/lines.rb +60 -0
  76. data/lib/ceradoc/include_selectors/tags.rb +136 -0
  77. data/lib/ceradoc/include_selectors.rb +26 -0
  78. data/lib/ceradoc/introspection/element_counter.rb +48 -0
  79. data/lib/ceradoc/introspection.rb +72 -0
  80. data/lib/ceradoc/link_rewriter/identity.rb +13 -0
  81. data/lib/ceradoc/link_rewriter/visitor.rb +148 -0
  82. data/lib/ceradoc/link_rewriter.rb +37 -0
  83. data/lib/ceradoc/lint/registry.rb +33 -0
  84. data/lib/ceradoc/lint/rule.rb +41 -0
  85. data/lib/ceradoc/lint/runner.rb +67 -0
  86. data/lib/ceradoc/lint/template.rb +190 -0
  87. data/lib/ceradoc/lint/violation.rb +16 -0
  88. data/lib/ceradoc/lint.rb +44 -0
  89. data/lib/ceradoc/logger.rb +54 -0
  90. data/lib/ceradoc/metanorma/block_builder.rb +130 -0
  91. data/lib/ceradoc/metanorma/builder.rb +397 -0
  92. data/lib/ceradoc/metanorma/iso_builder.rb +67 -0
  93. data/lib/ceradoc/metanorma.rb +7 -0
  94. data/lib/ceradoc/performance_regression.rb +121 -0
  95. data/lib/ceradoc/pipeline.rb +169 -0
  96. data/lib/ceradoc/query.rb +486 -0
  97. data/lib/ceradoc/reference/address/anchor.rb +48 -0
  98. data/lib/ceradoc/reference/address/doi.rb +40 -0
  99. data/lib/ceradoc/reference/address/isbn.rb +39 -0
  100. data/lib/ceradoc/reference/address/path.rb +66 -0
  101. data/lib/ceradoc/reference/address/scoped_path.rb +47 -0
  102. data/lib/ceradoc/reference/address/url.rb +41 -0
  103. data/lib/ceradoc/reference/address.rb +153 -0
  104. data/lib/ceradoc/reference/catalog/composite.rb +59 -0
  105. data/lib/ceradoc/reference/catalog/local.rb +97 -0
  106. data/lib/ceradoc/reference/catalog/memory_index.rb +59 -0
  107. data/lib/ceradoc/reference/catalog.rb +33 -0
  108. data/lib/ceradoc/reference/edge/citation_options.rb +16 -0
  109. data/lib/ceradoc/reference/edge/footnote_ref_options.rb +13 -0
  110. data/lib/ceradoc/reference/edge/image_ref_options.rb +15 -0
  111. data/lib/ceradoc/reference/edge/include_options.rb +15 -0
  112. data/lib/ceradoc/reference/edge/kind.rb +72 -0
  113. data/lib/ceradoc/reference/edge/link_options.rb +12 -0
  114. data/lib/ceradoc/reference/edge/navigation_options.rb +12 -0
  115. data/lib/ceradoc/reference/edge/options.rb +13 -0
  116. data/lib/ceradoc/reference/edge.rb +80 -0
  117. data/lib/ceradoc/reference/edge_search.rb +128 -0
  118. data/lib/ceradoc/reference/materializer/base.rb +44 -0
  119. data/lib/ceradoc/reference/materializer/passthrough.rb +31 -0
  120. data/lib/ceradoc/reference/materializer/registry.rb +116 -0
  121. data/lib/ceradoc/reference/materializer.rb +14 -0
  122. data/lib/ceradoc/reference/presentation/base.rb +47 -0
  123. data/lib/ceradoc/reference/presentation/custom_hierarchy.rb +104 -0
  124. data/lib/ceradoc/reference/presentation/page.rb +20 -0
  125. data/lib/ceradoc/reference/presentation/single_document.rb +35 -0
  126. data/lib/ceradoc/reference/presentation/split_pages.rb +118 -0
  127. data/lib/ceradoc/reference/presentation.rb +16 -0
  128. data/lib/ceradoc/reference/resolution.rb +184 -0
  129. data/lib/ceradoc/reference/resolver/base.rb +15 -0
  130. data/lib/ceradoc/reference/resolver/caching.rb +37 -0
  131. data/lib/ceradoc/reference/resolver/catalog.rb +69 -0
  132. data/lib/ceradoc/reference/resolver/chain.rb +33 -0
  133. data/lib/ceradoc/reference/resolver.rb +20 -0
  134. data/lib/ceradoc/reference/result/ambiguous.rb +23 -0
  135. data/lib/ceradoc/reference/result/base.rb +46 -0
  136. data/lib/ceradoc/reference/result/missing.rb +14 -0
  137. data/lib/ceradoc/reference/result/resolved.rb +22 -0
  138. data/lib/ceradoc/reference/result.rb +20 -0
  139. data/lib/ceradoc/reference.rb +65 -0
  140. data/lib/ceradoc/registry.rb +156 -0
  141. data/lib/ceradoc/relative_path.rb +32 -0
  142. data/lib/ceradoc/resolve_includes.rb +202 -0
  143. data/lib/ceradoc/source_graph/file_node.rb +147 -0
  144. data/lib/ceradoc/source_graph/graph.rb +165 -0
  145. data/lib/ceradoc/source_graph/include_edges.rb +33 -0
  146. data/lib/ceradoc/source_graph/sidecar.rb +97 -0
  147. data/lib/ceradoc/source_graph.rb +36 -0
  148. data/lib/ceradoc/validation.rb +686 -0
  149. data/lib/ceradoc/version.rb +5 -0
  150. data/lib/ceradoc/visitor.rb +283 -0
  151. data/lib/ceradoc.rb +41 -0
  152. metadata +225 -0
@@ -0,0 +1,209 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Generic inline formatting element
6
+ #
7
+ # Typed subclasses (BoldElement, ItalicElement, etc.) express their
8
+ # format identity via the class hierarchy — the class IS the format type.
9
+ # Generic InlineElement instances use the format_type attribute for typing.
10
+ class InlineElement < Base
11
+ attribute :children, Base, collection: true
12
+
13
+ include ChildrenContent
14
+
15
+ def self.format_type
16
+ nil
17
+ end
18
+
19
+ def self.format_type_class(type)
20
+ FORMAT_TYPE_CLASS_MAP[type] || InlineElement
21
+ end
22
+
23
+ def resolve_format_type
24
+ self.class.format_type || format_type
25
+ end
26
+
27
+ # Return a duplicate of this element with its content replaced.
28
+ # Used by InlineContent.strip_edges (and other edge-cleanup
29
+ # callers) so that mutations never leak through the public API.
30
+ def with_content(new_content)
31
+ dup.tap { |copy| copy.content = new_content }
32
+ end
33
+
34
+ # Polymorphic classification used by LinkRewriter::Visitor. Returns
35
+ # :link / :xref when this node carries a rewrite-able target, nil
36
+ # otherwise. Generic InlineElement instances defer to their
37
+ # resolved format_type; typed subclasses override with a literal.
38
+ # Keeps the visitor free of class-keyed case/when (OCP).
39
+ def link_kind
40
+ case resolve_format_type
41
+ when 'link' then :link
42
+ when 'xref' then :xref
43
+ end
44
+ end
45
+
46
+ attribute :format_type, :string
47
+ attribute :content, :string
48
+ attribute :nested_elements, InlineElement, collection: true
49
+ attribute :target, :string
50
+ attribute :stem_type, :string
51
+ # Emphasis marker spelling recorded by formats that know it
52
+ # (AsciiDoc constrained `*x*` vs unconstrained `**x**`). nil =
53
+ # unknown — serializers fall back to flank inference.
54
+ attribute :constraint, :string
55
+
56
+ private
57
+
58
+ def comparable_attributes
59
+ %i[format_type content nested_elements stem_type constraint]
60
+ end
61
+ end
62
+
63
+ # Typed InlineElement subclasses
64
+
65
+ class BoldElement < InlineElement
66
+ def self.format_type
67
+ 'bold'
68
+ end
69
+ end
70
+
71
+ class ItalicElement < InlineElement
72
+ def self.format_type
73
+ 'italic'
74
+ end
75
+ end
76
+
77
+ class MonospaceElement < InlineElement
78
+ def self.format_type
79
+ 'monospace'
80
+ end
81
+ end
82
+
83
+ class UnderlineElement < InlineElement
84
+ def self.format_type
85
+ 'underline'
86
+ end
87
+ end
88
+
89
+ class StrikethroughElement < InlineElement
90
+ def self.format_type
91
+ 'strikethrough'
92
+ end
93
+ end
94
+
95
+ class SubscriptElement < InlineElement
96
+ def self.format_type
97
+ 'subscript'
98
+ end
99
+ end
100
+
101
+ class SuperscriptElement < InlineElement
102
+ def self.format_type
103
+ 'superscript'
104
+ end
105
+ end
106
+
107
+ class HighlightElement < InlineElement
108
+ def self.format_type
109
+ 'highlight'
110
+ end
111
+ end
112
+
113
+ class LinkElement < InlineElement
114
+ def self.format_type
115
+ 'link'
116
+ end
117
+
118
+ def link_kind
119
+ :link
120
+ end
121
+
122
+ # Flat text carries both the visible label and the target so
123
+ # text-extraction contexts (conformance flatten, docx runs) keep
124
+ # the destination that raw-string paragraphs used to include.
125
+ def flat_text
126
+ "#{content}#{target}"
127
+ end
128
+ end
129
+
130
+ class CrossReferenceElement < InlineElement
131
+ def self.format_type
132
+ 'xref'
133
+ end
134
+
135
+ def link_kind
136
+ :xref
137
+ end
138
+ end
139
+
140
+ class StemElement < InlineElement
141
+ def self.format_type
142
+ 'stem'
143
+ end
144
+ end
145
+
146
+ class FootnoteElement < InlineElement
147
+ def self.format_type
148
+ 'footnote'
149
+ end
150
+ end
151
+
152
+ class HardLineBreakElement < InlineElement
153
+ def self.format_type
154
+ 'hard_line_break'
155
+ end
156
+ end
157
+
158
+ class TextElement < InlineElement
159
+ def self.format_type
160
+ 'text'
161
+ end
162
+ end
163
+
164
+ class SpanElement < InlineElement
165
+ def self.format_type
166
+ 'span'
167
+ end
168
+ end
169
+
170
+ class TermElement < InlineElement
171
+ def self.format_type
172
+ 'term'
173
+ end
174
+ end
175
+
176
+ class LineBreakElement < InlineElement
177
+ def self.format_type
178
+ 'line_break'
179
+ end
180
+ end
181
+
182
+ # Wire-name table: bidirectional string ↔ class index. Single source
183
+ # of truth for serialization names and runtime dispatch. Reopened
184
+ # onto InlineElement so the subclasses above are defined first.
185
+ class InlineElement
186
+ FORMAT_TYPE_CLASS_MAP = {
187
+ 'bold' => BoldElement,
188
+ 'italic' => ItalicElement,
189
+ 'monospace' => MonospaceElement,
190
+ 'underline' => UnderlineElement,
191
+ 'strikethrough' => StrikethroughElement,
192
+ 'subscript' => SubscriptElement,
193
+ 'superscript' => SuperscriptElement,
194
+ 'highlight' => HighlightElement,
195
+ 'link' => LinkElement,
196
+ 'xref' => CrossReferenceElement,
197
+ 'stem' => StemElement,
198
+ 'footnote' => FootnoteElement,
199
+ 'hard_line_break' => HardLineBreakElement,
200
+ 'text' => TextElement,
201
+ 'span' => SpanElement,
202
+ 'term' => TermElement,
203
+ 'line_break' => LineBreakElement
204
+ }.freeze
205
+
206
+ FORMAT_TYPES = FORMAT_TYPE_CLASS_MAP.keys.freeze
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Represents a list block with proper nesting support
6
+ #
7
+ # Handles all list types:
8
+ # - Unordered lists
9
+ # - Ordered lists
10
+ # - Description lists
11
+ #
12
+ # Lists can contain nested lists at multiple levels, with each level
13
+ # tracked through marker_level.
14
+ #
15
+ # @example Creating an unordered list
16
+ # list = CoreModel::ListBlock.new(
17
+ # marker_type: "unordered",
18
+ # marker_level: 1,
19
+ # items: [
20
+ # ListItem.new(marker: "*", content: "First item"),
21
+ # ListItem.new(marker: "*", content: "Second item")
22
+ # ]
23
+ # )
24
+ #
25
+ # @example Creating a nested list
26
+ # nested = CoreModel::ListBlock.new(
27
+ # marker_type: "unordered",
28
+ # marker_level: 2,
29
+ # items: [ListItem.new(marker: "**", content: "Nested item")]
30
+ # )
31
+ # list = CoreModel::ListBlock.new(
32
+ # marker_type: "unordered",
33
+ # marker_level: 1,
34
+ # items: [
35
+ # ListItem.new(
36
+ # marker: "*",
37
+ # content: "Parent item",
38
+ # nested_list: nested
39
+ # )
40
+ # ]
41
+ # )
42
+ class ListBlock < Base
43
+ # @!attribute marker_type
44
+ # @return [String, nil] type of list marker
45
+ # (e.g., 'unordered', 'ordered', 'definition')
46
+ attribute :marker_type, :string
47
+
48
+ # @!attribute marker_level
49
+ # @return [Integer] nesting level of the list (default: 1)
50
+ attribute :marker_level, :integer, default: -> { 1 }
51
+
52
+ # @!attribute start
53
+ # @return [Integer, nil] starting number for ordered lists
54
+ attribute :start, :integer
55
+
56
+ # @!attribute items
57
+ # @return [Array<ListItem>] collection of list items
58
+ attribute :items, 'Ceradoc::CoreModel::ListItem', collection: true
59
+
60
+ # -- Fluent construction helpers (paired with Base.build) --
61
+
62
+ # Append a new ListItem, built via ListItem.build. The block
63
+ # (if given) is yielded the new item so callers can chain
64
+ # +add_text+ / +add_link+ on it inline:
65
+ #
66
+ # ListBlock.build do |ul|
67
+ # children.each { |c| ul.add_item { |li| li.add_link(c[:slug], text: c[:title]) } }
68
+ # end
69
+ #
70
+ # Returns self for chaining at the list level.
71
+ def add_item(marker: marker_type == 'ordered' ? '.' : '*')
72
+ item = ListItem.build(marker: marker) { |li| yield li if block_given? }
73
+ self.items = Array(items) + [item]
74
+ self
75
+ end
76
+
77
+ private
78
+
79
+ # Attributes to compare for semantic equivalence
80
+ #
81
+ # Lists are semantically equivalent if they have the same marker
82
+ # type and items, regardless of marker level (which is structural).
83
+ #
84
+ # @return [Array<Symbol>] list of comparable attributes
85
+ def comparable_attributes
86
+ super + %i[marker_type items]
87
+ end
88
+ end
89
+
90
+ # Represents a single item within a list
91
+ #
92
+ # A list item can contain:
93
+ # - Simple text content
94
+ # - A nested list
95
+ # - Child elements (paragraphs, blocks, etc.)
96
+ #
97
+ # @example Simple list item
98
+ # item = ListItem.new(
99
+ # marker: "*",
100
+ # content: "Item text"
101
+ # )
102
+ #
103
+ # @example List item with nested list
104
+ # item = ListItem.new(
105
+ # marker: "*",
106
+ # content: "Parent item",
107
+ # nested_list: nested_list_block
108
+ # )
109
+ class ListItem < Base
110
+ # @!attribute marker
111
+ # @return [String, nil] the marker character(s) for this item
112
+ # (e.g., '*', '**', '.', '..', '-')
113
+ attribute :marker, :string
114
+
115
+ # @!attribute content
116
+ # @return [String, nil] text content of the list item
117
+ attribute :content, :string
118
+
119
+ # @!attribute nested_list
120
+ # @return [ListBlock, nil] nested list within this item
121
+ attribute :nested_list, Ceradoc::CoreModel::ListBlock
122
+
123
+ private
124
+
125
+ # Attributes to compare for semantic equivalence
126
+ #
127
+ # List items are semantically equivalent if they have the same
128
+ # content, nested list, and children, regardless of the specific
129
+ # marker used.
130
+ #
131
+ # @return [Array<Symbol>] list of comparable attributes
132
+ def comparable_attributes
133
+ %i[content nested_list children]
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Represents a list item
6
+ #
7
+ # List items can contain text content, nested lists, and attached blocks.
8
+ # They support various marker types and can have different nesting levels.
9
+ #
10
+ # @example Creating a simple list item
11
+ # item = ListItem.new(
12
+ # marker: "*",
13
+ # content: "First item"
14
+ # )
15
+ #
16
+ # @example Creating a list item with nested content
17
+ # item = ListItem.new(
18
+ # marker: "*",
19
+ # content: "Item with nested list",
20
+ # nested_list: nested_list_block,
21
+ # children: [attached_block]
22
+ # )
23
+ class ListItem < Base
24
+ attribute :children, Base, collection: true
25
+
26
+ include ChildrenContent
27
+
28
+ # @!attribute marker
29
+ # @return [String] the list marker (*, -, 1., etc.)
30
+ attribute :marker, :string
31
+
32
+ # @!attribute content
33
+ # @return [String] the text content of the list item
34
+ attribute :content, :string
35
+
36
+ # @!attribute children
37
+ # @return [Array] array of attached blocks/elements (mixed content, via ChildrenContent)
38
+
39
+ # Initialize with optional nested structure support
40
+ # @param args [Hash] initialization arguments
41
+ def initialize(args = {})
42
+ # Support :nested as alias for :nested_list
43
+ args[:nested_list] = args.delete(:nested) if args.key?(:nested)
44
+ super
45
+ end
46
+
47
+ # Delegate nested to nested_list (lutaml attribute added by list_block.rb)
48
+ def nested
49
+ nested_list
50
+ end
51
+
52
+ # Set nested list
53
+ # @param value [ListBlock, nil] nested list block
54
+ def nested=(value)
55
+ self.nested_list = value
56
+ end
57
+
58
+ # Override semantic equivalence to handle nested structures properly
59
+ def semantically_equivalent?(other)
60
+ return false unless other.is_a?(self.class)
61
+ return false unless content == other.content
62
+
63
+ # Compare nested lists if present
64
+ if nested || other.nested
65
+ return false if nested.nil? != other.nested.nil?
66
+ return false if nested && !lists_equivalent?(nested, other.nested)
67
+ end
68
+
69
+ # Compare children if present
70
+ if children || other.children
71
+ return false if children.nil? != other.children.nil?
72
+ return false if children && !arrays_equivalent?(children, other.children)
73
+ end
74
+
75
+ true
76
+ end
77
+
78
+ # -- Fluent construction helpers (paired with Base.build) --
79
+
80
+ # Append a plain-text inline to this item's children. Returns
81
+ # self for chaining. Pairs naturally with ListItem.build:
82
+ #
83
+ # ListItem.build do |li|
84
+ # li.add_text("See ")
85
+ # li.add_link("foo.adoc", text: "Foo")
86
+ # end
87
+ def add_text(text)
88
+ self.children = Array(children) + [TextContent.new(text: text)]
89
+ self
90
+ end
91
+
92
+ # Append a +link:+ inline to this item's children. +text+ becomes
93
+ # the link's visible label; +target+ is the URL/anchor.
94
+ def add_link(target, text: nil)
95
+ self.children = Array(children) + [LinkElement.new(target: target, content: text)]
96
+ self
97
+ end
98
+
99
+ private
100
+
101
+ # Compare two list blocks for equivalence
102
+ def lists_equivalent?(list1, list2)
103
+ # Both should be ListBlock objects or compatible
104
+ return true if list1 == list2
105
+ return false if list1.nil? || list2.nil?
106
+
107
+ # Check if both are ListBlock instances
108
+ if list1.is_a?(Ceradoc::CoreModel::ListBlock) &&
109
+ list2.is_a?(Ceradoc::CoreModel::ListBlock)
110
+ list1.semantically_equivalent?(list2)
111
+ elsif list1.instance_of?(::Ceradoc::CoreModel::ListBlock) &&
112
+ list2.instance_of?(::Ceradoc::CoreModel::ListBlock)
113
+ # Serialized by Lutaml - compare as objects
114
+ list1.marker_type == list2.marker_type &&
115
+ list1.items.to_a == list2.items.to_a
116
+ else
117
+ list1 == list2
118
+ end
119
+ end
120
+
121
+ # Compare two arrays for equivalence
122
+ def arrays_equivalent?(arr1, arr2)
123
+ return false unless arr1.size == arr2.size
124
+
125
+ arr1.zip(arr2).all? { |a, b| a == b }
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Listing block -- a delimited block for listing/content without source language
6
+ #
7
+ # Distinct from SourceBlock: a listing has no language annotation.
8
+ # When a language is present, SourceBlock should be used instead.
9
+ class ListingBlock < Block
10
+ def self.semantic_type
11
+ :listing
12
+ end
13
+
14
+ def prose?
15
+ false
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Literal block — a delimited block for preformatted literal text
6
+ class LiteralBlock < Block
7
+ def self.semantic_type
8
+ :literal
9
+ end
10
+
11
+ def prose?
12
+ false
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # A single metadata entry (key-value pair)
6
+ class MetadataEntry < Base
7
+ attribute :key, :string
8
+ attribute :value, :string
9
+ end
10
+
11
+ # Represents metadata associated with a document element
12
+ #
13
+ # Stores arbitrary key-value pairs for tracking source location,
14
+ # processing information, and other contextual data.
15
+ #
16
+ # @example
17
+ # meta = Metadata.new
18
+ # meta["source_line"] = 42
19
+ # meta["parser_version"] = "1.0.0"
20
+ class Metadata < Base
21
+ attribute :entries, MetadataEntry, collection: true
22
+
23
+ # Get a metadata value by key
24
+ # @param key [String] The metadata key
25
+ # @return [String, nil] The value or nil if not found
26
+ def [](key)
27
+ return nil if entries.nil?
28
+
29
+ find_entry(key)&.value
30
+ end
31
+
32
+ # Set a metadata value
33
+ # @param key [String] The metadata key
34
+ # @param value [String] The value to set
35
+ def []=(key, value)
36
+ self.entries ||= []
37
+ existing = find_entry(key)
38
+ if existing
39
+ existing.value = value
40
+ else
41
+ entries << MetadataEntry.new(key: key, value: value)
42
+ end
43
+ end
44
+
45
+ # Check if a key exists
46
+ # @param key [String] The key to check
47
+ # @return [Boolean] True if key exists
48
+ def key?(key)
49
+ return false if entries.nil?
50
+
51
+ !find_entry(key).nil?
52
+ end
53
+
54
+ # Get all keys
55
+ # @return [Array<String>] List of keys
56
+ def keys
57
+ return [] if entries.nil?
58
+
59
+ entries.map(&:key)
60
+ end
61
+
62
+ private
63
+
64
+ def find_entry(key)
65
+ return nil if entries.nil?
66
+
67
+ entries.find { |e| e.key == key }
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Open block — a generic container block with no special rendering
6
+ class OpenBlock < Block
7
+ def self.semantic_type
8
+ :open
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Output-side state object for host-system emitters (VitePress, Hugo,
6
+ # Astro, plain ERB, etc.).
7
+ #
8
+ # ceradoc's source side has +IncludeResolver::Filesystem+ to resolve
9
+ # include targets without coupling to a storage layer. The output side
10
+ # has no analogous state object — until now. +OutputArtifact+ captures
11
+ # the three pieces of state ceradoc genuinely needs to hand to a
12
+ # downstream emitter:
13
+ #
14
+ # - +output_key+ — site-relative key (e.g. "author/iso/ref/foo")
15
+ # - +frontmatter_block+ — parsed YAML frontmatter (may be empty)
16
+ # - +core_document+ — the canonical CoreModel document
17
+ #
18
+ # The consumer takes these and renders whatever wrapper it needs in
19
+ # its host system's native template language. ceradoc does not know
20
+ # about VitePress, ERB, or Liquid. Symmetric with the source side:
21
+ # minimal protocol object, not an engine.
22
+ #
23
+ # A mirror-tree document is deliberately NOT bundled here. ceradoc
24
+ # core has no runtime dependency on ceradoc-mirror; consumers that
25
+ # target the mirror JSON pipeline pair an +OutputArtifact+ with a
26
+ # separately-computed +Ceradoc::Mirror.transform(core)+ result.
27
+ class OutputArtifact < Base
28
+ # @!attribute output_key
29
+ # @return [String, nil] site-relative key with no leading slash
30
+ # and no trailing extension. SSGs map this to their URL space.
31
+ attribute :output_key, :string
32
+
33
+ # @!attribute frontmatter_block
34
+ # @return [FrontmatterBlock, nil] parsed YAML frontmatter
35
+ attribute :frontmatter_block, FrontmatterBlock
36
+
37
+ # @!attribute core_document
38
+ # @return [DocumentElement, nil] canonical CoreModel document
39
+ attribute :core_document, DocumentElement
40
+
41
+ private
42
+
43
+ def comparable_attributes
44
+ %i[output_key frontmatter_block core_document]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Paragraph block — a block of prose text
6
+ class ParagraphBlock < Block
7
+ def self.semantic_type
8
+ :paragraph
9
+ end
10
+
11
+ def whitespace_only?
12
+ flat_text.strip.empty?
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ class PartintroBlock < Block
6
+ def self.semantic_type
7
+ :partintro
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ceradoc
4
+ module CoreModel
5
+ # Pass-through block — raw content passed through without processing
6
+ class PassBlock < Block
7
+ def self.semantic_type
8
+ :pass
9
+ end
10
+
11
+ def prose?
12
+ false
13
+ end
14
+ end
15
+ end
16
+ end