coridoc 3.0.0

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 (148) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/Rakefile +8 -0
  4. data/exe/coridoc +24 -0
  5. data/lib/coridoc/binding_inflater.rb +118 -0
  6. data/lib/coridoc/cli.rb +311 -0
  7. data/lib/coridoc/configurable.rb +530 -0
  8. data/lib/coridoc/core_model/abstract_block.rb +11 -0
  9. data/lib/coridoc/core_model/annotation_block.rb +57 -0
  10. data/lib/coridoc/core_model/attribute_reference_resolver.rb +155 -0
  11. data/lib/coridoc/core_model/base.rb +281 -0
  12. data/lib/coridoc/core_model/bibliography.rb +41 -0
  13. data/lib/coridoc/core_model/bibliography_entry.rb +48 -0
  14. data/lib/coridoc/core_model/block.rb +69 -0
  15. data/lib/coridoc/core_model/callout.rb +32 -0
  16. data/lib/coridoc/core_model/callout_text.rb +35 -0
  17. data/lib/coridoc/core_model/children_content.rb +72 -0
  18. data/lib/coridoc/core_model/comment_block.rb +16 -0
  19. data/lib/coridoc/core_model/comment_line.rb +23 -0
  20. data/lib/coridoc/core_model/definition_item.rb +68 -0
  21. data/lib/coridoc/core_model/definition_list.rb +28 -0
  22. data/lib/coridoc/core_model/element_attribute.rb +14 -0
  23. data/lib/coridoc/core_model/example_block.rb +12 -0
  24. data/lib/coridoc/core_model/footnote.rb +92 -0
  25. data/lib/coridoc/core_model/frontmatter/codec.rb +151 -0
  26. data/lib/coridoc/core_model/frontmatter/field_transform.rb +75 -0
  27. data/lib/coridoc/core_model/frontmatter/frontmatter_entry.rb +22 -0
  28. data/lib/coridoc/core_model/frontmatter/frontmatter_value.rb +78 -0
  29. data/lib/coridoc/core_model/frontmatter/schema_resolver.rb +57 -0
  30. data/lib/coridoc/core_model/frontmatter/text_splitter.rb +75 -0
  31. data/lib/coridoc/core_model/frontmatter.rb +72 -0
  32. data/lib/coridoc/core_model/has_children.rb +23 -0
  33. data/lib/coridoc/core_model/horizontal_rule_block.rb +16 -0
  34. data/lib/coridoc/core_model/id_generator.rb +23 -0
  35. data/lib/coridoc/core_model/image.rb +69 -0
  36. data/lib/coridoc/core_model/include.rb +43 -0
  37. data/lib/coridoc/core_model/include_level_offset.rb +71 -0
  38. data/lib/coridoc/core_model/include_options.rb +101 -0
  39. data/lib/coridoc/core_model/inline_content.rb +78 -0
  40. data/lib/coridoc/core_model/inline_element.rb +198 -0
  41. data/lib/coridoc/core_model/list_block.rb +137 -0
  42. data/lib/coridoc/core_model/list_item.rb +129 -0
  43. data/lib/coridoc/core_model/listing_block.rb +19 -0
  44. data/lib/coridoc/core_model/literal_block.rb +16 -0
  45. data/lib/coridoc/core_model/metadata.rb +71 -0
  46. data/lib/coridoc/core_model/open_block.rb +12 -0
  47. data/lib/coridoc/core_model/output_artifact.rb +48 -0
  48. data/lib/coridoc/core_model/paragraph_block.rb +16 -0
  49. data/lib/coridoc/core_model/partintro_block.rb +11 -0
  50. data/lib/coridoc/core_model/pass_block.rb +16 -0
  51. data/lib/coridoc/core_model/quote_block.rb +14 -0
  52. data/lib/coridoc/core_model/raw_inline_element.rb +16 -0
  53. data/lib/coridoc/core_model/reviewer_block.rb +12 -0
  54. data/lib/coridoc/core_model/sidebar_block.rb +12 -0
  55. data/lib/coridoc/core_model/source_block.rb +16 -0
  56. data/lib/coridoc/core_model/stem_block.rb +25 -0
  57. data/lib/coridoc/core_model/structural_element.rb +157 -0
  58. data/lib/coridoc/core_model/table.rb +148 -0
  59. data/lib/coridoc/core_model/term.rb +53 -0
  60. data/lib/coridoc/core_model/text_content.rb +26 -0
  61. data/lib/coridoc/core_model/toc.rb +99 -0
  62. data/lib/coridoc/core_model/toc_generator.rb +151 -0
  63. data/lib/coridoc/core_model/verse_block.rb +14 -0
  64. data/lib/coridoc/core_model.rb +92 -0
  65. data/lib/coridoc/coridoc.rb +164 -0
  66. data/lib/coridoc/dispatch.rb +96 -0
  67. data/lib/coridoc/errors.rb +387 -0
  68. data/lib/coridoc/format_catalog.rb +102 -0
  69. data/lib/coridoc/format_module.rb +78 -0
  70. data/lib/coridoc/hooks.rb +176 -0
  71. data/lib/coridoc/include_resolver/filesystem.rb +84 -0
  72. data/lib/coridoc/include_resolver.rb +67 -0
  73. data/lib/coridoc/include_selectors/indent.rb +54 -0
  74. data/lib/coridoc/include_selectors/level_offset.rb +84 -0
  75. data/lib/coridoc/include_selectors/lines.rb +60 -0
  76. data/lib/coridoc/include_selectors/tags.rb +136 -0
  77. data/lib/coridoc/include_selectors.rb +26 -0
  78. data/lib/coridoc/introspection/element_counter.rb +48 -0
  79. data/lib/coridoc/introspection.rb +72 -0
  80. data/lib/coridoc/link_rewriter/identity.rb +13 -0
  81. data/lib/coridoc/link_rewriter/visitor.rb +148 -0
  82. data/lib/coridoc/link_rewriter.rb +37 -0
  83. data/lib/coridoc/lint/registry.rb +33 -0
  84. data/lib/coridoc/lint/rule.rb +41 -0
  85. data/lib/coridoc/lint/runner.rb +67 -0
  86. data/lib/coridoc/lint/template.rb +190 -0
  87. data/lib/coridoc/lint/violation.rb +16 -0
  88. data/lib/coridoc/lint.rb +44 -0
  89. data/lib/coridoc/logger.rb +54 -0
  90. data/lib/coridoc/performance_regression.rb +121 -0
  91. data/lib/coridoc/pipeline.rb +169 -0
  92. data/lib/coridoc/query.rb +486 -0
  93. data/lib/coridoc/reference/address/anchor.rb +48 -0
  94. data/lib/coridoc/reference/address/doi.rb +40 -0
  95. data/lib/coridoc/reference/address/isbn.rb +39 -0
  96. data/lib/coridoc/reference/address/path.rb +66 -0
  97. data/lib/coridoc/reference/address/scoped_path.rb +47 -0
  98. data/lib/coridoc/reference/address/url.rb +41 -0
  99. data/lib/coridoc/reference/address.rb +153 -0
  100. data/lib/coridoc/reference/catalog/composite.rb +59 -0
  101. data/lib/coridoc/reference/catalog/local.rb +97 -0
  102. data/lib/coridoc/reference/catalog/memory_index.rb +59 -0
  103. data/lib/coridoc/reference/catalog.rb +33 -0
  104. data/lib/coridoc/reference/edge/citation_options.rb +16 -0
  105. data/lib/coridoc/reference/edge/footnote_ref_options.rb +13 -0
  106. data/lib/coridoc/reference/edge/image_ref_options.rb +15 -0
  107. data/lib/coridoc/reference/edge/include_options.rb +15 -0
  108. data/lib/coridoc/reference/edge/kind.rb +72 -0
  109. data/lib/coridoc/reference/edge/link_options.rb +12 -0
  110. data/lib/coridoc/reference/edge/navigation_options.rb +12 -0
  111. data/lib/coridoc/reference/edge/options.rb +13 -0
  112. data/lib/coridoc/reference/edge.rb +80 -0
  113. data/lib/coridoc/reference/edge_search.rb +128 -0
  114. data/lib/coridoc/reference/materializer/base.rb +44 -0
  115. data/lib/coridoc/reference/materializer/passthrough.rb +31 -0
  116. data/lib/coridoc/reference/materializer/registry.rb +116 -0
  117. data/lib/coridoc/reference/materializer.rb +14 -0
  118. data/lib/coridoc/reference/presentation/base.rb +47 -0
  119. data/lib/coridoc/reference/presentation/custom_hierarchy.rb +104 -0
  120. data/lib/coridoc/reference/presentation/page.rb +20 -0
  121. data/lib/coridoc/reference/presentation/single_document.rb +35 -0
  122. data/lib/coridoc/reference/presentation/split_pages.rb +118 -0
  123. data/lib/coridoc/reference/presentation.rb +16 -0
  124. data/lib/coridoc/reference/resolution.rb +184 -0
  125. data/lib/coridoc/reference/resolver/base.rb +15 -0
  126. data/lib/coridoc/reference/resolver/caching.rb +37 -0
  127. data/lib/coridoc/reference/resolver/catalog.rb +69 -0
  128. data/lib/coridoc/reference/resolver/chain.rb +33 -0
  129. data/lib/coridoc/reference/resolver.rb +20 -0
  130. data/lib/coridoc/reference/result/ambiguous.rb +23 -0
  131. data/lib/coridoc/reference/result/base.rb +46 -0
  132. data/lib/coridoc/reference/result/missing.rb +14 -0
  133. data/lib/coridoc/reference/result/resolved.rb +22 -0
  134. data/lib/coridoc/reference/result.rb +20 -0
  135. data/lib/coridoc/reference.rb +65 -0
  136. data/lib/coridoc/registry.rb +156 -0
  137. data/lib/coridoc/relative_path.rb +32 -0
  138. data/lib/coridoc/resolve_includes.rb +202 -0
  139. data/lib/coridoc/source_graph/file_node.rb +147 -0
  140. data/lib/coridoc/source_graph/graph.rb +165 -0
  141. data/lib/coridoc/source_graph/include_edges.rb +33 -0
  142. data/lib/coridoc/source_graph/sidecar.rb +97 -0
  143. data/lib/coridoc/source_graph.rb +36 -0
  144. data/lib/coridoc/validation.rb +686 -0
  145. data/lib/coridoc/version.rb +5 -0
  146. data/lib/coridoc/visitor.rb +283 -0
  147. data/lib/coridoc.rb +41 -0
  148. metadata +221 -0
