coridoc-mirror 0.1.11

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 (91) hide show
  1. checksums.yaml +7 -0
  2. data/lib/coridoc/mirror/core_model_to_mirror.rb +221 -0
  3. data/lib/coridoc/mirror/frontmatter_query.rb +50 -0
  4. data/lib/coridoc/mirror/frontmatter_tree_to_hash.rb +40 -0
  5. data/lib/coridoc/mirror/handler_registry.rb +94 -0
  6. data/lib/coridoc/mirror/handlers/abstract.rb +19 -0
  7. data/lib/coridoc/mirror/handlers/admonition.rb +29 -0
  8. data/lib/coridoc/mirror/handlers/bibliography.rb +43 -0
  9. data/lib/coridoc/mirror/handlers/blockquote.rb +19 -0
  10. data/lib/coridoc/mirror/handlers/code_block.rb +62 -0
  11. data/lib/coridoc/mirror/handlers/comment.rb +14 -0
  12. data/lib/coridoc/mirror/handlers/definition_list.rb +133 -0
  13. data/lib/coridoc/mirror/handlers/example.rb +19 -0
  14. data/lib/coridoc/mirror/handlers/footnote.rb +18 -0
  15. data/lib/coridoc/mirror/handlers/frontmatter.rb +71 -0
  16. data/lib/coridoc/mirror/handlers/generic_block.rb +24 -0
  17. data/lib/coridoc/mirror/handlers/horizontal_rule.rb +14 -0
  18. data/lib/coridoc/mirror/handlers/image.rb +64 -0
  19. data/lib/coridoc/mirror/handlers/include.rb +50 -0
  20. data/lib/coridoc/mirror/handlers/inline.rb +282 -0
  21. data/lib/coridoc/mirror/handlers/list.rb +80 -0
  22. data/lib/coridoc/mirror/handlers/open_block.rb +16 -0
  23. data/lib/coridoc/mirror/handlers/paragraph.rb +16 -0
  24. data/lib/coridoc/mirror/handlers/partintro.rb +19 -0
  25. data/lib/coridoc/mirror/handlers/reviewer.rb +14 -0
  26. data/lib/coridoc/mirror/handlers/sidebar.rb +19 -0
  27. data/lib/coridoc/mirror/handlers/structural.rb +84 -0
  28. data/lib/coridoc/mirror/handlers/table.rb +82 -0
  29. data/lib/coridoc/mirror/handlers/toc.rb +48 -0
  30. data/lib/coridoc/mirror/handlers/verse.rb +22 -0
  31. data/lib/coridoc/mirror/handlers.rb +41 -0
  32. data/lib/coridoc/mirror/mark.rb +181 -0
  33. data/lib/coridoc/mirror/mark_reverse_builder.rb +142 -0
  34. data/lib/coridoc/mirror/mirror_json_format.rb +48 -0
  35. data/lib/coridoc/mirror/mirror_to_core_model.rb +93 -0
  36. data/lib/coridoc/mirror/mirror_yaml_format.rb +47 -0
  37. data/lib/coridoc/mirror/node.rb +1005 -0
  38. data/lib/coridoc/mirror/partitioner.rb +75 -0
  39. data/lib/coridoc/mirror/reverse_builder/abstract.rb +17 -0
  40. data/lib/coridoc/mirror/reverse_builder/admonition.rb +16 -0
  41. data/lib/coridoc/mirror/reverse_builder/base.rb +42 -0
  42. data/lib/coridoc/mirror/reverse_builder/biblio_entry.rb +18 -0
  43. data/lib/coridoc/mirror/reverse_builder/bibliography.rb +14 -0
  44. data/lib/coridoc/mirror/reverse_builder/blockquote.rb +16 -0
  45. data/lib/coridoc/mirror/reverse_builder/bullet_list.rb +14 -0
  46. data/lib/coridoc/mirror/reverse_builder/caption.rb +15 -0
  47. data/lib/coridoc/mirror/reverse_builder/code_block.rb +18 -0
  48. data/lib/coridoc/mirror/reverse_builder/definition_list.rb +31 -0
  49. data/lib/coridoc/mirror/reverse_builder/document.rb +18 -0
  50. data/lib/coridoc/mirror/reverse_builder/example.rb +16 -0
  51. data/lib/coridoc/mirror/reverse_builder/figure.rb +31 -0
  52. data/lib/coridoc/mirror/reverse_builder/footnote_entry.rb +14 -0
  53. data/lib/coridoc/mirror/reverse_builder/footnote_marker.rb +20 -0
  54. data/lib/coridoc/mirror/reverse_builder/footnotes.rb +16 -0
  55. data/lib/coridoc/mirror/reverse_builder/frontmatter.rb +19 -0
  56. data/lib/coridoc/mirror/reverse_builder/generic_block.rb +22 -0
  57. data/lib/coridoc/mirror/reverse_builder/hard_break.rb +13 -0
  58. data/lib/coridoc/mirror/reverse_builder/header.rb +18 -0
  59. data/lib/coridoc/mirror/reverse_builder/horizontal_rule.rb +13 -0
  60. data/lib/coridoc/mirror/reverse_builder/image.rb +21 -0
  61. data/lib/coridoc/mirror/reverse_builder/include.rb +42 -0
  62. data/lib/coridoc/mirror/reverse_builder/inline_text.rb +15 -0
  63. data/lib/coridoc/mirror/reverse_builder/list_item.rb +33 -0
  64. data/lib/coridoc/mirror/reverse_builder/literal_block.rb +18 -0
  65. data/lib/coridoc/mirror/reverse_builder/open_block.rb +13 -0
  66. data/lib/coridoc/mirror/reverse_builder/ordered_list.rb +14 -0
  67. data/lib/coridoc/mirror/reverse_builder/paragraph.rb +13 -0
  68. data/lib/coridoc/mirror/reverse_builder/partintro.rb +17 -0
  69. data/lib/coridoc/mirror/reverse_builder/pass_block.rb +18 -0
  70. data/lib/coridoc/mirror/reverse_builder/preamble.rb +13 -0
  71. data/lib/coridoc/mirror/reverse_builder/raw_inline.rb +13 -0
  72. data/lib/coridoc/mirror/reverse_builder/section.rb +22 -0
  73. data/lib/coridoc/mirror/reverse_builder/sections.rb +15 -0
  74. data/lib/coridoc/mirror/reverse_builder/sidebar.rb +16 -0
  75. data/lib/coridoc/mirror/reverse_builder/soft_break.rb +13 -0
  76. data/lib/coridoc/mirror/reverse_builder/stem_block.rb +18 -0
  77. data/lib/coridoc/mirror/reverse_builder/table.rb +23 -0
  78. data/lib/coridoc/mirror/reverse_builder/table_body.rb +13 -0
  79. data/lib/coridoc/mirror/reverse_builder/table_cell.rb +20 -0
  80. data/lib/coridoc/mirror/reverse_builder/table_head.rb +13 -0
  81. data/lib/coridoc/mirror/reverse_builder/table_row.rb +14 -0
  82. data/lib/coridoc/mirror/reverse_builder/text.rb +20 -0
  83. data/lib/coridoc/mirror/reverse_builder/toc.rb +13 -0
  84. data/lib/coridoc/mirror/reverse_builder/toc_entry.rb +14 -0
  85. data/lib/coridoc/mirror/reverse_builder/verse.rb +16 -0
  86. data/lib/coridoc/mirror/reverse_builder.rb +147 -0
  87. data/lib/coridoc/mirror/transformer.rb +41 -0
  88. data/lib/coridoc/mirror/version.rb +7 -0
  89. data/lib/coridoc/mirror.rb +177 -0
  90. data/lib/coridoc-mirror.rb +12 -0
  91. metadata +191 -0
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module List
7
+ def self.call(element, context:)
8
+ items = Array(element.items).filter_map do |item|
9
+ list_item(item, context: context)
10
+ end
11
+ return nil if items.empty?
12
+
13
+ node_class = ordered?(element) ? Node::OrderedList : Node::BulletList
14
+ node_class.new(
15
+ attrs: node_class::Attrs.new(
16
+ id: element.id,
17
+ start: element.is_a?(CoreModel::ListBlock) ? element.start : nil
18
+ ),
19
+ content: items
20
+ )
21
+ end
22
+
23
+ class << self
24
+ private
25
+
26
+ def list_item(item, context:)
27
+ content = build_item_content(item, context)
28
+ return nil if content.empty?
29
+
30
+ Node::ListItem.new(
31
+ attrs: Node::ListItem::Attrs.new(id: item.id),
32
+ content: content
33
+ )
34
+ end
35
+
36
+ def build_item_content(item, context)
37
+ content = []
38
+
39
+ has_children = item.is_a?(CoreModel::ListItem) &&
40
+ item.children && !item.children.empty?
41
+
42
+ if has_children
43
+ item.children.each do |child|
44
+ node = dispatch_child(child, context)
45
+ content << node if node
46
+ end
47
+ elsif item.content && !item.content.to_s.empty?
48
+ content << context.text_node(item.content.to_s)
49
+ end
50
+
51
+ if item.is_a?(CoreModel::ListItem) && item.nested_list
52
+ nested = Handlers::List.call(item.nested_list, context: context)
53
+ content << nested if nested
54
+ end
55
+
56
+ content
57
+ end
58
+
59
+ def dispatch_child(child, context)
60
+ case child
61
+ when CoreModel::TextContent
62
+ return nil if child.text.nil? || child.text.empty?
63
+
64
+ context.text_node(child.text)
65
+ when CoreModel::InlineElement
66
+ Handlers::Inline.call(child, context: context)
67
+ when CoreModel::Block, CoreModel::StructuralElement
68
+ result = context.registry.handle(child, context: context)
69
+ result&.first
70
+ end
71
+ end
72
+
73
+ def ordered?(element)
74
+ element.marker_type == 'ordered'
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module OpenBlock
7
+ def self.call(element, context:)
8
+ content = context.extract_content(element)
9
+ return nil if content.empty?
10
+
11
+ Node::OpenBlock.new(content: content)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module Paragraph
7
+ def self.call(element, context:)
8
+ content = context.process_inline_content(element)
9
+ return nil if content.empty?
10
+
11
+ Node::Paragraph.new(content: content)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module Partintro
7
+ def self.call(element, context:)
8
+ content = context.extract_content(element)
9
+ return nil if content.empty?
10
+
11
+ Node::Partintro.new(
12
+ attrs: Node::Partintro::Attrs.new(id: element.id, title: element.title),
13
+ content: content
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ # Handles ReviewerBlock → omitted (reviewer notes are not rendered).
7
+ module Reviewer
8
+ def self.call(_element, *)
9
+ nil
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module Sidebar
7
+ def self.call(element, context:)
8
+ content = context.extract_content(element)
9
+ return nil if content.empty?
10
+
11
+ Node::Sidebar.new(
12
+ attrs: Node::Sidebar::Attrs.new(id: element.id, title: element.title),
13
+ content: content
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module Structural
7
+ # Top-level document handler. Stays flat; structural partitioning
8
+ # (preface/sections/bibliography) is opted into via the
9
+ # partition_structural: kwarg on CoreModelToMirror#call, which
10
+ # delegates to Mirror::Partitioner.
11
+ def self.document(element, context:)
12
+ content = context.extract_content(element)
13
+ Node::Document.new(
14
+ attrs: Node::Document::Attrs.new(title: element.title, id: element.id),
15
+ content: content
16
+ )
17
+ end
18
+
19
+ # Map CoreModel section style/title hints to JS SECTION_TYPES.
20
+ # When coridoc propagates AsciiDoc style attributes ([appendix],
21
+ # [bibliography], etc.) into SectionElement.attributes, this table
22
+ # is used to pick the right JS section type. Default fallback is
23
+ # `clause` (the JS generic section type).
24
+ SECTION_STYLE_TO_JS_TYPE = {
25
+ 'appendix' => 'annex',
26
+ 'annex' => 'annex',
27
+ 'bibliography' => 'references',
28
+ 'references' => 'references',
29
+ 'abstract' => 'abstract',
30
+ 'foreword' => 'foreword',
31
+ 'introduction' => 'introduction',
32
+ 'acknowledgements' => 'acknowledgements',
33
+ 'terms' => 'terms',
34
+ 'definitions' => 'definitions'
35
+ }.freeze
36
+
37
+ def self.section(element, context:)
38
+ content = context.extract_content(element)
39
+ type = context.partition_structural ? section_type_for(element) : 'section'
40
+
41
+ Node::Section.new(
42
+ type: type,
43
+ attrs: Node::Section::Attrs.new(
44
+ id: element.id,
45
+ title: element.title,
46
+ level: element.heading_level
47
+ ),
48
+ content: content
49
+ )
50
+ end
51
+
52
+ def self.section_type_for(element)
53
+ style = section_style(element)
54
+ SECTION_STYLE_TO_JS_TYPE[style] || 'clause'
55
+ end
56
+
57
+ # Reads `style` then `role` from SectionElement#attributes via the
58
+ # Metadata#[] accessor — no intermediate hash allocation per call.
59
+ def self.section_style(element)
60
+ attrs = element.attributes
61
+ return nil unless attrs.is_a?(Coridoc::CoreModel::Metadata)
62
+
63
+ attrs['style'] || attrs['role']
64
+ end
65
+
66
+ def self.preamble(element, context:)
67
+ content = context.extract_content(element)
68
+ Node::Preamble.new(content: content)
69
+ end
70
+
71
+ def self.header(element, context:)
72
+ content = context.extract_content(element)
73
+ Node::Header.new(
74
+ attrs: Node::Header::Attrs.new(
75
+ title: element.title,
76
+ level: element.heading_level
77
+ ),
78
+ content: content
79
+ )
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module Table
7
+ def self.call(element, context:)
8
+ rows = Array(element.rows)
9
+ return nil if rows.empty?
10
+
11
+ head_rows, body_rows = partition_rows(rows)
12
+
13
+ content = []
14
+ content << build_table_head(head_rows, context) unless head_rows.empty?
15
+ content << build_table_body(body_rows, context) unless body_rows.empty?
16
+
17
+ return nil if content.empty?
18
+
19
+ Node::Table.new(
20
+ attrs: Node::Table::Attrs.new(
21
+ id: element.id,
22
+ title: element.title,
23
+ width: element.width
24
+ ),
25
+ content: content
26
+ )
27
+ end
28
+
29
+ class << self
30
+ private
31
+
32
+ def partition_rows(rows)
33
+ head = rows.select { |r| r.is_a?(CoreModel::TableRow) && r.header }
34
+ body = rows.reject { |r| r.is_a?(CoreModel::TableRow) && r.header }
35
+ [head, body]
36
+ end
37
+
38
+ def build_table_head(rows, context)
39
+ content = rows.map { |r| build_table_row(r, context) }
40
+ Node::TableHead.new(content: content)
41
+ end
42
+
43
+ def build_table_body(rows, context)
44
+ content = rows.map { |r| build_table_row(r, context) }
45
+ Node::TableBody.new(content: content)
46
+ end
47
+
48
+ def build_table_row(row, context)
49
+ cells = Array(row.cells).map { |c| build_table_cell(c, context) }
50
+ Node::TableRow.new(content: cells)
51
+ end
52
+
53
+ def build_table_cell(cell, context)
54
+ content = build_cell_content(cell, context)
55
+ Node::TableCell.new(
56
+ attrs: Node::TableCell::Attrs.new(
57
+ colspan: cell.colspan,
58
+ rowspan: cell.rowspan,
59
+ alignment: cell.alignment,
60
+ header: cell.header || nil
61
+ ),
62
+ content: content
63
+ )
64
+ end
65
+
66
+ def build_cell_content(cell, context)
67
+ if cell.is_a?(CoreModel::TableCell) && cell.children && !cell.children.empty?
68
+ return cell.children.flat_map do |child|
69
+ Handlers::Inline.process_child(child, context)
70
+ end
71
+ end
72
+
73
+ text = cell.content
74
+ return [] if text.nil? || text.to_s.empty?
75
+
76
+ [context.text_node(text.to_s)]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module Toc
7
+ def self.call(element, context:)
8
+ entries = if element.is_a?(CoreModel::Toc) && element.entries
9
+ Array(element.entries).filter_map do |entry|
10
+ build_entry(entry, context)
11
+ end
12
+ else
13
+ []
14
+ end
15
+
16
+ Node::Toc.new(
17
+ attrs: Node::Toc::Attrs.new(title: element.title),
18
+ content: entries
19
+ )
20
+ end
21
+
22
+ class << self
23
+ private
24
+
25
+ def build_entry(entry, context)
26
+ children = if entry.is_a?(CoreModel::TocEntry) && entry.children
27
+ entry.children.filter_map { |c| build_entry(c, context) }
28
+ else
29
+ []
30
+ end
31
+
32
+ content = [context.text_node(entry.title.to_s)] unless children.any?
33
+ content ||= children
34
+
35
+ Node::TocEntry.new(
36
+ attrs: Node::TocEntry::Attrs.new(
37
+ id: entry.is_a?(CoreModel::TocEntry) ? entry.id : nil,
38
+ title: entry.is_a?(CoreModel::TocEntry) ? entry.title : nil,
39
+ level: entry.is_a?(CoreModel::TocEntry) ? entry.level : nil
40
+ ),
41
+ content: content
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ module Handlers
6
+ module Verse
7
+ def self.call(element, context:)
8
+ text = if element.content && !element.content.to_s.empty?
9
+ element.flat_text || element.content.to_s
10
+ else
11
+ ''
12
+ end
13
+
14
+ Node::Verse.new(
15
+ attrs: Node::Verse::Attrs.new(attribution: element.attribution),
16
+ content: [context.text_node(text)]
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module Mirror
5
+ # Handler modules for transforming CoreModel types to Mirror nodes.
6
+ #
7
+ # Each handler is a module/class that responds to +call(element, context:)+,
8
+ # where +element+ is a CoreModel instance and +context+ is the
9
+ # CoreModelToMirror transformer providing shared helpers.
10
+ #
11
+ # New handlers are added by creating a new module file and registering
12
+ # it in +Coridoc::Mirror.default_registry+ — no existing code changes (OCP).
13
+ module Handlers
14
+ autoload :Structural, "#{__dir__}/handlers/structural"
15
+ autoload :Paragraph, "#{__dir__}/handlers/paragraph"
16
+ autoload :CodeBlock, "#{__dir__}/handlers/code_block"
17
+ autoload :Blockquote, "#{__dir__}/handlers/blockquote"
18
+ autoload :Example, "#{__dir__}/handlers/example"
19
+ autoload :Sidebar, "#{__dir__}/handlers/sidebar"
20
+ autoload :Abstract, "#{__dir__}/handlers/abstract"
21
+ autoload :Partintro, "#{__dir__}/handlers/partintro"
22
+ autoload :OpenBlock, "#{__dir__}/handlers/open_block"
23
+ autoload :Verse, "#{__dir__}/handlers/verse"
24
+ autoload :Comment, "#{__dir__}/handlers/comment"
25
+ autoload :HorizontalRule, "#{__dir__}/handlers/horizontal_rule"
26
+ autoload :Reviewer, "#{__dir__}/handlers/reviewer"
27
+ autoload :Admonition, "#{__dir__}/handlers/admonition"
28
+ autoload :List, "#{__dir__}/handlers/list"
29
+ autoload :DefinitionList, "#{__dir__}/handlers/definition_list"
30
+ autoload :Table, "#{__dir__}/handlers/table"
31
+ autoload :Image, "#{__dir__}/handlers/image"
32
+ autoload :Inline, "#{__dir__}/handlers/inline"
33
+ autoload :Bibliography, "#{__dir__}/handlers/bibliography"
34
+ autoload :Footnote, "#{__dir__}/handlers/footnote"
35
+ autoload :Toc, "#{__dir__}/handlers/toc"
36
+ autoload :Frontmatter, "#{__dir__}/handlers/frontmatter"
37
+ autoload :GenericBlock, "#{__dir__}/handlers/generic_block"
38
+ autoload :Include, "#{__dir__}/handlers/include"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lutaml/model'
4
+
5
+ module Coridoc
6
+ module Mirror
7
+ # ProseMirror-compatible inline mark (formatting annotation).
8
+ #
9
+ # Marks decorate inline text nodes with formatting semantics like
10
+ # bold, italic, link, etc. Wire format:
11
+ #
12
+ # { "type": "strong" }
13
+ # { "type": "link", "attrs": { "href": "..." } }
14
+ #
15
+ # All built-in Mark subclasses live below in this file so the
16
+ # TYPE_TO_CLASS registry at the bottom can see every PM_TYPE at
17
+ # load time. Adding a new mark type = adding one subclass + letting
18
+ # the registry walker pick it up (OCP).
19
+ class Mark < Lutaml::Model::Serializable
20
+ PM_TYPE = 'mark'
21
+
22
+ attribute :type, :string, default: -> { self.class::PM_TYPE }
23
+
24
+ key_value do
25
+ map 'type', to: :type, render_default: true
26
+ end
27
+
28
+ def text_content
29
+ ''
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ module Coridoc
36
+ module Mirror
37
+ class Mark
38
+ # ── Marks without attrs ──
39
+
40
+ class Bold < Mark
41
+ PM_TYPE = 'strong'
42
+ end
43
+
44
+ class Italic < Mark
45
+ PM_TYPE = 'emphasis'
46
+ end
47
+
48
+ class Monospace < Mark
49
+ PM_TYPE = 'code'
50
+ end
51
+
52
+ class Underline < Mark
53
+ PM_TYPE = 'underline'
54
+ end
55
+
56
+ class Strikethrough < Mark
57
+ PM_TYPE = 'strike'
58
+ end
59
+
60
+ class Subscript < Mark
61
+ PM_TYPE = 'subscript'
62
+ end
63
+
64
+ class Superscript < Mark
65
+ PM_TYPE = 'superscript'
66
+ end
67
+
68
+ class Highlight < Mark
69
+ PM_TYPE = 'highlight'
70
+ end
71
+
72
+ # ── Marks with attrs ──
73
+
74
+ class Link < Mark
75
+ PM_TYPE = 'link'
76
+
77
+ class Attrs < Lutaml::Model::Serializable
78
+ attribute :href, :string
79
+
80
+ key_value do
81
+ map 'href', to: :href
82
+ end
83
+ end
84
+
85
+ attribute :attrs, Attrs
86
+
87
+ key_value do
88
+ map 'type', to: :type, render_default: true
89
+ map 'attrs', to: :attrs
90
+ end
91
+ end
92
+
93
+ class CrossReference < Mark
94
+ PM_TYPE = 'xref'
95
+
96
+ class Attrs < Lutaml::Model::Serializable
97
+ attribute :target, :string
98
+ attribute :resolved, :string
99
+
100
+ key_value do
101
+ map 'target', to: :target
102
+ map 'resolved', to: :resolved
103
+ end
104
+ end
105
+
106
+ attribute :attrs, Attrs
107
+
108
+ key_value do
109
+ map 'type', to: :type, render_default: true
110
+ map 'attrs', to: :attrs
111
+ end
112
+ end
113
+
114
+ class Stem < Mark
115
+ PM_TYPE = 'stem'
116
+
117
+ class Attrs < Lutaml::Model::Serializable
118
+ attribute :stem_type, :string
119
+
120
+ key_value do
121
+ map 'stem_type', to: :stem_type
122
+ end
123
+ end
124
+
125
+ attribute :attrs, Attrs
126
+
127
+ key_value do
128
+ map 'type', to: :type, render_default: true
129
+ map 'attrs', to: :attrs
130
+ end
131
+ end
132
+
133
+ class Span < Mark
134
+ PM_TYPE = 'span'
135
+
136
+ class Attrs < Lutaml::Model::Serializable
137
+ attribute :role, :string
138
+
139
+ key_value do
140
+ map 'role', to: :role
141
+ end
142
+ end
143
+
144
+ attribute :attrs, Attrs
145
+
146
+ key_value do
147
+ map 'type', to: :type, render_default: true
148
+ map 'attrs', to: :attrs
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ module Coridoc
156
+ module Mirror
157
+ class Mark
158
+ # Polymorphic class map — flat hash from PM_TYPE wire string to
159
+ # fully-qualified Ruby class name. Used by Node and Mark mappings
160
+ # to dispatch polymorphic deserialization. Populated once after
161
+ # all subclasses are defined above.
162
+ TYPE_TO_CLASS = begin
163
+ result = {}
164
+ Mark.constants.each do |name|
165
+ k = Mark.const_get(name)
166
+ next unless k.is_a?(Class) && k < Mark && k::PM_TYPE != 'mark'
167
+
168
+ result[k::PM_TYPE] = k.name
169
+ end
170
+ result.freeze
171
+ end
172
+
173
+ # Frozen polymorphic option block. Referenced verbatim by every
174
+ # Node mapping that has a `marks` collection.
175
+ POLYMORPHIC = {
176
+ attribute: 'type',
177
+ class_map: TYPE_TO_CLASS
178
+ }.freeze
179
+ end
180
+ end
181
+ end