@leo-studio/leo-markup 0.0.0-stage → 0.1.1
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.
- package/LICENSE +9 -0
- package/README.md +18 -2
- package/dist/agent-support.d.ts +10 -0
- package/dist/agent-support.d.ts.map +1 -0
- package/dist/agent-support.js +27 -0
- package/dist/agent-support.js.map +1 -0
- package/dist/ast-json.d.ts +104 -0
- package/dist/ast-json.d.ts.map +1 -0
- package/dist/ast-json.js +203 -0
- package/dist/ast-json.js.map +1 -0
- package/dist/authoring-lints.d.ts +79 -0
- package/dist/authoring-lints.d.ts.map +1 -0
- package/dist/authoring-lints.js +145 -0
- package/dist/authoring-lints.js.map +1 -0
- package/dist/block-inline.d.ts +74 -0
- package/dist/block-inline.d.ts.map +1 -0
- package/dist/block-inline.js +171 -0
- package/dist/block-inline.js.map +1 -0
- package/dist/fence.d.ts +14 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +55 -0
- package/dist/fence.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/parity.d.ts +44 -0
- package/dist/parity.d.ts.map +1 -0
- package/dist/parity.js +80 -0
- package/dist/parity.js.map +1 -0
- package/dist/product-spec.d.ts +164 -0
- package/dist/product-spec.d.ts.map +1 -0
- package/dist/product-spec.js +240 -0
- package/dist/product-spec.js.map +1 -0
- package/dist/registry.d.ts +53 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +483 -0
- package/dist/registry.js.map +1 -0
- package/dist/scanner.d.ts +40 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +291 -0
- package/dist/scanner.js.map +1 -0
- package/dist/schema/leo-markup-ast.schema.json +217 -0
- package/dist/schema/vocabulary.json +382 -0
- package/dist/tree-text.d.ts +16 -0
- package/dist/tree-text.d.ts.map +1 -0
- package/dist/tree-text.js +320 -0
- package/dist/tree-text.js.map +1 -0
- package/dist/types.d.ts +211 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +34 -0
- package/dist/types.js.map +1 -0
- package/dist/vocabulary.d.ts +293 -0
- package/dist/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary.js +226 -0
- package/dist/vocabulary.js.map +1 -0
- package/package.json +43 -3
package/dist/scanner.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `<leo.*>` island scanner (ADR-D-01KVQHTWH8MQ).
|
|
3
|
+
*
|
|
4
|
+
* A single-pass, quote-aware, balanced-nesting scanner that finds `<leo.*>`
|
|
5
|
+
* islands in a source string and returns the document as an ordered list of
|
|
6
|
+
* spans — prose passes through VERBATIM; each island is extracted with its raw
|
|
7
|
+
* attrs and balanced body; a `<leo.` opener that cannot be parsed DEGRADES to a
|
|
8
|
+
* malformed span (preserved as text) rather than stalling or dropping the rest.
|
|
9
|
+
*
|
|
10
|
+
* It is the SOLE resolution path on both surfaces (terminal + web), so the two
|
|
11
|
+
* cannot diverge. It claims ONLY `<leo.*>` (the namespace allow-list); every
|
|
12
|
+
* other angle bracket — `<div>`, `<Callout>`, autolinks, code spans, `a < b` —
|
|
13
|
+
* passes through untouched.
|
|
14
|
+
*
|
|
15
|
+
* Fixes the three silent-mangle cases the PoC proved in the old regex/nextLeoTag
|
|
16
|
+
* parser:
|
|
17
|
+
* 1. `value="a > b"` — quote-aware attr scan; `>` inside quotes is not the end.
|
|
18
|
+
* 2. callout-in-callout — depth-counted body scan over the SAME tag name.
|
|
19
|
+
* 3. unterminated opener — degrades to a malformed span; surrounding prose kept.
|
|
20
|
+
*
|
|
21
|
+
* Tag names are LOWERCASE-ONLY. `<leo.Callout>` (PascalCase) is NOT a
|
|
22
|
+
* leo island — the scanner does not claim it (a lint rejects the authoring form
|
|
23
|
+
* separately). The dot is a literal character in the name, not a namespace
|
|
24
|
+
* lookup.
|
|
25
|
+
*/
|
|
26
|
+
import { countRun, findFenceEnd, readFence } from './fence.js';
|
|
27
|
+
/** The opener prefix the scanner claims. */
|
|
28
|
+
const LEO_PREFIX = '<leo.';
|
|
29
|
+
/**
|
|
30
|
+
* A lowercase tag name: starts with a-z, then a-z/0-9/hyphen. This is what makes
|
|
31
|
+
* the scanner lowercase-only — an uppercase first char fails the match, so the
|
|
32
|
+
* prefix is treated as ordinary prose and passes through.
|
|
33
|
+
*/
|
|
34
|
+
const NAME_RE = /^[a-z][a-z0-9-]*/;
|
|
35
|
+
/**
|
|
36
|
+
* Scan a source string into ordered spans. Prose between islands is preserved
|
|
37
|
+
* verbatim; islands carry raw (pre-coercion) attrs + balanced body; an
|
|
38
|
+
* unparseable `<leo.` opener becomes a malformed span.
|
|
39
|
+
*/
|
|
40
|
+
export function scan(source) {
|
|
41
|
+
const spans = [];
|
|
42
|
+
let cursor = 0;
|
|
43
|
+
while (cursor < source.length) {
|
|
44
|
+
const lt = findNextLeoPrefix(source, cursor);
|
|
45
|
+
if (lt === -1) {
|
|
46
|
+
// No more openers — the rest is prose.
|
|
47
|
+
pushProse(spans, source.slice(cursor), cursor, source.length);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
const nameMatch = NAME_RE.exec(source.slice(lt + LEO_PREFIX.length));
|
|
51
|
+
if (!nameMatch) {
|
|
52
|
+
// `<leo.` not followed by a lowercase name (e.g. `<leo.` then EOF, a
|
|
53
|
+
// space, or an uppercase char). Not a claimable island: emit the
|
|
54
|
+
// `<leo.` literal as prose and continue scanning AFTER it, so a real
|
|
55
|
+
// island later in the source is still found.
|
|
56
|
+
pushProse(spans, source.slice(cursor, lt + LEO_PREFIX.length), cursor, lt + LEO_PREFIX.length);
|
|
57
|
+
cursor = lt + LEO_PREFIX.length;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
// Flush the prose before this opener.
|
|
61
|
+
pushProse(spans, source.slice(cursor, lt), cursor, lt);
|
|
62
|
+
const name = nameMatch[0];
|
|
63
|
+
const island = parseIsland(source, lt, name);
|
|
64
|
+
if (island === null) {
|
|
65
|
+
// Unterminated/unclosed opener — degrade. Preserve the `<leo.NAME`
|
|
66
|
+
// opener text and resume scanning just past it so the rest of the
|
|
67
|
+
// document (including any well-formed islands) is never dropped.
|
|
68
|
+
const openerEnd = lt + LEO_PREFIX.length + name.length;
|
|
69
|
+
const malformed = {
|
|
70
|
+
kind: 'malformed',
|
|
71
|
+
text: source.slice(lt, openerEnd),
|
|
72
|
+
reason: 'unterminated',
|
|
73
|
+
start: lt,
|
|
74
|
+
end: openerEnd,
|
|
75
|
+
};
|
|
76
|
+
spans.push(malformed);
|
|
77
|
+
cursor = openerEnd;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
spans.push(island);
|
|
81
|
+
cursor = island.end;
|
|
82
|
+
}
|
|
83
|
+
return spans;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Find the next claimable opener outside Markdown code spans and fenced code.
|
|
87
|
+
* This is lexical shielding, not a second Markdown parser: it recognizes only
|
|
88
|
+
* CommonMark's literal-code delimiters, whose contents must pass through byte
|
|
89
|
+
* for byte on every surface.
|
|
90
|
+
*/
|
|
91
|
+
function findNextLeoPrefix(source, from) {
|
|
92
|
+
let i = from;
|
|
93
|
+
while (i < source.length) {
|
|
94
|
+
const literalEnd = skipLiteral(source, i);
|
|
95
|
+
if (literalEnd !== i) {
|
|
96
|
+
i = literalEnd;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (source.startsWith(LEO_PREFIX, i)) {
|
|
100
|
+
return i;
|
|
101
|
+
}
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
/** Skip Markdown literals and comments before recognizing either tag boundary. */
|
|
107
|
+
function skipLiteral(source, at) {
|
|
108
|
+
if (source.startsWith('<!--', at)) {
|
|
109
|
+
const end = source.indexOf('-->', at + 4);
|
|
110
|
+
return end === -1 ? source.length : end + 3;
|
|
111
|
+
}
|
|
112
|
+
if (at === 0 || source[at - 1] === '\n') {
|
|
113
|
+
const fence = readFence(source, at);
|
|
114
|
+
if (fence) {
|
|
115
|
+
const end = findFenceEnd(source, fence.contentStart, fence.marker, fence.length);
|
|
116
|
+
return end === -1 ? source.length : end;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (source[at] === '`') {
|
|
120
|
+
const length = countRun(source, at, '`');
|
|
121
|
+
const close = findMatchingBacktickRun(source, at + length, length);
|
|
122
|
+
return close === -1 ? at + length : close + length;
|
|
123
|
+
}
|
|
124
|
+
return at;
|
|
125
|
+
}
|
|
126
|
+
/** Find a closing backtick run of exactly `length`, per CommonMark code spans. */
|
|
127
|
+
function findMatchingBacktickRun(source, from, length) {
|
|
128
|
+
let at = source.indexOf('`', from);
|
|
129
|
+
while (at !== -1) {
|
|
130
|
+
const candidateLength = countRun(source, at, '`');
|
|
131
|
+
if (candidateLength === length) {
|
|
132
|
+
return at;
|
|
133
|
+
}
|
|
134
|
+
at = source.indexOf('`', at + candidateLength);
|
|
135
|
+
}
|
|
136
|
+
return -1;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Parse a single island starting at `start` (the `<` of `<leo.NAME`). Returns
|
|
140
|
+
* the island span, or `null` if it cannot be parsed as a balanced island
|
|
141
|
+
* (caller degrades). Quote-aware throughout.
|
|
142
|
+
*/
|
|
143
|
+
function parseIsland(source, start, name) {
|
|
144
|
+
const attrsStart = start + LEO_PREFIX.length + name.length;
|
|
145
|
+
// Find the end of the opening tag, skipping over quoted attribute values so
|
|
146
|
+
// a `>` inside `value="a > b"` does not terminate the tag (PoC bug #1).
|
|
147
|
+
const openEnd = findOpenTagEnd(source, attrsStart);
|
|
148
|
+
if (openEnd === null) {
|
|
149
|
+
return null; // `<leo.NAME` with no closing `>` — unterminated opener.
|
|
150
|
+
}
|
|
151
|
+
const attrsRaw = source.slice(attrsStart, openEnd.attrsEnd);
|
|
152
|
+
const attrs = parseAttrs(attrsRaw);
|
|
153
|
+
if (openEnd.selfClosing) {
|
|
154
|
+
return {
|
|
155
|
+
kind: 'island',
|
|
156
|
+
name,
|
|
157
|
+
attrs,
|
|
158
|
+
body: '',
|
|
159
|
+
selfClosing: true,
|
|
160
|
+
bodyStart: openEnd.tagEnd,
|
|
161
|
+
start,
|
|
162
|
+
end: openEnd.tagEnd,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// Walk the body, depth-counting `<leo.NAME` openers vs `</leo.NAME>` closers
|
|
166
|
+
// for THIS name (quote-aware), so a callout nested in a callout matches its
|
|
167
|
+
// own close, not the inner one (PoC bug #2).
|
|
168
|
+
const bodyStart = openEnd.tagEnd;
|
|
169
|
+
const close = findMatchingClose(source, bodyStart, name);
|
|
170
|
+
if (close === null) {
|
|
171
|
+
return null; // No matching close — unclosed body; degrade.
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
kind: 'island',
|
|
175
|
+
name,
|
|
176
|
+
attrs,
|
|
177
|
+
body: source.slice(bodyStart, close.bodyEnd),
|
|
178
|
+
selfClosing: false,
|
|
179
|
+
bodyStart,
|
|
180
|
+
start,
|
|
181
|
+
end: close.tagEnd,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Find the end of an opening tag's `>` (or `/>`), starting at the first attr
|
|
186
|
+
* char. Skips over single- and double-quoted regions so a `>` inside a quoted
|
|
187
|
+
* attribute value is ignored.
|
|
188
|
+
*/
|
|
189
|
+
function findOpenTagEnd(source, from) {
|
|
190
|
+
let i = from;
|
|
191
|
+
let quote = null;
|
|
192
|
+
while (i < source.length) {
|
|
193
|
+
const ch = source[i];
|
|
194
|
+
if (quote !== null) {
|
|
195
|
+
if (ch === quote) {
|
|
196
|
+
quote = null;
|
|
197
|
+
}
|
|
198
|
+
i++;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (ch === '"' || ch === "'") {
|
|
202
|
+
quote = ch;
|
|
203
|
+
i++;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (ch === '>') {
|
|
207
|
+
const selfClosing = source[i - 1] === '/';
|
|
208
|
+
const attrsEnd = selfClosing ? i - 1 : i;
|
|
209
|
+
return { attrsEnd, tagEnd: i + 1, selfClosing };
|
|
210
|
+
}
|
|
211
|
+
i++;
|
|
212
|
+
}
|
|
213
|
+
return null; // ran off the end without a `>` — unterminated.
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* From `bodyStart`, find the `</leo.NAME>` that closes the island, honoring
|
|
217
|
+
* nesting of the SAME name and skipping quoted regions. Each well-formed
|
|
218
|
+
* `<leo.NAME ...>` (non-self-closing) opener increments depth; each
|
|
219
|
+
* `</leo.NAME>` decrements it; depth 0 is the match. A self-closing
|
|
220
|
+
* `<leo.NAME .../>` does not change depth.
|
|
221
|
+
*/
|
|
222
|
+
function findMatchingClose(source, bodyStart, name) {
|
|
223
|
+
const closeTag = `</leo.${name}>`;
|
|
224
|
+
let depth = 1;
|
|
225
|
+
let i = bodyStart;
|
|
226
|
+
while (i < source.length) {
|
|
227
|
+
const literalEnd = skipLiteral(source, i);
|
|
228
|
+
if (literalEnd !== i) {
|
|
229
|
+
i = literalEnd;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (source.startsWith(closeTag, i)) {
|
|
233
|
+
depth--;
|
|
234
|
+
if (depth === 0) {
|
|
235
|
+
return { bodyEnd: i, tagEnd: i + closeTag.length };
|
|
236
|
+
}
|
|
237
|
+
i += closeTag.length;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (source.startsWith(LEO_PREFIX, i)) {
|
|
241
|
+
const match = NAME_RE.exec(source.slice(i + LEO_PREFIX.length));
|
|
242
|
+
if (match) {
|
|
243
|
+
const inner = findOpenTagEnd(source, i + LEO_PREFIX.length + match[0].length);
|
|
244
|
+
if (!inner) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
if (match[0] === name && !inner.selfClosing) {
|
|
248
|
+
depth++;
|
|
249
|
+
}
|
|
250
|
+
i = inner.tagEnd;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
i++;
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Parse `key="value"` / `key='value'` (and bare `key`) attribute pairs from an
|
|
260
|
+
* opening tag's attribute string. Quote-aware so a `>` inside a value is part of
|
|
261
|
+
* the value (the scanner already kept it inside `attrsRaw`). A bare attribute
|
|
262
|
+
* with no `=` becomes `key -> ""` (the schema coerces a boolean from presence).
|
|
263
|
+
*/
|
|
264
|
+
export function parseAttrs(attrsRaw) {
|
|
265
|
+
const attrs = {};
|
|
266
|
+
const re = /([a-zA-Z_][\w-]*)(?:\s*=\s*("([^"]*)"|'([^']*)'))?/g;
|
|
267
|
+
let m;
|
|
268
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: idiomatic exec loop
|
|
269
|
+
while ((m = re.exec(attrsRaw)) !== null) {
|
|
270
|
+
if (m[0].trim() === '') {
|
|
271
|
+
// Zero-width match — advance to avoid an infinite loop.
|
|
272
|
+
re.lastIndex++;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const key = m[1];
|
|
276
|
+
// m[3] = double-quoted body, m[4] = single-quoted body, else bare.
|
|
277
|
+
const value = m[3] ?? m[4] ?? '';
|
|
278
|
+
attrs[key] = value;
|
|
279
|
+
}
|
|
280
|
+
return attrs;
|
|
281
|
+
}
|
|
282
|
+
// ── helpers ─────────────────────────────────────────────────────────────────
|
|
283
|
+
/** Push a prose span iff non-empty (keeps the span list free of empty noise). */
|
|
284
|
+
function pushProse(spans, text, start, end) {
|
|
285
|
+
if (text.length === 0) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const prose = { kind: 'prose', text, start, end };
|
|
289
|
+
spans.push(prose);
|
|
290
|
+
}
|
|
291
|
+
//# sourceMapp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KAAgB,EAAE,IAAY,EAAE,KAAa,EAAE,GAAW;IACzE,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO;IACX,CAAC;IACD,MAAM,KAAK,GAAc,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAC7D,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC","sourcesContent":["/**\n * The `<leo.*>` island scanner (ADR-D-01KVQHTWH8MQ).\n *\n * A single-pass, quote-aware, balanced-nesting scanner that finds `<leo.*>`\n * islands in a source string and returns the document as an ordered list of\n * spans — prose passes through VERBATIM; each island is extracted with its raw\n * attrs and balanced body; a `<leo.` opener that cannot be parsed DEGRADES to a\n * malformed span (preserved as text) rather than stalling or dropping the rest.\n *\n * It is the SOLE resolution path on both surfaces (terminal + web), so the two\n * cannot diverge. It claims ONLY `<leo.*>` (the namespace allow-list); every\n * other angle bracket — `<div>`, `<Callout>`, autolinks, code spans, `a < b` —\n * passes through untouched.\n *\n * Fixes the three silent-mangle cases the PoC proved in the old regex/nextLeoTag\n * parser:\n * 1. `value=\"a > b\"` — quote-aware attr scan; `>` inside quotes is not the end.\n * 2. callout-in-callout — depth-counted body scan over the SAME tag name.\n * 3. unterminated opener — degrades to a malformed span; surrounding prose kept.\n *\n * Tag names are LOWERCASE-ONLY. `<leo.Callout>` (PascalCase) is NOT a\n * leo island — the scanner does not claim it (a lint rejects the authoring form\n * separately). The dot is a literal character in the name, not a namespace\n * lookup.\n */\n\nimport { countRun, findFenceEnd, readFence } from './fence.js';\nimport type { DocSpan, IslandSpan, MalformedSpan, ProseSpan } from './types.js';\n\n/** The opener prefix the scanner claims. */\nconst LEO_PREFIX = '<leo.';\n\n/**\n * A lowercase tag name: starts with a-z, then a-z/0-9/hyphen. This is what makes\n * the scanner lowercase-only — an uppercase first char fails the match, so the\n * prefix is treated as ordinary prose and passes through.\n */\nconst NAME_RE = /^[a-z][a-z0-9-]*/;\n\n/**\n * Scan a source string into ordered spans. Prose between islands is preserved\n * verbatim; islands carry raw (pre-coercion) attrs + balanced body; an\n * unparseable `<leo.` opener becomes a malformed span.\n */\nexport function scan(source: string): DocSpan[] {\n const spans: DocSpan[] = [];\n let cursor = 0;\n\n while (cursor < source.length) {\n const lt = findNextLeoPrefix(source, cursor);\n if (lt === -1) {\n // No more openers — the rest is prose.\n pushProse(spans, source.slice(cursor), cursor, source.length);\n break;\n }\n\n const nameMatch = NAME_RE.exec(source.slice(lt + LEO_PREFIX.length));\n if (!nameMatch) {\n // `<leo.` not followed by a lowercase name (e.g. `<leo.` then EOF, a\n // space, or an uppercase char). Not a claimable island: emit the\n // `<leo.` literal as prose and continue scanning AFTER it, so a real\n // island later in the source is still found.\n pushProse(\n spans,\n source.slice(cursor, lt + LEO_PREFIX.length),\n cursor,\n lt + LEO_PREFIX.length\n );\n cursor = lt + LEO_PREFIX.length;\n continue;\n }\n\n // Flush the prose before this opener.\n pushProse(spans, source.slice(cursor, lt), cursor, lt);\n\n const name = nameMatch[0];\n const island = parseIsland(source, lt, name);\n if (island === null) {\n // Unterminated/unclosed opener — degrade. Preserve the `<leo.NAME`\n // opener text and resume scanning just past it so the rest of the\n // document (including any well-formed islands) is never dropped.\n const openerEnd = lt + LEO_PREFIX.length + name.length;\n const malformed: MalformedSpan = {\n kind: 'malformed',\n text: source.slice(lt, openerEnd),\n reason: 'unterminated',\n start: lt,\n end: openerEnd,\n };\n spans.push(malformed);\n cursor = openerEnd;\n continue;\n }\n\n spans.push(island);\n cursor = island.end;\n }\n\n return spans;\n}\n\n/**\n * Find the next claimable opener outside Markdown code spans and fenced code.\n * This is lexical shielding, not a second Markdown parser: it recognizes only\n * CommonMark's literal-code delimiters, whose contents must pass through byte\n * for byte on every surface.\n */\nfunction findNextLeoPrefix(source: string, from: number): number {\n let i = from;\n\n while (i < source.length) {\n const literalEnd = skipLiteral(source, i);\n if (literalEnd !== i) {\n i = literalEnd;\n continue;\n }\n\n if (source.startsWith(LEO_PREFIX, i)) {\n return i;\n }\n i++;\n }\n\n return -1;\n}\n\n/** Skip Markdown literals and comments before recognizing either tag boundary. */\nfunction skipLiteral(source: string, at: number): number {\n if (source.startsWith('<!--', at)) {\n const end = source.indexOf('-->', at + 4);\n return end === -1 ? source.length : end + 3;\n }\n if (at === 0 || source[at - 1] === '\\n') {\n const fence = readFence(source, at);\n if (fence) {\n const end = findFenceEnd(source, fence.contentStart, fence.marker, fence.length);\n return end === -1 ? source.length : end;\n }\n }\n if (source[at] === '`') {\n const length = countRun(source, at, '`');\n const close = findMatchingBacktickRun(source, at + length, length);\n return close === -1 ? at + length : close + length;\n }\n return at;\n}\n\n/** Find a closing backtick run of exactly `length`, per CommonMark code spans. */\nfunction findMatchingBacktickRun(source: string, from: number, length: number): number {\n let at = source.indexOf('`', from);\n while (at !== -1) {\n const candidateLength = countRun(source, at, '`');\n if (candidateLength === length) {\n return at;\n }\n at = source.indexOf('`', at + candidateLength);\n }\n return -1;\n}\n\n/**\n * Parse a single island starting at `start` (the `<` of `<leo.NAME`). Returns\n * the island span, or `null` if it cannot be parsed as a balanced island\n * (caller degrades). Quote-aware throughout.\n */\nfunction parseIsland(source: string, start: number, name: string): IslandSpan | null {\n const attrsStart = start + LEO_PREFIX.length + name.length;\n\n // Find the end of the opening tag, skipping over quoted attribute values so\n // a `>` inside `value=\"a > b\"` does not terminate the tag (PoC bug #1).\n const openEnd = findOpenTagEnd(source, attrsStart);\n if (openEnd === null) {\n return null; // `<leo.NAME` with no closing `>` — unterminated opener.\n }\n\n const attrsRaw = source.slice(attrsStart, openEnd.attrsEnd);\n const attrs = parseAttrs(attrsRaw);\n\n if (openEnd.selfClosing) {\n return {\n kind: 'island',\n name,\n attrs,\n body: '',\n selfClosing: true,\n bodyStart: openEnd.tagEnd,\n start,\n end: openEnd.tagEnd,\n };\n }\n\n // Walk the body, depth-counting `<leo.NAME` openers vs `</leo.NAME>` closers\n // for THIS name (quote-aware), so a callout nested in a callout matches its\n // own close, not the inner one (PoC bug #2).\n const bodyStart = openEnd.tagEnd;\n const close = findMatchingClose(source, bodyStart, name);\n if (close === null) {\n return null; // No matching close — unclosed body; degrade.\n }\n\n return {\n kind: 'island',\n name,\n attrs,\n body: source.slice(bodyStart, close.bodyEnd),\n selfClosing: false,\n bodyStart,\n start,\n end: close.tagEnd,\n };\n}\n\ninterface OpenTagEnd {\n /** Offset just past the last attr char (before `/>` or `>`). */\n readonly attrsEnd: number;\n /** Offset just past the closing `>` of the opening tag. */\n readonly tagEnd: number;\n readonly selfClosing: boolean;\n}\n\n/**\n * Find the end of an opening tag's `>` (or `/>`), starting at the first attr\n * char. Skips over single- and double-quoted regions so a `>` inside a quoted\n * attribute value is ignored.\n */\nfunction findOpenTagEnd(source: string, from: number): OpenTagEnd | null {\n let i = from;\n let quote: '\"' | \"'\" | null = null;\n while (i < source.length) {\n const ch = source[i];\n if (quote !== null) {\n if (ch === quote) {\n quote = null;\n }\n i++;\n continue;\n }\n if (ch === '\"' || ch === \"'\") {\n quote = ch;\n i++;\n continue;\n }\n if (ch === '>') {\n const selfClosing = source[i - 1] === '/';\n const attrsEnd = selfClosing ? i - 1 : i;\n return { attrsEnd, tagEnd: i + 1, selfClosing };\n }\n i++;\n }\n return null; // ran off the end without a `>` — unterminated.\n}\n\ninterface MatchingClose {\n /** Offset of the start of the matching `</leo.NAME>` (end of body). */\n readonly bodyEnd: number;\n /** Offset just past the matching close tag. */\n readonly tagEnd: number;\n}\n\n/**\n * From `bodyStart`, find the `</leo.NAME>` that closes the island, honoring\n * nesting of the SAME name and skipping quoted regions. Each well-formed\n * `<leo.NAME ...>` (non-self-closing) opener increments depth; each\n * `</leo.NAME>` decrements it; depth 0 is the match. A self-closing\n * `<leo.NAME .../>` does not change depth.\n */\nfunction findMatchingClose(source: string, bodyStart: number, name: string): MatchingClose | null {\n const closeTag = `</leo.${name}>`;\n let depth = 1;\n let i = bodyStart;\n while (i < source.length) {\n const literalEnd = skipLiteral(source, i);\n if (literalEnd !== i) {\n i = literalEnd;\n continue;\n }\n if (source.startsWith(closeTag, i)) {\n depth--;\n if (depth === 0) {\n return { bodyEnd: i, tagEnd: i + closeTag.length };\n }\n i += closeTag.length;\n continue;\n }\n if (source.startsWith(LEO_PREFIX, i)) {\n const match = NAME_RE.exec(source.slice(i + LEO_PREFIX.length));\n if (match) {\n const inner = findOpenTagEnd(source, i + LEO_PREFIX.length + match[0].length);\n if (!inner) {\n return null;\n }\n if (match[0] === name && !inner.selfClosing) {\n depth++;\n }\n i = inner.tagEnd;\n continue;\n }\n }\n i++;\n }\n return null;\n}\n\n/**\n * Parse `key=\"value\"` / `key='value'` (and bare `key`) attribute pairs from an\n * opening tag's attribute string. Quote-aware so a `>` inside a value is part of\n * the value (the scanner already kept it inside `attrsRaw`). A bare attribute\n * with no `=` becomes `key -> \"\"` (the schema coerces a boolean from presence).\n */\nexport function parseAttrs(attrsRaw: string): Record<string, string> {\n const attrs: Record<string, string> = {};\n const re = /([a-zA-Z_][\\w-]*)(?:\\s*=\\s*(\"([^\"]*)\"|'([^']*)'))?/g;\n let m: RegExpExecArray | null;\n // biome-ignore lint/suspicious/noAssignInExpressions: idiomatic exec loop\n while ((m = re.exec(attrsRaw)) !== null) {\n if (m[0].trim() === '') {\n // Zero-width match — advance to avoid an infinite loop.\n re.lastIndex++;\n continue;\n }\n const key = m[1];\n // m[3] = double-quoted body, m[4] = single-quoted body, else bare.\n const value = m[3] ?? m[4] ?? '';\n attrs[key] = value;\n }\n return attrs;\n}\n\n// ── helpers ─────────────────────────────────────────────────────────────────\n\n/** Push a prose span iff non-empty (keeps the span list free of empty noise). */\nfunction pushProse(spans: DocSpan[], text: string, start: number, end: number): void {\n if (text.length === 0) {\n return;\n }\n const prose: ProseSpan = { kind: 'prose', text, start, end };\n spans.push(prose);\n}\n"]}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/leo-studio-ai/leo-markup/schema/leo-markup-ast.schema.json",
|
|
4
|
+
"title": "leo markup AST",
|
|
5
|
+
"description": "The JSON projection of one leo markup document, emitted by toAstJson in @leo-studio/leo-markup. Offsets are UTF-16 code-unit offsets into the whole source, frontmatter included; ranges are half-open [start, end). Keys are emitted in a fixed order, attribute and prop maps sorted by key; optional members are omitted, never null, unless stated.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["version", "bodyStart", "spans", "productSpec"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"version": { "const": 1, "description": "Version of this AST shape." },
|
|
11
|
+
"bodyStart": {
|
|
12
|
+
"$ref": "#/$defs/offset",
|
|
13
|
+
"description": "Offset of the first character after a leading `---` frontmatter block; 0 without one. Nothing before it is scanned."
|
|
14
|
+
},
|
|
15
|
+
"spans": {
|
|
16
|
+
"description": "The island scanner's top-level spans in source order. Nested islands stay inside their parent's body. Prose spans carry offsets only; the text is the source slice.",
|
|
17
|
+
"type": "array",
|
|
18
|
+
"items": { "$ref": "#/$defs/span" }
|
|
19
|
+
},
|
|
20
|
+
"productSpec": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"additionalProperties": false,
|
|
23
|
+
"required": ["nodes", "diagnostics"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"nodes": {
|
|
26
|
+
"description": "The product-spec node tree (parseProductSpec) in source order, with closed `leo.tree` and `leo.journey` fences split out of prose into fence nodes.",
|
|
27
|
+
"type": "array",
|
|
28
|
+
"items": { "$ref": "#/$defs/node" }
|
|
29
|
+
},
|
|
30
|
+
"diagnostics": { "type": "array", "items": { "$ref": "#/$defs/diagnostic" } }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"$defs": {
|
|
35
|
+
"offset": { "type": "integer", "minimum": 0 },
|
|
36
|
+
"jsonValue": { "description": "Any JSON value (a `json` prop parses to arbitrary data)." },
|
|
37
|
+
"stringMap": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
38
|
+
"propMap": {
|
|
39
|
+
"description": "Coerced product-spec props: strings, and booleans for boolean props (a bare attribute is true).",
|
|
40
|
+
"type": "object",
|
|
41
|
+
"additionalProperties": { "type": ["string", "boolean"] }
|
|
42
|
+
},
|
|
43
|
+
"scope": {
|
|
44
|
+
"description": "Delivery scope a node inherits from an enclosing leo.scope (or carries itself for a scope component).",
|
|
45
|
+
"oneOf": [
|
|
46
|
+
{
|
|
47
|
+
"type": "object",
|
|
48
|
+
"additionalProperties": false,
|
|
49
|
+
"required": ["kind", "increment"],
|
|
50
|
+
"properties": {
|
|
51
|
+
"kind": { "const": "increment" },
|
|
52
|
+
"increment": { "type": "string", "pattern": "^I[0-9]+$" }
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"type": "object",
|
|
57
|
+
"additionalProperties": false,
|
|
58
|
+
"required": ["kind"],
|
|
59
|
+
"properties": { "kind": { "enum": ["deferred", "unassigned"] } }
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"span": {
|
|
64
|
+
"oneOf": [
|
|
65
|
+
{ "$ref": "#/$defs/proseSpan" },
|
|
66
|
+
{ "$ref": "#/$defs/islandSpan" },
|
|
67
|
+
{ "$ref": "#/$defs/malformedSpan" }
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"proseSpan": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"additionalProperties": false,
|
|
73
|
+
"required": ["kind", "start", "end"],
|
|
74
|
+
"properties": {
|
|
75
|
+
"kind": { "const": "prose" },
|
|
76
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
77
|
+
"end": { "$ref": "#/$defs/offset" }
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"islandSpan": {
|
|
81
|
+
"description": "One balanced `<leo.name …>` island. `attrs` is the raw attribute map (a bare attribute is \"\"). `props` and `errors` are the result of coercing `attrs` against the display registry entry of that name, or the product-spec schema when only that defines it; `known` is false (with empty props and errors) when neither does. A self-closing island has bodyStart = bodyEnd = end.",
|
|
82
|
+
"type": "object",
|
|
83
|
+
"additionalProperties": false,
|
|
84
|
+
"required": ["kind", "name", "start", "end", "bodyStart", "bodyEnd", "selfClosing", "attrs", "known", "props", "errors"],
|
|
85
|
+
"properties": {
|
|
86
|
+
"kind": { "const": "island" },
|
|
87
|
+
"name": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
|
|
88
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
89
|
+
"end": { "$ref": "#/$defs/offset" },
|
|
90
|
+
"bodyStart": { "$ref": "#/$defs/offset" },
|
|
91
|
+
"bodyEnd": { "$ref": "#/$defs/offset" },
|
|
92
|
+
"selfClosing": { "type": "boolean" },
|
|
93
|
+
"attrs": { "$ref": "#/$defs/stringMap" },
|
|
94
|
+
"known": { "type": "boolean" },
|
|
95
|
+
"props": { "type": "object", "additionalProperties": { "$ref": "#/$defs/jsonValue" } },
|
|
96
|
+
"errors": { "type": "array", "items": { "type": "string" } }
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"malformedSpan": {
|
|
100
|
+
"description": "A `<leo.name` opener that could not be parsed as a balanced island. Only the opener (`<leo.name`) is covered; the rest of the source continues as later spans.",
|
|
101
|
+
"type": "object",
|
|
102
|
+
"additionalProperties": false,
|
|
103
|
+
"required": ["kind", "reason", "start", "end"],
|
|
104
|
+
"properties": {
|
|
105
|
+
"kind": { "const": "malformed" },
|
|
106
|
+
"reason": { "enum": ["unterminated", "unclosed-body"] },
|
|
107
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
108
|
+
"end": { "$ref": "#/$defs/offset" }
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"node": {
|
|
112
|
+
"oneOf": [
|
|
113
|
+
{ "$ref": "#/$defs/componentNode" },
|
|
114
|
+
{ "$ref": "#/$defs/textNode" },
|
|
115
|
+
{ "$ref": "#/$defs/displayNode" },
|
|
116
|
+
{ "$ref": "#/$defs/fenceNode" }
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
"componentName": {
|
|
120
|
+
"enum": ["documents", "document", "journey", "step", "transition", "tree", "node", "scope", "ref", "decisions", "decision", "statement", "rationale"]
|
|
121
|
+
},
|
|
122
|
+
"componentNode": {
|
|
123
|
+
"description": "A valid product-spec component. `props` are the coerced props; children cover the body [bodyStart, bodyEnd).",
|
|
124
|
+
"type": "object",
|
|
125
|
+
"additionalProperties": false,
|
|
126
|
+
"required": ["kind", "name", "start", "end", "bodyStart", "bodyEnd", "props", "children"],
|
|
127
|
+
"properties": {
|
|
128
|
+
"kind": { "const": "component" },
|
|
129
|
+
"name": { "$ref": "#/$defs/componentName" },
|
|
130
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
131
|
+
"end": { "$ref": "#/$defs/offset" },
|
|
132
|
+
"bodyStart": { "$ref": "#/$defs/offset" },
|
|
133
|
+
"bodyEnd": { "$ref": "#/$defs/offset" },
|
|
134
|
+
"props": { "$ref": "#/$defs/propMap" },
|
|
135
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
136
|
+
"children": { "type": "array", "items": { "$ref": "#/$defs/node" } }
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"textNode": {
|
|
140
|
+
"description": "`prose`: ordinary Markdown (including tags written mid-sentence that are not refs). `fallback`: source preserved verbatim because it is malformed, unknown or invalid; a diagnostic covers the same range.",
|
|
141
|
+
"type": "object",
|
|
142
|
+
"additionalProperties": false,
|
|
143
|
+
"required": ["kind", "start", "end"],
|
|
144
|
+
"properties": {
|
|
145
|
+
"kind": { "enum": ["prose", "fallback"] },
|
|
146
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
147
|
+
"end": { "$ref": "#/$defs/offset" },
|
|
148
|
+
"scope": { "$ref": "#/$defs/scope" }
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"displayNode": {
|
|
152
|
+
"description": "A display-vocabulary island (callout, badge, the name-based tree, …) left to the display renderers.",
|
|
153
|
+
"type": "object",
|
|
154
|
+
"additionalProperties": false,
|
|
155
|
+
"required": ["kind", "name", "start", "end"],
|
|
156
|
+
"properties": {
|
|
157
|
+
"kind": { "const": "display" },
|
|
158
|
+
"name": { "type": "string" },
|
|
159
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
160
|
+
"end": { "$ref": "#/$defs/offset" },
|
|
161
|
+
"scope": { "$ref": "#/$defs/scope" }
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"fenceNode": {
|
|
165
|
+
"description": "A closed fenced block whose info string starts with `leo.tree` or `leo.journey`. The range runs from the opening fence line to the end of the closing fence line. `title` is the rest of the info string. `component` is the parsed tree or journey, or null when the block names no nodes or steps (its source is kept verbatim).",
|
|
166
|
+
"type": "object",
|
|
167
|
+
"additionalProperties": false,
|
|
168
|
+
"required": ["kind", "form", "start", "end", "component"],
|
|
169
|
+
"properties": {
|
|
170
|
+
"kind": { "const": "fence" },
|
|
171
|
+
"form": { "enum": ["tree", "journey"] },
|
|
172
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
173
|
+
"end": { "$ref": "#/$defs/offset" },
|
|
174
|
+
"title": { "type": "string", "minLength": 1 },
|
|
175
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
176
|
+
"component": { "oneOf": [{ "$ref": "#/$defs/fenceComponent" }, { "type": "null" }] }
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
"fenceComponent": {
|
|
180
|
+
"description": "A component parsed from a fence's plain-text form. It has no source offsets. Annotations map as follows: `[relation: target]` with relation exists, todo, deferred, depends-on, supersedes or superseded-by becomes a ref child; `[I<n>]`, `[deferred]` and `[unassigned]` wrap the node or step in a scope component; any other `[key: value]` or a `key: value` column becomes a prop. Journey steps get id `step-<n>` unless written `#id`; `→ <n> when <condition>` becomes a transition to `step-<n>`.",
|
|
181
|
+
"type": "object",
|
|
182
|
+
"additionalProperties": false,
|
|
183
|
+
"required": ["kind", "name", "props", "children"],
|
|
184
|
+
"properties": {
|
|
185
|
+
"kind": { "const": "component" },
|
|
186
|
+
"name": { "$ref": "#/$defs/componentName" },
|
|
187
|
+
"props": { "$ref": "#/$defs/propMap" },
|
|
188
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
189
|
+
"children": {
|
|
190
|
+
"type": "array",
|
|
191
|
+
"items": { "oneOf": [{ "$ref": "#/$defs/fenceComponent" }, { "$ref": "#/$defs/fenceText" }] }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"fenceText": {
|
|
196
|
+
"description": "Prose belonging to a fence node or step (a tree node's description lines, a step's text), joined with single spaces.",
|
|
197
|
+
"type": "object",
|
|
198
|
+
"additionalProperties": false,
|
|
199
|
+
"required": ["kind", "text"],
|
|
200
|
+
"properties": {
|
|
201
|
+
"kind": { "const": "text" },
|
|
202
|
+
"text": { "type": "string" }
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
"diagnostic": {
|
|
206
|
+
"type": "object",
|
|
207
|
+
"additionalProperties": false,
|
|
208
|
+
"required": ["code", "message", "start", "end"],
|
|
209
|
+
"properties": {
|
|
210
|
+
"code": { "enum": ["invalid-component", "unknown-component", "malformed-component", "unsupported-version"] },
|
|
211
|
+
"message": { "type": "string" },
|
|
212
|
+
"start": { "$ref": "#/$defs/offset" },
|
|
213
|
+
"end": { "$ref": "#/$defs/offset" }
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|