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,1005 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lutaml/model'
4
+ require_relative 'mark'
5
+
6
+ module Coridoc
7
+ module Mirror
8
+ # ProseMirror-compatible document node.
9
+ #
10
+ # Wire format:
11
+ #
12
+ # { "type": "paragraph", "attrs": {...}, "content": [...], "marks": [...] }
13
+ #
14
+ # All built-in Node subclasses live below in this file so the
15
+ # TYPE_TO_CLASS registry can see every PM_TYPE at load time. Adding
16
+ # a new node type = adding one subclass (+ optional Attrs sub-model)
17
+ # and letting the registry walker pick it up (OCP).
18
+ #
19
+ # The TYPE_TO_CLASS and POLYMORPHIC constants are declared up-front
20
+ # (empty) because subclass `key_value` blocks reference them at class
21
+ # load time. The table is populated and frozen after every subclass
22
+ # is defined at the bottom of this file.
23
+ class Node < Lutaml::Model::Serializable
24
+ PM_TYPE = 'node'
25
+
26
+ TYPE_TO_CLASS = {}
27
+ POLYMORPHIC = { attribute: 'type', class_map: TYPE_TO_CLASS }.freeze
28
+
29
+ attribute :type, :string, default: -> { self.class::PM_TYPE }
30
+ attribute :content, Node, collection: true
31
+ attribute :marks, Mark, collection: true
32
+ # Parser metadata, single source of truth on the wire side too.
33
+ # Carried in memory so CoreModel → Mirror → CoreModel round-trips
34
+ # preserve the source location. Intentionally absent from every
35
+ # subclass `key_value` block: source_line is not part of the
36
+ # ProseMirror JSON contract — editor consumers don't need it, and
37
+ # serializing it would leak parser internals onto the wire.
38
+ attribute :source_line, :integer
39
+
40
+ key_value do
41
+ map 'type', to: :type, render_default: true
42
+ map 'content', to: :content, polymorphic: POLYMORPHIC
43
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
44
+ end
45
+
46
+ def text_content
47
+ return '' unless content
48
+
49
+ content.select { |c| c.is_a?(Node) }.map(&:text_content).join
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ module Coridoc
56
+ module Mirror
57
+ class Node
58
+ # ── Top-level ──
59
+
60
+ class Document < Node
61
+ PM_TYPE = 'doc'
62
+
63
+ class Attrs < Lutaml::Model::Serializable
64
+ attribute :title, :string
65
+ attribute :id, :string
66
+
67
+ key_value do
68
+ map 'title', to: :title
69
+ map 'id', to: :id
70
+ end
71
+ end
72
+
73
+ attribute :attrs, Attrs
74
+
75
+ key_value do
76
+ map 'type', to: :type, render_default: true
77
+ map 'attrs', to: :attrs
78
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
79
+ end
80
+ end
81
+
82
+ # ── Structural containers ──
83
+
84
+ class Section < Node
85
+ # JS SECTION_TYPES — all deserialize to Section. The type string
86
+ # is preserved as the type attribute on the instance.
87
+ PM_TYPE = 'section'
88
+ PM_ALIASES = %w[
89
+ clause annex content_section abstract foreword introduction
90
+ acknowledgements terms definitions references
91
+ ].freeze
92
+
93
+ class Attrs < Lutaml::Model::Serializable
94
+ attribute :title, :string
95
+ attribute :id, :string
96
+ attribute :level, :integer
97
+
98
+ key_value do
99
+ map 'title', to: :title
100
+ map 'id', to: :id
101
+ map 'level', to: :level
102
+ end
103
+ end
104
+
105
+ attribute :attrs, Attrs
106
+
107
+ key_value do
108
+ map 'type', to: :type, render_default: true
109
+ map 'attrs', to: :attrs
110
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
111
+ end
112
+ end
113
+
114
+ class Preamble < Node
115
+ PM_TYPE = 'preface'
116
+
117
+ key_value do
118
+ map 'type', to: :type, render_default: true
119
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
120
+ end
121
+ end
122
+
123
+ class Sections < Node
124
+ PM_TYPE = 'sections'
125
+
126
+ key_value do
127
+ map 'type', to: :type, render_default: true
128
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
129
+ end
130
+ end
131
+
132
+ class Header < Node
133
+ PM_TYPE = 'floating_title'
134
+
135
+ class Attrs < Lutaml::Model::Serializable
136
+ attribute :title, :string
137
+ attribute :level, :integer
138
+
139
+ key_value do
140
+ map 'title', to: :title
141
+ map 'level', to: :level
142
+ end
143
+ end
144
+
145
+ attribute :attrs, Attrs
146
+
147
+ key_value do
148
+ map 'type', to: :type, render_default: true
149
+ map 'attrs', to: :attrs
150
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
151
+ end
152
+ end
153
+
154
+ # ── Text (special: text at top level, not under attrs) ──
155
+
156
+ class Text < Node
157
+ PM_TYPE = 'text'
158
+
159
+ attribute :text, :string
160
+
161
+ key_value do
162
+ map 'type', to: :type, render_default: true
163
+ map 'text', to: :text
164
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
165
+ end
166
+
167
+ def text_content
168
+ text.to_s
169
+ end
170
+ end
171
+
172
+ # Raw inline passthrough — content the source format marked as "do
173
+ # not process, emit verbatim." Distinct from `text` so renderers can
174
+ # skip escaping without sniffing content for `<...>`. AsciiDoc's
175
+ # `+++raw+++` is the canonical producer.
176
+ class RawInline < Node
177
+ PM_TYPE = 'raw_inline'
178
+
179
+ attribute :text, :string
180
+
181
+ key_value do
182
+ map 'type', to: :type, render_default: true
183
+ map 'text', to: :text
184
+ end
185
+
186
+ def text_content
187
+ text.to_s
188
+ end
189
+ end
190
+
191
+ # ── Paragraph / block text ──
192
+
193
+ class Paragraph < Node
194
+ PM_TYPE = 'paragraph'
195
+
196
+ key_value do
197
+ map 'type', to: :type, render_default: true
198
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
199
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
200
+ end
201
+ end
202
+
203
+ class CodeBlock < Node
204
+ PM_TYPE = 'sourcecode'
205
+
206
+ class Attrs < Lutaml::Model::Serializable
207
+ attribute :language, :string
208
+ attribute :title, :string
209
+ attribute :passthrough, :boolean
210
+ attribute :text, :string
211
+
212
+ key_value do
213
+ map 'language', to: :language
214
+ map 'title', to: :title
215
+ map 'passthrough', to: :passthrough
216
+ map 'text', to: :text
217
+ end
218
+ end
219
+
220
+ attribute :attrs, Attrs
221
+
222
+ key_value do
223
+ map 'type', to: :type, render_default: true
224
+ map 'attrs', to: :attrs
225
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
226
+ end
227
+ end
228
+
229
+ # Literal block — preformatted text (`....` delimiter). Same shape
230
+ # as CodeBlock but distinguished on the wire so consumers can apply
231
+ # literal-vs-source rendering/styling.
232
+ class LiteralBlock < CodeBlock
233
+ PM_TYPE = 'literal'
234
+ end
235
+
236
+ # Pass block — raw passthrough content (`++++` delimiter). Same
237
+ # shape as CodeBlock; flagged via attrs.passthrough = true.
238
+ class PassBlock < CodeBlock
239
+ PM_TYPE = 'pass'
240
+ end
241
+
242
+ # STEM block — mathematical/scientific markup (`[stem|latexmath|
243
+ # asciimath]\n++++`). Carries a +language+ attr ('latex' default,
244
+ # 'asciimath' alternative).
245
+ class StemBlock < CodeBlock
246
+ PM_TYPE = 'stem'
247
+ end
248
+
249
+ class Blockquote < Node
250
+ PM_TYPE = 'quote'
251
+
252
+ class Attrs < Lutaml::Model::Serializable
253
+ attribute :attribution, :string
254
+
255
+ key_value do
256
+ map 'attribution', to: :attribution
257
+ end
258
+ end
259
+
260
+ attribute :attrs, Attrs
261
+
262
+ key_value do
263
+ map 'type', to: :type, render_default: true
264
+ map 'attrs', to: :attrs
265
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
266
+ end
267
+ end
268
+
269
+ class Example < Node
270
+ PM_TYPE = 'example'
271
+
272
+ class Attrs < Lutaml::Model::Serializable
273
+ attribute :title, :string
274
+ attribute :id, :string
275
+
276
+ key_value do
277
+ map 'title', to: :title
278
+ map 'id', to: :id
279
+ end
280
+ end
281
+
282
+ attribute :attrs, Attrs
283
+
284
+ key_value do
285
+ map 'type', to: :type, render_default: true
286
+ map 'attrs', to: :attrs
287
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
288
+ end
289
+ end
290
+
291
+ class Sidebar < Node
292
+ PM_TYPE = 'sidebar'
293
+
294
+ class Attrs < Lutaml::Model::Serializable
295
+ attribute :title, :string
296
+ attribute :id, :string
297
+
298
+ key_value do
299
+ map 'title', to: :title
300
+ map 'id', to: :id
301
+ end
302
+ end
303
+
304
+ attribute :attrs, Attrs
305
+
306
+ key_value do
307
+ map 'type', to: :type, render_default: true
308
+ map 'attrs', to: :attrs
309
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
310
+ end
311
+ end
312
+
313
+ # Abstract block — `[abstract]\n====\n...\n====` in AsciiDoc. Carries
314
+ # the same shape as Sidebar/Example but a distinct wire type so the
315
+ # block-level construct does not collide with the section-level
316
+ # `abstract` (one of Section's PM_ALIASES). The block preserves its
317
+ # block identity through round-trip; renderers that want a section
318
+ # view should look at SectionElement-style sources instead.
319
+ class Abstract < Node
320
+ PM_TYPE = 'abstract_block'
321
+
322
+ class Attrs < Lutaml::Model::Serializable
323
+ attribute :title, :string
324
+ attribute :id, :string
325
+
326
+ key_value do
327
+ map 'title', to: :title
328
+ map 'id', to: :id
329
+ end
330
+ end
331
+
332
+ attribute :attrs, Attrs
333
+
334
+ key_value do
335
+ map 'type', to: :type, render_default: true
336
+ map 'attrs', to: :attrs
337
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
338
+ end
339
+ end
340
+
341
+ # Partintro block — `[partintro]\n====\n...\n====` in AsciiDoc, used
342
+ # to introduce a "part" in multi-part documents. Distinct wire type
343
+ # for the same reason as Abstract (no collision with potential
344
+ # section-level uses of "partintro").
345
+ class Partintro < Node
346
+ PM_TYPE = 'partintro_block'
347
+
348
+ class Attrs < Lutaml::Model::Serializable
349
+ attribute :title, :string
350
+ attribute :id, :string
351
+
352
+ key_value do
353
+ map 'title', to: :title
354
+ map 'id', to: :id
355
+ end
356
+ end
357
+
358
+ attribute :attrs, Attrs
359
+
360
+ key_value do
361
+ map 'type', to: :type, render_default: true
362
+ map 'attrs', to: :attrs
363
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
364
+ end
365
+ end
366
+
367
+ class OpenBlock < Node
368
+ PM_TYPE = 'open_block'
369
+
370
+ key_value do
371
+ map 'type', to: :type, render_default: true
372
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
373
+ end
374
+ end
375
+
376
+ class Verse < Node
377
+ PM_TYPE = 'verse'
378
+
379
+ class Attrs < Lutaml::Model::Serializable
380
+ attribute :attribution, :string
381
+
382
+ key_value do
383
+ map 'attribution', to: :attribution
384
+ end
385
+ end
386
+
387
+ attribute :attrs, Attrs
388
+
389
+ key_value do
390
+ map 'type', to: :type, render_default: true
391
+ map 'attrs', to: :attrs
392
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
393
+ end
394
+ end
395
+
396
+ class HorizontalRule < Node
397
+ PM_TYPE = 'horizontal_rule'
398
+ end
399
+
400
+ class ThematicBreak < Node
401
+ PM_TYPE = 'thematic_break'
402
+ end
403
+
404
+ class SoftBreak < Node
405
+ PM_TYPE = 'soft_break'
406
+ end
407
+
408
+ # Hard line break — author-requested explicit break (`foo +\nbar` in
409
+ # AsciiDoc, `<br>` semantics in HTML). Distinct from SoftBreak so
410
+ # downstream renderers can map it to `<br>` rather than collapsing
411
+ # the break into a soft newline-or-space convention. ProseMirror's
412
+ # schema uses `hard_break` for the same purpose.
413
+ class HardBreak < Node
414
+ PM_TYPE = 'hard_break'
415
+ end
416
+
417
+ # ── Admonition (NOTE, TIP, WARNING, CAUTION, IMPORTANT) ──
418
+ #
419
+ # The Ruby attribute name is `admonition_type` (kept distinct from
420
+ # Node's built-in `type` discriminator). The wire attribute name is
421
+ # `type` per the @metanorma/mirror JS contract. The rename happens
422
+ # via a `map` declaration — no hand-rolled to_h/from_h.
423
+
424
+ class Admonition < Node
425
+ PM_TYPE = 'admonition'
426
+
427
+ class Attrs < Lutaml::Model::Serializable
428
+ attribute :admonition_type, :string
429
+ attribute :title, :string
430
+ attribute :label, :string
431
+ attribute :id, :string
432
+
433
+ key_value do
434
+ map 'type', to: :admonition_type # RENAME: Ruby ≠ wire
435
+ map 'title', to: :title
436
+ map 'label', to: :label
437
+ map 'id', to: :id
438
+ end
439
+ end
440
+
441
+ attribute :attrs, Attrs
442
+
443
+ key_value do
444
+ map 'type', to: :type, render_default: true
445
+ map 'attrs', to: :attrs
446
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
447
+ end
448
+ end
449
+
450
+ # ── Lists ──
451
+
452
+ class BulletList < Node
453
+ PM_TYPE = 'bullet_list'
454
+
455
+ class Attrs < Lutaml::Model::Serializable
456
+ attribute :id, :string
457
+ attribute :start, :integer
458
+
459
+ key_value do
460
+ map 'id', to: :id
461
+ map 'start', to: :start
462
+ end
463
+ end
464
+
465
+ attribute :attrs, Attrs
466
+
467
+ key_value do
468
+ map 'type', to: :type, render_default: true
469
+ map 'attrs', to: :attrs
470
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
471
+ end
472
+ end
473
+
474
+ class OrderedList < Node
475
+ PM_TYPE = 'ordered_list'
476
+
477
+ class Attrs < Lutaml::Model::Serializable
478
+ attribute :id, :string
479
+ attribute :start, :integer
480
+
481
+ key_value do
482
+ map 'id', to: :id
483
+ map 'start', to: :start
484
+ end
485
+ end
486
+
487
+ attribute :attrs, Attrs
488
+
489
+ key_value do
490
+ map 'type', to: :type, render_default: true
491
+ map 'attrs', to: :attrs
492
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
493
+ end
494
+ end
495
+
496
+ class ListItem < Node
497
+ PM_TYPE = 'list_item'
498
+
499
+ class Attrs < Lutaml::Model::Serializable
500
+ attribute :id, :string
501
+
502
+ key_value do
503
+ map 'id', to: :id
504
+ end
505
+ end
506
+
507
+ attribute :attrs, Attrs
508
+
509
+ key_value do
510
+ map 'type', to: :type, render_default: true
511
+ map 'attrs', to: :attrs
512
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
513
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
514
+ end
515
+ end
516
+
517
+ class DefinitionList < Node
518
+ PM_TYPE = 'dl'
519
+
520
+ class Attrs < Lutaml::Model::Serializable
521
+ attribute :id, :string
522
+
523
+ key_value do
524
+ map 'id', to: :id
525
+ end
526
+ end
527
+
528
+ attribute :attrs, Attrs
529
+
530
+ key_value do
531
+ map 'type', to: :type, render_default: true
532
+ map 'attrs', to: :attrs
533
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
534
+ end
535
+ end
536
+
537
+ class DefinitionTerm < Node
538
+ PM_TYPE = 'dt'
539
+
540
+ key_value do
541
+ map 'type', to: :type, render_default: true
542
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
543
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
544
+ end
545
+ end
546
+
547
+ class DefinitionDescription < Node
548
+ PM_TYPE = 'dd'
549
+
550
+ key_value do
551
+ map 'type', to: :type, render_default: true
552
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
553
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
554
+ end
555
+ end
556
+
557
+ # ── Media ──
558
+
559
+ class Image < Node
560
+ PM_TYPE = 'image'
561
+
562
+ class Attrs < Lutaml::Model::Serializable
563
+ attribute :src, :string
564
+ attribute :alt, :string
565
+ attribute :title, :string
566
+ attribute :caption, :string
567
+ attribute :width, :string
568
+ attribute :height, :string
569
+ attribute :role, :string
570
+ attribute :inline, :boolean
571
+
572
+ key_value do
573
+ map 'src', to: :src
574
+ map 'alt', to: :alt
575
+ map 'title', to: :title
576
+ map 'caption', to: :caption
577
+ map 'width', to: :width
578
+ map 'height', to: :height
579
+ map 'role', to: :role
580
+ map 'inline', to: :inline
581
+ end
582
+ end
583
+
584
+ attribute :attrs, Attrs
585
+
586
+ key_value do
587
+ map 'type', to: :type, render_default: true
588
+ map 'attrs', to: :attrs
589
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
590
+ end
591
+ end
592
+
593
+ # JS @metanorma/mirror figure: wraps Image + optional Caption.
594
+ class Figure < Node
595
+ PM_TYPE = 'figure'
596
+
597
+ class Attrs < Lutaml::Model::Serializable
598
+ attribute :id, :string
599
+ attribute :title, :string
600
+
601
+ key_value do
602
+ map 'id', to: :id
603
+ map 'title', to: :title
604
+ end
605
+ end
606
+
607
+ attribute :attrs, Attrs
608
+
609
+ key_value do
610
+ map 'type', to: :type, render_default: true
611
+ map 'attrs', to: :attrs
612
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
613
+ end
614
+ end
615
+
616
+ class Caption < Node
617
+ PM_TYPE = 'caption'
618
+
619
+ key_value do
620
+ map 'type', to: :type, render_default: true
621
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
622
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
623
+ end
624
+ end
625
+
626
+ # Include directive node — a text-graph edge pointing at another file.
627
+ # Graph mode emits this; flat mode (ResolveIncludes) replaces it with
628
+ # the included subtree before serialization.
629
+ class Include < Node
630
+ PM_TYPE = 'include'
631
+
632
+ class Attrs < Lutaml::Model::Serializable
633
+ attribute :target, :string
634
+ attribute :tags, :string, collection: true
635
+ attribute :tags_wildcard, :boolean
636
+ attribute :tags_inverted, :boolean
637
+ attribute :lines, :string
638
+ attribute :leveloffset, :string
639
+ attribute :indent, :integer
640
+ attribute :file_encoding, :string
641
+ attribute :raw_options, :string
642
+
643
+ key_value do
644
+ map 'target', to: :target
645
+ map 'tags', to: :tags
646
+ map 'tags_wildcard', to: :tags_wildcard
647
+ map 'tags_inverted', to: :tags_inverted
648
+ map 'lines', to: :lines
649
+ map 'leveloffset', to: :leveloffset
650
+ map 'indent', to: :indent
651
+ map 'encoding', to: :file_encoding
652
+ map 'raw_options', to: :raw_options
653
+ end
654
+ end
655
+
656
+ attribute :attrs, Attrs
657
+
658
+ key_value do
659
+ map 'type', to: :type, render_default: true
660
+ map 'attrs', to: :attrs
661
+ end
662
+ end
663
+
664
+ # ── Tables ──
665
+
666
+ class Table < Node
667
+ PM_TYPE = 'table'
668
+
669
+ class Attrs < Lutaml::Model::Serializable
670
+ attribute :title, :string
671
+ attribute :id, :string
672
+ attribute :width, :string
673
+
674
+ key_value do
675
+ map 'title', to: :title
676
+ map 'id', to: :id
677
+ map 'width', to: :width
678
+ end
679
+ end
680
+
681
+ attribute :attrs, Attrs
682
+
683
+ key_value do
684
+ map 'type', to: :type, render_default: true
685
+ map 'attrs', to: :attrs
686
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
687
+ end
688
+ end
689
+
690
+ class TableHead < Node
691
+ PM_TYPE = 'table_head'
692
+
693
+ key_value do
694
+ map 'type', to: :type, render_default: true
695
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
696
+ end
697
+ end
698
+
699
+ class TableBody < Node
700
+ PM_TYPE = 'table_body'
701
+
702
+ key_value do
703
+ map 'type', to: :type, render_default: true
704
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
705
+ end
706
+ end
707
+
708
+ class TableRow < Node
709
+ PM_TYPE = 'table_row'
710
+
711
+ key_value do
712
+ map 'type', to: :type, render_default: true
713
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
714
+ end
715
+ end
716
+
717
+ class TableCell < Node
718
+ PM_TYPE = 'table_cell'
719
+
720
+ class Attrs < Lutaml::Model::Serializable
721
+ attribute :colspan, :integer
722
+ attribute :rowspan, :integer
723
+ attribute :alignment, :string
724
+ attribute :header, :boolean
725
+
726
+ key_value do
727
+ map 'colspan', to: :colspan
728
+ map 'rowspan', to: :rowspan
729
+ map 'alignment', to: :alignment
730
+ map 'header', to: :header
731
+ end
732
+ end
733
+
734
+ attribute :attrs, Attrs
735
+
736
+ key_value do
737
+ map 'type', to: :type, render_default: true
738
+ map 'attrs', to: :attrs
739
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
740
+ map 'marks', to: :marks, polymorphic: Mark::POLYMORPHIC
741
+ end
742
+ end
743
+
744
+ # ── Bibliography ──
745
+
746
+ class Bibliography < Node
747
+ PM_TYPE = 'bibliography'
748
+
749
+ class Attrs < Lutaml::Model::Serializable
750
+ attribute :title, :string
751
+ attribute :id, :string
752
+ attribute :level, :integer
753
+
754
+ key_value do
755
+ map 'title', to: :title
756
+ map 'id', to: :id
757
+ map 'level', to: :level
758
+ end
759
+ end
760
+
761
+ attribute :attrs, Attrs
762
+
763
+ key_value do
764
+ map 'type', to: :type, render_default: true
765
+ map 'attrs', to: :attrs
766
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
767
+ end
768
+ end
769
+
770
+ class BibliographyEntry < Node
771
+ PM_TYPE = 'biblio_entry'
772
+
773
+ class Attrs < Lutaml::Model::Serializable
774
+ attribute :anchor_name, :string
775
+ attribute :document_id, :string
776
+ attribute :url, :string
777
+
778
+ key_value do
779
+ map 'anchor_name', to: :anchor_name
780
+ map 'document_id', to: :document_id
781
+ map 'url', to: :url
782
+ end
783
+ end
784
+
785
+ attribute :attrs, Attrs
786
+
787
+ key_value do
788
+ map 'type', to: :type, render_default: true
789
+ map 'attrs', to: :attrs
790
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
791
+ end
792
+ end
793
+
794
+ # ── Footnotes ──
795
+
796
+ class Footnotes < Node
797
+ PM_TYPE = 'footnotes'
798
+
799
+ key_value do
800
+ map 'type', to: :type, render_default: true
801
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
802
+ end
803
+ end
804
+
805
+ class FootnoteMarker < Node
806
+ PM_TYPE = 'footnote_marker'
807
+
808
+ class Attrs < Lutaml::Model::Serializable
809
+ attribute :id, :string
810
+ attribute :ref_id, :string
811
+ attribute :number, :integer
812
+
813
+ key_value do
814
+ map 'id', to: :id
815
+ map 'ref_id', to: :ref_id
816
+ map 'number', to: :number
817
+ end
818
+ end
819
+
820
+ attribute :attrs, Attrs
821
+
822
+ key_value do
823
+ map 'type', to: :type, render_default: true
824
+ map 'attrs', to: :attrs
825
+ end
826
+ end
827
+
828
+ class FootnoteEntry < Node
829
+ PM_TYPE = 'footnote_entry'
830
+
831
+ class Attrs < Lutaml::Model::Serializable
832
+ attribute :id, :string
833
+ attribute :ref_id, :string
834
+ attribute :number, :integer
835
+
836
+ key_value do
837
+ map 'id', to: :id
838
+ map 'ref_id', to: :ref_id
839
+ map 'number', to: :number
840
+ end
841
+ end
842
+
843
+ attribute :attrs, Attrs
844
+
845
+ key_value do
846
+ map 'type', to: :type, render_default: true
847
+ map 'attrs', to: :attrs
848
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
849
+ end
850
+ end
851
+
852
+ # ── TOC ──
853
+
854
+ class Toc < Node
855
+ PM_TYPE = 'toc'
856
+
857
+ class Attrs < Lutaml::Model::Serializable
858
+ attribute :title, :string
859
+
860
+ key_value do
861
+ map 'title', to: :title
862
+ end
863
+ end
864
+
865
+ attribute :attrs, Attrs
866
+
867
+ key_value do
868
+ map 'type', to: :type, render_default: true
869
+ map 'attrs', to: :attrs
870
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
871
+ end
872
+ end
873
+
874
+ class TocEntry < Node
875
+ PM_TYPE = 'toc_entry'
876
+
877
+ class Attrs < Lutaml::Model::Serializable
878
+ attribute :id, :string
879
+ attribute :title, :string
880
+ attribute :level, :integer
881
+
882
+ key_value do
883
+ map 'id', to: :id
884
+ map 'title', to: :title
885
+ map 'level', to: :level
886
+ end
887
+ end
888
+
889
+ attribute :attrs, Attrs
890
+
891
+ key_value do
892
+ map 'type', to: :type, render_default: true
893
+ map 'attrs', to: :attrs
894
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
895
+ end
896
+ end
897
+
898
+ # ── Generic (catch-all) ──
899
+
900
+ class GenericBlock < Node
901
+ PM_TYPE = 'generic_block'
902
+
903
+ class Attrs < Lutaml::Model::Serializable
904
+ attribute :semantic_type, :string
905
+ attribute :title, :string
906
+ attribute :id, :string
907
+
908
+ key_value do
909
+ map 'semantic_type', to: :semantic_type
910
+ map 'title', to: :title
911
+ map 'id', to: :id
912
+ end
913
+ end
914
+
915
+ attribute :attrs, Attrs
916
+
917
+ key_value do
918
+ map 'type', to: :type, render_default: true
919
+ map 'attrs', to: :attrs
920
+ map 'content', to: :content, polymorphic: Node::POLYMORPHIC
921
+ end
922
+ end
923
+
924
+ # ── Frontmatter (typed tree — no hashes) ──
925
+
926
+ class FrontmatterValue < Lutaml::Model::Serializable; end
927
+
928
+ class FrontmatterEntry < Lutaml::Model::Serializable
929
+ attribute :key, :string
930
+ attribute :value, FrontmatterValue
931
+
932
+ key_value do
933
+ map 'key', to: :key, render_default: true
934
+ map 'value', to: :value
935
+ end
936
+ end
937
+
938
+ class FrontmatterValue
939
+ attribute :value_type, :string
940
+ attribute :string_value, :string
941
+ attribute :integer_value, :integer
942
+ attribute :float_value, :float
943
+ attribute :boolean_value, :boolean
944
+ attribute :date_value, :date
945
+ attribute :datetime_value, :date_time
946
+ attribute :symbol_value, :string
947
+ attribute :items, FrontmatterValue, collection: true
948
+ attribute :entries, FrontmatterEntry, collection: true
949
+
950
+ key_value do
951
+ map 'value_type', to: :value_type, render_default: true
952
+ map 'string_value', to: :string_value
953
+ map 'integer_value', to: :integer_value
954
+ map 'float_value', to: :float_value
955
+ map 'boolean_value', to: :boolean_value
956
+ map 'date_value', to: :date_value
957
+ map 'datetime_value', to: :datetime_value
958
+ map 'symbol_value', to: :symbol_value
959
+ map 'items', to: :items
960
+ map 'entries', to: :entries
961
+ end
962
+ end
963
+
964
+ class Frontmatter < Node
965
+ PM_TYPE = 'frontmatter'
966
+
967
+ class Attrs < Lutaml::Model::Serializable
968
+ attribute :schema, :string
969
+ attribute :entries, FrontmatterEntry, collection: true
970
+
971
+ key_value do
972
+ map 'schema', to: :schema
973
+ map 'entries', to: :entries
974
+ end
975
+ end
976
+
977
+ attribute :attrs, Attrs
978
+
979
+ key_value do
980
+ map 'type', to: :type, render_default: true
981
+ map 'attrs', to: :attrs
982
+ end
983
+ end
984
+ end
985
+ end
986
+ end
987
+
988
+ module Coridoc
989
+ module Mirror
990
+ class Node
991
+ # Populate the polymorphic class map now that every subclass is
992
+ # defined. Maps each PM_TYPE wire string to its Ruby class name.
993
+ # Section's PM_ALIASES are added on top so all JS SECTION_TYPES
994
+ # route to Section on reverse parse.
995
+ Node.constants.each do |name|
996
+ k = Node.const_get(name)
997
+ next unless k.is_a?(Class) && k < Node && k::PM_TYPE != 'node'
998
+
999
+ TYPE_TO_CLASS[k::PM_TYPE] = k.name
1000
+ Array(k::PM_ALIASES).each { |a| TYPE_TO_CLASS[a] = k.name } if k.const_defined?(:PM_ALIASES, false)
1001
+ end
1002
+ TYPE_TO_CLASS.freeze
1003
+ end
1004
+ end
1005
+ end