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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Inline raw passthrough — content the source format marked as "do not
6
+ # process". AsciiDoc's `+++raw+++` is the canonical producer. Spokes
7
+ # that lack a passthrough concept (most of them) should emit the
8
+ # content verbatim, since the original author explicitly chose raw
9
+ # markup (often HTML) knowing it would be passed through.
10
+ class RawInlineElement < InlineElement
11
+ def self.format_type
12
+ 'raw_inline'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Reviewer comment block — a block for reviewer annotations
6
+ class ReviewerBlock < AnnotationBlock
7
+ def self.semantic_type
8
+ :reviewer
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Sidebar block — a delimited block for sidebars
6
+ class SidebarBlock < Block
7
+ def self.semantic_type
8
+ :sidebar
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Specialized block for source code listings
6
+ class SourceBlock < Block
7
+ def self.semantic_type
8
+ :source_code
9
+ end
10
+
11
+ def prose?
12
+ false
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # STEM block — mathematical/scientific content authored in LaTeX,
6
+ # AsciiMath, or another STEM markup. Carries a +language+ attribute so
7
+ # downstream renderers know which interpreter to invoke.
8
+ #
9
+ # AsciiDoc surface forms:
10
+ # [stem]\n++++\nx^2\n++++ # language: "latex" (default)
11
+ # [latexmath]\n++++\nx^2\n++++ # language: "latex"
12
+ # [asciimath]\n++++\nx^2\n++++ # language: "asciimath"
13
+ class StemBlock < Block
14
+ attribute :language, :string, default: -> { 'latex' }
15
+
16
+ def self.semantic_type
17
+ :stem
18
+ end
19
+
20
+ def prose?
21
+ false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Base class for structural elements
6
+ #
7
+ # Represents document structure elements that organize content.
8
+ # Typed subclasses (SectionElement, DocumentElement, etc.) express
9
+ # their role via the class hierarchy — the class IS the type.
10
+ #
11
+ # Structural elements can contain other elements (blocks, lists, etc.)
12
+ # and can be nested hierarchically to represent document structure.
13
+ class StructuralElement < Base
14
+ # StructuralElements carry typed block children (sections, paragraphs,
15
+ # etc.) rather than mixed inline content, so they don't include
16
+ # ChildrenContent. HasChildren marks the structural predicate that
17
+ # downstream traversal dispatches on (OCP).
18
+ include HasChildren
19
+ # @!attribute level
20
+ # @return [Integer, nil] hierarchical level (1-6 for sections)
21
+ attribute :level, :integer
22
+
23
+ # @!attribute content
24
+ # @return [String, nil] text content of the element
25
+ attribute :content, :string
26
+
27
+ # @!attribute children
28
+ # @return [Array<Base>, nil] child elements (sections, blocks, etc.)
29
+ attribute :children, Base, collection: true
30
+
31
+ # @!attribute attributes
32
+ # @return [Metadata, nil] document-level attributes (typed key-value pairs)
33
+ attribute :attributes, Metadata
34
+
35
+ def heading_level
36
+ level || 1
37
+ end
38
+
39
+ def section?
40
+ false
41
+ end
42
+
43
+ def document?
44
+ false
45
+ end
46
+
47
+ def preamble?
48
+ false
49
+ end
50
+
51
+ def header?
52
+ false
53
+ end
54
+
55
+ # Override in subclasses that carry document-title semantics.
56
+ # HeaderElement at level 0 represents the document title (`= Title`
57
+ # in AsciiDoc). Consumers that walk the body — TOC builders,
58
+ # section numbering — skip these so the title is not counted as
59
+ # "section 1". Polymorphic dispatch (vs. an is_a? guard at the
60
+ # call site) keeps the predicate open for future subclasses.
61
+ def document_title?
62
+ false
63
+ end
64
+
65
+ # Children that count as body content and aren't whitespace-only.
66
+ # Derived from per-node {#body_content?} and {#whitespace_only?}
67
+ # predicates — no central walker, no is_a? switch to maintain.
68
+ def visible_children
69
+ Array(children).select(&:body_content?).reject(&:whitespace_only?)
70
+ end
71
+
72
+ # True when the body has no visible content anywhere in its subtree.
73
+ # A document with only frontmatter + comments returns true; a
74
+ # document with one non-whitespace paragraph returns false.
75
+ def empty_body?
76
+ return true if children.nil? || children.empty?
77
+
78
+ children.all? do |child|
79
+ next true unless child.body_content?
80
+ next true if child.whitespace_only?
81
+ next child.empty_body? if child.is_a?(StructuralElement)
82
+
83
+ false
84
+ end
85
+ end
86
+
87
+ # Derived element_type string for backward compatibility with
88
+ # templates and legacy consumers. Subclasses override this.
89
+ def element_type
90
+ self.class.element_type_name
91
+ end
92
+
93
+ def self.element_type_name
94
+ nil
95
+ end
96
+
97
+ private
98
+
99
+ def comparable_attributes
100
+ [:title] + %i[level children]
101
+ end
102
+ end
103
+
104
+ # Root document element
105
+ class DocumentElement < StructuralElement
106
+ def document?
107
+ true
108
+ end
109
+
110
+ def self.element_type_name
111
+ 'document'
112
+ end
113
+ end
114
+
115
+ # Section with a heading at a specific level
116
+ class SectionElement < StructuralElement
117
+ def section?
118
+ true
119
+ end
120
+
121
+ def self.element_type_name
122
+ 'section'
123
+ end
124
+ end
125
+
126
+ # Preamble content before the first section heading
127
+ class PreambleElement < StructuralElement
128
+ def preamble?
129
+ true
130
+ end
131
+
132
+ def self.element_type_name
133
+ 'preamble'
134
+ end
135
+ end
136
+
137
+ # Header / title block of a document
138
+ class HeaderElement < StructuralElement
139
+ def header?
140
+ true
141
+ end
142
+
143
+ # A level-0 HeaderElement represents the document title (the `= Title`
144
+ # line in AsciiDoc, the `<h1>` in HTML). It is structurally part of
145
+ # the body but semantically the document's title, not a section —
146
+ # section numbering, TOC builders, and other section-aware logic
147
+ # skip these so the title is not counted as "section 1".
148
+ def document_title?
149
+ level.to_i.zero?
150
+ end
151
+
152
+ def self.element_type_name
153
+ 'header'
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Represents a table cell in a document
6
+ #
7
+ # Table cells can contain text content and have various formatting
8
+ # attributes like alignment, colspan, rowspan, and styling.
9
+ #
10
+ # Cell format specification: [colspan][.rowspan][halign][valign][style][*]
11
+ #
12
+ # @example Creating a table cell with full formatting
13
+ # cell = CoreModel::TableCell.new(
14
+ # content: "Cell content",
15
+ # alignment: "center",
16
+ # colspan: 2,
17
+ # rowspan: 3,
18
+ # style: "emphasis",
19
+ # bgcolor: "#ffff00"
20
+ # )
21
+ class TableCell < Base
22
+ attribute :children, Base, collection: true
23
+
24
+ include ChildrenContent
25
+
26
+ # @!attribute content
27
+ # @return [String, nil] text content of the cell
28
+ attribute :content, :string
29
+
30
+ # @!attribute alignment
31
+ # @return [String, nil] horizontal text alignment ('left', 'center', 'right')
32
+ attribute :alignment, :string
33
+
34
+ # @!attribute vertical_alignment
35
+ # @return [String, nil] vertical alignment ('top', 'middle', 'bottom')
36
+ attribute :vertical_alignment, :string
37
+
38
+ # @!attribute colspan
39
+ # @return [Integer, nil] number of columns to span
40
+ attribute :colspan, :integer
41
+
42
+ # @!attribute rowspan
43
+ # @return [Integer, nil] number of rows to span
44
+ attribute :rowspan, :integer
45
+
46
+ # @!attribute header
47
+ # @return [Boolean] whether this is a header cell
48
+ attribute :header, :boolean, default: -> { false }
49
+
50
+ # @!attribute style
51
+ # @return [String, nil] cell style ('default', 'strong', 'emphasis', 'monospace',
52
+ # 'asciidoc', 'literal', 'verse')
53
+ attribute :style, :string
54
+
55
+ private
56
+
57
+ def comparable_attributes
58
+ %i[content alignment vertical_alignment colspan rowspan header style]
59
+ end
60
+ end
61
+
62
+ # Represents a row in a table
63
+ #
64
+ # A table row contains multiple cells and can be a header row
65
+ # or a data row.
66
+ #
67
+ # @example Creating a table row
68
+ # row = CoreModel::TableRow.new(
69
+ # cells: [
70
+ # CoreModel::TableCell.new(content: "Name"),
71
+ # CoreModel::TableCell.new(content: "Value")
72
+ # ],
73
+ # header: true
74
+ # )
75
+ class TableRow < Base
76
+ # @!attribute cells
77
+ # @return [Array<TableCell>] collection of cells in the row
78
+ attribute :cells, TableCell, collection: true
79
+
80
+ # @!attribute header
81
+ # @return [Boolean] whether this is a header row
82
+ attribute :header, :boolean, default: -> { false }
83
+
84
+ private
85
+
86
+ def comparable_attributes
87
+ %i[cells header]
88
+ end
89
+ end
90
+
91
+ # Represents a table in a document
92
+ #
93
+ # Tables contain rows of cells and support various formatting options
94
+ # like frame, grid, column widths, and styling.
95
+ #
96
+ # @example Creating a simple table
97
+ # table = CoreModel::Table.new(
98
+ # title: "Data Table",
99
+ # rows: [
100
+ # CoreModel::TableRow.new(
101
+ # cells: [
102
+ # CoreModel::TableCell.new(content: "Header 1", header: true),
103
+ # CoreModel::TableCell.new(content: "Header 2", header: true)
104
+ # ],
105
+ # header: true
106
+ # ),
107
+ # CoreModel::TableRow.new(
108
+ # cells: [
109
+ # CoreModel::TableCell.new(content: "Cell 1"),
110
+ # CoreModel::TableCell.new(content: "Cell 2")
111
+ # ]
112
+ # )
113
+ # ]
114
+ # )
115
+ #
116
+ # @example Creating a table with column specifications
117
+ # table = CoreModel::Table.new(
118
+ # cols: ["1", "2", "3"], # relative widths
119
+ # col_alignments: ["left", "center", "right"],
120
+ # col_styles: [nil, "emphasis", "monospace"],
121
+ # rows: [...]
122
+ # )
123
+ class Table < Base
124
+ # @!attribute rows
125
+ # @return [Array<TableRow>] collection of table rows
126
+ attribute :rows, TableRow, collection: true
127
+
128
+ # @!attribute grid
129
+ # @return [String, nil] table grid style ('all', 'cols', 'rows', 'none')
130
+ # @note Not yet wired by any transformer; reserved for future use
131
+ attribute :grid, :string
132
+
133
+ # @!attribute width
134
+ # @return [String, nil] table width (e.g., '100%', '500px')
135
+ attribute :width, :string
136
+
137
+ # @!attribute cols
138
+ # @return [Array<String>, nil] column width specifications (e.g., ["1", "2", "3"])
139
+ attribute :cols, :string, collection: true
140
+
141
+ private
142
+
143
+ def comparable_attributes
144
+ super + %i[rows grid width cols]
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Represents a definition term in a document
6
+ #
7
+ # Terms are used in definition lists, glossaries, and terminology
8
+ # sections. They can have various types (acronym, symbol, preferred, etc.)
9
+ # and support multi-language content.
10
+ #
11
+ # @example Creating a simple term
12
+ # term = CoreModel::Term.new(
13
+ # text: "API",
14
+ # type: "acronym",
15
+ # definition: "Application Programming Interface"
16
+ # )
17
+ #
18
+ # @example Creating a multi-language term
19
+ # term = CoreModel::Term.new(
20
+ # text: "computer",
21
+ # type: "preferred",
22
+ # lang: "en",
23
+ # definition: "An electronic device for processing data"
24
+ # )
25
+ class Term < Base
26
+ # @!attribute text
27
+ # @return [String, nil] the term text
28
+ attribute :text, :string
29
+
30
+ # @!attribute type
31
+ # @return [String, nil] term type ('acronym', 'symbol', 'preferred', 'admitted', 'deprecated')
32
+ attribute :type, :string
33
+
34
+ # @!attribute lang
35
+ # @return [String] language code (default: 'en')
36
+ attribute :lang, :string, default: -> { 'en' }
37
+
38
+ # @!attribute definition
39
+ # @return [String, nil] definition of the term
40
+ attribute :definition, :string
41
+
42
+ # @!attribute source
43
+ # @return [String, nil] source reference for the term
44
+ attribute :source, :string
45
+
46
+ private
47
+
48
+ def comparable_attributes
49
+ super + %i[text type lang definition]
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Wrapper for plain-text strings in mixed-content children arrays.
6
+ #
7
+ # Enables every child in a children collection to be a typed Base
8
+ # instance, so that children can be declared as
9
+ # attribute :children, Base, collection: true
10
+ # matching StructuralElement's proven pattern.
11
+ #
12
+ # @example
13
+ # TextContent.new(text: "Hello, world")
14
+ class TextContent < Base
15
+ attribute :text, :string
16
+
17
+ def to_s
18
+ text.to_s
19
+ end
20
+
21
+ def whitespace_only?
22
+ text.to_s.strip.empty?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Represents a Table of Contents in a document
6
+ #
7
+ # TOC provides hierarchical navigation structure for documents.
8
+ # It can be auto-generated from document sections or manually defined.
9
+ #
10
+ # @example Creating a TOC from sections
11
+ # toc = CoreModel::Toc.new(
12
+ # entries: [
13
+ # CoreModel::TocEntry.new(
14
+ # id: 'section-1',
15
+ # title: 'Section 1',
16
+ # level: 1,
17
+ # children: [
18
+ # CoreModel::TocEntry.new(id: 'subsection', title: 'Subsection', level: 2)
19
+ # ]
20
+ # )
21
+ # ]
22
+ # )
23
+ #
24
+ # @example Creating a TOC with configuration
25
+ # toc = CoreModel::Toc.new(
26
+ # entries: entries,
27
+ # min_level: 1,
28
+ # max_level: 3,
29
+ # numbered: true
30
+ # )
31
+ class Toc < Base
32
+ # @!attribute entries
33
+ # @return [Array<TocEntry>] the TOC entries
34
+ # Declared as Base (not :string): TocEntry is defined below and
35
+ # lutaml-model never re-registers a re-declared attribute — the
36
+ # old remove_method reopen did not fix the :string cast, so every
37
+ # entry was stringified at construction (issue #255). Base-typed
38
+ # collections preserve TocEntry instances (the pattern used by
39
+ # Block/Table children).
40
+ attribute :entries, Base, collection: true
41
+
42
+ # @!attribute min_level
43
+ # @return [Integer] minimum heading level to include (default: 1)
44
+ attribute :min_level, :integer, default: -> { 1 }
45
+
46
+ # @!attribute max_level
47
+ # @return [Integer] maximum heading level to include (default: 6)
48
+ attribute :max_level, :integer, default: -> { 6 }
49
+
50
+ # @!attribute numbered
51
+ # @return [Boolean] whether to include section numbers
52
+ attribute :numbered, :boolean, default: -> { false }
53
+
54
+ # @!attribute styled
55
+ # @return [Boolean] whether to include styling
56
+ attribute :styled, :boolean, default: -> { false }
57
+
58
+ private
59
+
60
+ def comparable_attributes
61
+ super + %i[entries min_level max_level numbered styled]
62
+ end
63
+ end
64
+
65
+ # Represents a single entry in a Table of Contents
66
+ #
67
+ # Each entry represents a heading/section and can contain
68
+ # nested child entries.
69
+ class TocEntry < Base
70
+ # @!attribute id
71
+ # @return [String, nil] the anchor ID for linking
72
+ attribute :id, :string
73
+
74
+ # @!attribute title
75
+ # @return [String, nil] the heading text
76
+ attribute :title, :string
77
+
78
+ # @!attribute level
79
+ # @return [Integer] the heading level (1-6)
80
+ attribute :level, :integer, default: -> { 1 }
81
+
82
+ # @!attribute number
83
+ # @return [String, nil] the section number (e.g., "1.2.3")
84
+ attribute :number, :string
85
+
86
+ # @!attribute children
87
+ # @return [Array<TocEntry>] nested child entries
88
+ # Base-typed for the same reason as Toc#entries (self-referential;
89
+ # see issue #255).
90
+ attribute :children, Base, collection: true
91
+
92
+ private
93
+
94
+ def comparable_attributes
95
+ super + %i[id title level number children]
96
+ end
97
+ end
98
+ end
99
+ end