markplus_core 0.2.0

Universal Markdown → AST (JSON) compiler for the MarkPlus ecosystem
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://markplus.dev/schema/v1/markplus-ast.schema.json",
  "title": "MarkPlus AST v1",
  "description": "Schema for the MarkPlus AST produced by markplus_core::parse_document() and parse_body(). The 't' field is the node type discriminant throughout the tree.",

  "$defs": {

    "AttrsMap": {
      "description": "Key-value attribute pairs. Values are strings or booleans (bare flags become true).",
      "type": "object",
      "additionalProperties": {
        "oneOf": [
          { "type": "string" },
          { "type": "boolean" }
        ]
      }
    },

    "InlineNode": {
      "description": "Any node that appears inside a block's 'children' array.",
      "oneOf": [
        { "$ref": "#/$defs/TextNode" },
        { "$ref": "#/$defs/EmNode" },
        { "$ref": "#/$defs/StrongNode" },
        { "$ref": "#/$defs/DelNode" },
        { "$ref": "#/$defs/SupNode" },
        { "$ref": "#/$defs/SubNode" },
        { "$ref": "#/$defs/CodeSpanNode" },
        { "$ref": "#/$defs/MathInlineNode" },
        { "$ref": "#/$defs/LinkNode" },
        { "$ref": "#/$defs/ImageNode" },
        { "$ref": "#/$defs/WidgetNode" },
        { "$ref": "#/$defs/FootnoteRefNode" },
        { "$ref": "#/$defs/TaskMarkerNode" },
        { "$ref": "#/$defs/SoftBreakNode" },
        { "$ref": "#/$defs/HardBreakNode" },
        { "$ref": "#/$defs/RawHtmlNode" }
      ]
    },

    "BlockNode": {
      "description": "Any node that appears at the top level of the 'ast' array or nested inside a container block.",
      "oneOf": [
        { "$ref": "#/$defs/HeadingNode" },
        { "$ref": "#/$defs/ParagraphNode" },
        { "$ref": "#/$defs/FencedNode" },
        { "$ref": "#/$defs/BlockquoteNode" },
        { "$ref": "#/$defs/ListNode" },
        { "$ref": "#/$defs/TableNode" },
        { "$ref": "#/$defs/DefinitionListNode" },
        { "$ref": "#/$defs/HrNode" },
        { "$ref": "#/$defs/HtmlBlockNode" },
        { "$ref": "#/$defs/FootnoteDefNode" },
        { "$ref": "#/$defs/MathBlockNode" },
        { "$ref": "#/$defs/RawHtmlNode" }
      ]
    },

    "CellNode": {
      "description": "A table cell — internal node, only appears inside table 'headers' and 'rows'.",
      "type": "object",
      "properties": {
        "t": { "const": "_cell" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "DefTitleNode": {
      "description": "A definition list title term.",
      "type": "object",
      "properties": {
        "t": { "const": "_def_title" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "DefBodyNode": {
      "description": "A definition list definition body.",
      "type": "object",
      "properties": {
        "t": { "const": "_def_body" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "HeadingNode": {
      "description": "A heading (# to ######). Optional 'id', 'classes', and 'attrs' from heading attribute syntax.",
      "type": "object",
      "properties": {
        "t": { "const": "heading" },
        "level": {
          "type": "integer",
          "minimum": 1,
          "maximum": 6,
          "description": "Heading depth: 1 = h1, 6 = h6."
        },
        "id": {
          "type": "string",
          "description": "Optional heading ID from '{ #my-id }' syntax."
        },
        "classes": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Optional CSS classes from '{ .class1 .class2 }' syntax."
        },
        "attrs": {
          "$ref": "#/$defs/AttrsMap",
          "description": "Optional custom attributes from '{ key=val }' syntax."
        },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" },
          "description": "Inline content of the heading."
        }
      },
      "required": ["t", "level", "children"],
      "additionalProperties": false
    },

    "ParagraphNode": {
      "description": "A paragraph of inline content.",
      "type": "object",
      "properties": {
        "t": { "const": "paragraph" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "FencedNode": {
      "description": "A fenced or indented code block. All fenced blocks share this shape — the renderer decides whether 'name' means syntax highlight, diagram, or plugin.",
      "type": "object",
      "properties": {
        "t": { "const": "fenced" },
        "name": {
          "type": "string",
          "description": "The info string first token (e.g. 'python', 'mermaid', 'simby'). Empty string for indented blocks or unlabelled fences."
        },
        "attrs": {
          "$ref": "#/$defs/AttrsMap",
          "description": "Key-value attributes parsed from the remainder of the info string. Absent when empty."
        },
        "raw": {
          "type": "string",
          "description": "Raw block content with trailing whitespace trimmed."
        }
      },
      "required": ["t", "name", "raw"],
      "additionalProperties": false
    },

    "BlockquoteNode": {
      "description": "A blockquote (>) or GFM alert (> [!NOTE], > [!WARNING], etc.).",
      "type": "object",
      "properties": {
        "t": { "const": "blockquote" },
        "kind": {
          "type": "string",
          "enum": ["note", "tip", "important", "warning", "caution"],
          "description": "GFM alert kind. Absent for regular blockquotes."
        },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/BlockNode" },
          "description": "Block-level content of the quote."
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "ListItemNode": {
      "description": "A single list item. In loose lists, children are block-level nodes (paragraphs, nested lists). In tight lists, children are inline nodes directly (no wrapping paragraph).",
      "type": "object",
      "properties": {
        "t": { "const": "list_item" },
        "children": {
          "type": "array",
          "items": {
            "oneOf": [
              { "$ref": "#/$defs/BlockNode" },
              { "$ref": "#/$defs/InlineNode" }
            ]
          }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "ListNode": {
      "description": "An ordered or unordered list.",
      "type": "object",
      "properties": {
        "t": { "const": "list" },
        "ordered": {
          "type": "boolean",
          "description": "true for ordered (1. 2. 3.), false for unordered (- *)."
        },
        "start": {
          "type": "integer",
          "description": "Starting number for ordered lists. Absent for unordered lists."
        },
        "items": {
          "type": "array",
          "items": { "$ref": "#/$defs/ListItemNode" }
        }
      },
      "required": ["t", "ordered", "items"],
      "additionalProperties": false
    },

    "TableNode": {
      "description": "A GFM table.",
      "type": "object",
      "properties": {
        "t": { "const": "table" },
        "align": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["left", "right", "center", "none"]
          },
          "description": "Column alignment, one entry per column."
        },
        "headers": {
          "type": "array",
          "items": { "$ref": "#/$defs/CellNode" },
          "description": "Header row cells."
        },
        "rows": {
          "type": "array",
          "items": {
            "type": "array",
            "items": { "$ref": "#/$defs/CellNode" }
          },
          "description": "Body rows, each row is an array of cells."
        }
      },
      "required": ["t", "align", "headers", "rows"],
      "additionalProperties": false
    },

    "DefinitionListNode": {
      "description": "A GFM definition list (term + one or more definitions).",
      "type": "object",
      "properties": {
        "t": { "const": "definition_list" },
        "items": {
          "type": "array",
          "items": {
            "oneOf": [
              { "$ref": "#/$defs/DefTitleNode" },
              { "$ref": "#/$defs/DefBodyNode" }
            ]
          },
          "description": "Alternating title and body nodes."
        }
      },
      "required": ["t", "items"],
      "additionalProperties": false
    },

    "HrNode": {
      "description": "A thematic break (---, ***, ___).",
      "type": "object",
      "properties": {
        "t": { "const": "hr" }
      },
      "required": ["t"],
      "additionalProperties": false
    },

    "HtmlBlockNode": {
      "description": "A raw HTML block element.",
      "type": "object",
      "properties": {
        "t": { "const": "html_block" },
        "html": {
          "type": "string",
          "description": "Raw HTML string including newlines."
        }
      },
      "required": ["t", "html"],
      "additionalProperties": false
    },

    "FootnoteDefNode": {
      "description": "A footnote definition ([^label]: body).",
      "type": "object",
      "properties": {
        "t": { "const": "footnote_def" },
        "label": {
          "type": "string",
          "description": "The footnote label (the part inside [^...])."
        },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/BlockNode" }
        }
      },
      "required": ["t", "label", "children"],
      "additionalProperties": false
    },

    "MathBlockNode": {
      "description": "A display math block ($$...$$).",
      "type": "object",
      "properties": {
        "t": { "const": "math_block" },
        "src": {
          "type": "string",
          "description": "Raw LaTeX source, as emitted by the parser."
        }
      },
      "required": ["t", "src"],
      "additionalProperties": false
    },

    "TextNode": {
      "description": "Plain text content.",
      "type": "object",
      "properties": {
        "t": { "const": "text" },
        "text": { "type": "string" }
      },
      "required": ["t", "text"],
      "additionalProperties": false
    },

    "EmNode": {
      "description": "Emphasis (*text* or _text_).",
      "type": "object",
      "properties": {
        "t": { "const": "em" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "StrongNode": {
      "description": "Strong emphasis (**text** or __text__).",
      "type": "object",
      "properties": {
        "t": { "const": "strong" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "DelNode": {
      "description": "Strikethrough (~~text~~).",
      "type": "object",
      "properties": {
        "t": { "const": "del" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "SupNode": {
      "description": "Superscript (^text^).",
      "type": "object",
      "properties": {
        "t": { "const": "sup" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "SubNode": {
      "description": "Subscript (~text~).",
      "type": "object",
      "properties": {
        "t": { "const": "sub" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" }
        }
      },
      "required": ["t", "children"],
      "additionalProperties": false
    },

    "CodeSpanNode": {
      "description": "An inline code span (`code`).",
      "type": "object",
      "properties": {
        "t": { "const": "code_span" },
        "text": {
          "type": "string",
          "description": "The code content, backticks stripped."
        }
      },
      "required": ["t", "text"],
      "additionalProperties": false
    },

    "MathInlineNode": {
      "description": "Inline math ($formula$).",
      "type": "object",
      "properties": {
        "t": { "const": "math_inline" },
        "src": {
          "type": "string",
          "description": "Raw LaTeX source."
        }
      },
      "required": ["t", "src"],
      "additionalProperties": false
    },

    "LinkNode": {
      "description": "An inline hyperlink [text](url). Optional '{attrs}' block absorbed into 'attrs'.",
      "type": "object",
      "properties": {
        "t": { "const": "link" },
        "href": {
          "type": "string",
          "description": "Destination URL."
        },
        "title": {
          "type": "string",
          "description": "Optional link title (from '\"title\"' in the URL parens). Empty string when absent."
        },
        "attrs": {
          "$ref": "#/$defs/AttrsMap",
          "description": "Extra attributes from trailing '{key=val}' block. Absent when no block given."
        },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" },
          "description": "The link label inline content."
        }
      },
      "required": ["t", "href", "title", "children"],
      "additionalProperties": false
    },

    "ImageNode": {
      "description": "An inline image ![alt](src). Optional '{attrs}' block absorbed into 'attrs'.",
      "type": "object",
      "properties": {
        "t": { "const": "image" },
        "src": {
          "type": "string",
          "description": "Image source URL."
        },
        "title": {
          "type": "string",
          "description": "Optional image title. Empty string when absent."
        },
        "attrs": {
          "$ref": "#/$defs/AttrsMap",
          "description": "Extra attributes from trailing '{key=val}' block. Absent when no block given."
        },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/InlineNode" },
          "description": "Alt text inline content."
        }
      },
      "required": ["t", "src", "title", "children"],
      "additionalProperties": false
    },

    "WidgetNode": {
      "description": "A MarkPlus inline extension widget: :[text]{name key=value ...}",
      "type": "object",
      "properties": {
        "t": { "const": "widget" },
        "name": {
          "type": "string",
          "description": "Widget type identifier (first token in the brace block)."
        },
        "text": {
          "type": "string",
          "description": "The visible text content (inside the square brackets)."
        },
        "attrs": {
          "$ref": "#/$defs/AttrsMap",
          "description": "Widget parameters parsed from the brace block."
        }
      },
      "required": ["t", "name", "text", "attrs"],
      "additionalProperties": false
    },

    "FootnoteRefNode": {
      "description": "A footnote reference ([^label]).",
      "type": "object",
      "properties": {
        "t": { "const": "footnote_ref" },
        "label": {
          "type": "string",
          "description": "The footnote label being referenced."
        }
      },
      "required": ["t", "label"],
      "additionalProperties": false
    },

    "TaskMarkerNode": {
      "description": "A task list checkbox marker ([ ] or [x]). Always the first inline child of a task list item paragraph.",
      "type": "object",
      "properties": {
        "t": { "const": "task_marker" },
        "checked": {
          "type": "boolean",
          "description": "true when the box is checked ([x])."
        }
      },
      "required": ["t", "checked"],
      "additionalProperties": false
    },

    "SoftBreakNode": {
      "description": "A soft line break (single newline without trailing spaces).",
      "type": "object",
      "properties": {
        "t": { "const": "soft_break" }
      },
      "required": ["t"],
      "additionalProperties": false
    },

    "HardBreakNode": {
      "description": "A hard line break (two trailing spaces or backslash before newline).",
      "type": "object",
      "properties": {
        "t": { "const": "hard_break" }
      },
      "required": ["t"],
      "additionalProperties": false
    },

    "RawHtmlNode": {
      "description": "A raw HTML node. Appears as a block when at document root, inline otherwise.",
      "type": "object",
      "properties": {
        "t": { "const": "raw_html" },
        "html": {
          "type": "string",
          "description": "The raw HTML string."
        }
      },
      "required": ["t", "html"],
      "additionalProperties": false
    }
  },

  "type": "object",
  "description": "The top-level MarkPlus site asset (note.json wire format).",
  "properties": {
    "schema": {
      "type": "integer",
      "const": 1,
      "description": "AST schema version. Renderers must reject assets with an unexpected version."
    },
    "meta": {
      "description": "Parsed YAML frontmatter as a JSON object. null/absent when the document has no frontmatter.",
      "oneOf": [
        { "type": "object" },
        { "type": "null" }
      ]
    },
    "ast": {
      "type": "array",
      "items": { "$ref": "#/$defs/BlockNode" },
      "description": "Ordered list of top-level block nodes representing the document body."
    }
  },
  "required": ["schema", "ast"],
  "additionalProperties": false
}