@@ -0,0 +1,198 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
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
+
52
+ private
53
+
54
+ def comparable_attributes
55
+ %i[format_type content nested_elements stem_type]
56
+ end
57
+ end
58
+
59
+ # Typed InlineElement subclasses
60
+
61
+ class BoldElement < InlineElement
62
+ def self.format_type
63
+ 'bold'
64
+ end
65
+ end
66
+
67
+ class ItalicElement < InlineElement
68
+ def self.format_type
69
+ 'italic'
70
+ end
71
+ end
72
+
73
+ class MonospaceElement < InlineElement
74
+ def self.format_type
75
+ 'monospace'
76
+ end
77
+ end
78
+
79
+ class UnderlineElement < InlineElement
80
+ def self.format_type
81
+ 'underline'
82
+ end
83
+ end
84
+
85
+ class StrikethroughElement < InlineElement
86
+ def self.format_type
87
+ 'strikethrough'
88
+ end
89
+ end
90
+
91
+ class SubscriptElement < InlineElement
92
+ def self.format_type
93
+ 'subscript'
94
+ end
95
+ end
96
+
97
+ class SuperscriptElement < InlineElement
98
+ def self.format_type
99
+ 'superscript'
100
+ end
101
+ end
102
+
103
+ class HighlightElement < InlineElement
104
+ def self.format_type
105
+ 'highlight'
106
+ end
107
+ end
108
+
109
+ class LinkElement < InlineElement
110
+ def self.format_type
111
+ 'link'
112
+ end
113
+
114
+ def link_kind
115
+ :link
116
+ end
117
+ end
118
+
119
+ class CrossReferenceElement < InlineElement
120
+ def self.format_type
121
+ 'xref'
122
+ end
123
+
124
+ def link_kind
125
+ :xref
126
+ end
127
+ end
128
+
129
+ class StemElement < InlineElement
130
+ def self.format_type
131
+ 'stem'
132
+ end
133
+ end
134
+
135
+ class FootnoteElement < InlineElement
136
+ def self.format_type
137
+ 'footnote'
138
+ end
139
+ end
140
+
141
+ class HardLineBreakElement < InlineElement
142
+ def self.format_type
143
+ 'hard_line_break'
144
+ end
145
+ end
146
+
147
+ class TextElement < InlineElement
148
+ def self.format_type
149
+ 'text'
150
+ end
151
+ end
152
+
153
+ class SpanElement < InlineElement
154
+ def self.format_type
155
+ 'span'
156
+ end
157
+ end
158
+
159
+ class TermElement < InlineElement
160
+ def self.format_type
161
+ 'term'
162
+ end
163
+ end
164
+
165
+ class LineBreakElement < InlineElement
166
+ def self.format_type
167
+ 'line_break'
168
+ end
169
+ end
170
+
171
+ # Wire-name table: bidirectional string ↔ class index. Single source
172
+ # of truth for serialization names and runtime dispatch. Reopened
173
+ # onto InlineElement so the subclasses above are defined first.
174
+ class InlineElement
175
+ FORMAT_TYPE_CLASS_MAP = {
176
+ 'bold' => BoldElement,
177
+ 'italic' => ItalicElement,
178
+ 'monospace' => MonospaceElement,
179
+ 'underline' => UnderlineElement,
180
+ 'strikethrough' => StrikethroughElement,
181
+ 'subscript' => SubscriptElement,
182
+ 'superscript' => SuperscriptElement,
183
+ 'highlight' => HighlightElement,
184
+ 'link' => LinkElement,
185
+ 'xref' => CrossReferenceElement,
186
+ 'stem' => StemElement,
187
+ 'footnote' => FootnoteElement,
188
+ 'hard_line_break' => HardLineBreakElement,
189
+ 'text' => TextElement,
190
+ 'span' => SpanElement,
191
+ 'term' => TermElement,
192
+ 'line_break' => LineBreakElement
193
+ }.freeze
194
+
195
+ FORMAT_TYPES = FORMAT_TYPE_CLASS_MAP.keys.freeze
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
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, 'Coridoc::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, Coridoc::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 Coridoc
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?(Coridoc::CoreModel::ListBlock) &&
109
+ list2.is_a?(Coridoc::CoreModel::ListBlock)
110
+ list1.semantically_equivalent?(list2)
111
+ elsif list1.instance_of?(::Coridoc::CoreModel::ListBlock) &&
112
+ list2.instance_of?(::Coridoc::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 Coridoc
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 Coridoc
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 Coridoc
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 Coridoc
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 Coridoc
4
+ module CoreModel
5
+ # Output-side state object for host-system emitters (VitePress, Hugo,
6
+ # Astro, plain ERB, etc.).
7
+ #
8
+ # coridoc'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 coridoc 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. coridoc 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. coridoc
24
+ # core has no runtime dependency on coridoc-mirror; consumers that
25
+ # target the mirror JSON pipeline pair an +OutputArtifact+ with a
26
+ # separately-computed +Coridoc::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 Coridoc
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 Coridoc
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 Coridoc
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
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Quote block — a delimited block for quotations
6
+ class QuoteBlock < Block
7
+ def self.semantic_type
8
+ :quote
9
+ end
10
+
11
+ attribute :attribution, :string
12
+ end
13
+ end
14
+ end