@agentshouse/mdmodel 0.1.0-alpha.5 → 0.1.0-alpha.6

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/README.md CHANGED
@@ -7,7 +7,7 @@ Markdown syntax profile, and the conformance fixtures.
7
7
  The package runs in a browser and in Node. It makes no network call and reads
8
8
  no filesystem on its own. Callers pass text Library state as path-to-content and declare retained binary
9
9
  link targets separately in a `ValidationContext`.
10
- The public root exposes one ESM artifact. Node 24.20.0 and later can load it
10
+ The public root exposes one ESM artifact. Node 24.21.0 and later can load it
11
11
  through either `import` or `require`; browser bundlers consume the same artifact.
12
12
 
13
13
  ## Install
@@ -26,6 +26,7 @@ import {
26
26
  links,
27
27
  MARKDOWN_SYNTAX_PROFILE,
28
28
  parse,
29
+ project,
29
30
  serialize,
30
31
  validate,
31
32
  VERSION,
@@ -140,6 +141,54 @@ whitespace, does not open with `<`, and balances its parentheses, otherwise
140
141
  inside angle brackets, which the original form is kept in when it still fits. A
141
142
  destination that neither form can carry is refused as `unwritable-link`.
142
143
 
144
+ `project(document, file, context?)` is the Embedding projection input of one
145
+ Document: the prose a consumer embeds, with every internal Markdown-document
146
+ link reduced to the label a reader sees. A Document that declares no MD type
147
+ contributes its body after the frontmatter fence. A Document that declares one
148
+ contributes the H2 sections its MD type declares as free text, each with its own
149
+ heading line and every occurrence of a repeated name, in the order the Document
150
+ carries them. Its Path, its frontmatter fields, its preamble, the sections it
151
+ carries that its MD type does not declare, and the declared structured-list
152
+ sections are outside that input.
153
+
154
+ ```ts
155
+ const parsed = parse(content);
156
+ if (parsed.ok) {
157
+ const projected = project(parsed.document, 'tasks/two.md', {
158
+ documentTargets: ['plans/q3.md', 'people/ana.md'],
159
+ definition: types['types/task.md'],
160
+ });
161
+ if (projected.ok) embed(projected.text);
162
+ }
163
+ ```
164
+
165
+ `ProjectionContext` carries `documentTargets`, the collection-relative Paths the
166
+ caller holds as Markdown documents, and `definition`, the source of the MD Type
167
+ definition Document the Document's `type` names. A Document that declares a type
168
+ the caller supplies no definition for is refused as `unknown-type`, and a
169
+ definition source the model cannot read carries its own refusal naming
170
+ `types/<type>.md`. `documentTargets` is what makes a destination internal: a
171
+ destination resolving to a supplied Path is internal, and every other
172
+ destination stays authored text, a retained binary target and a Path nobody
173
+ supplied alike. The caller supplies that membership, as it does for `validate`;
174
+ the model reads no bytes, resolves no authority, and classifies nothing it was
175
+ not given.
176
+
177
+ An internal link contributes its visible label and no destination, fragment, or
178
+ title, in the inline `[label](path)`, full `[label][id]`, and collapsed
179
+ `[label][]` forms, and the link reference definition an enumerated use resolves
180
+ through leaves the projection with it. An image at a supplied document target
181
+ contributes its alt text the same way, because a move rewrites that destination
182
+ too. External URLs, retained binary targets, unsupplied destinations, bare
183
+ fragments, code spans, fenced code, and escaped syntax stay exactly as authored,
184
+ read through the same syntax profile `links` and `validate` read. `project`
185
+ returns text and never rewrites the Document.
186
+
187
+ Because a moved Path changes destinations alone, applying a `link` change leaves
188
+ the projection of every Document it rewrites byte-identical, while a changed
189
+ visible label changes it. `fixtures/projection.json` carries every move row of
190
+ that corpus; the label change is proven at this package's own `project` seam.
191
+
143
192
  ## Fixtures
144
193
 
145
194
  The conformance corpus ships in `fixtures/`. Its verdict format and rule ids
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { apply, links, parse, serialize } from './document.js';
2
2
  export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
3
- export type { ApplyResult, Change, Document, Library, Link, ParseResult, Refusal, Validation, ValidationContext, } from './types.js';
3
+ export { project } from './project.js';
4
+ export type { ApplyResult, Change, Document, Library, Link, ParseResult, Projection, ProjectionContext, Refusal, Validation, ValidationContext, } from './types.js';
4
5
  export { validate } from './validate.js';
5
6
  export { VERSION } from './version.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { apply, links, parse, serialize } from './document.js';
2
2
  export { MARKDOWN_SYNTAX_PROFILE } from './profile.js';
3
+ export { project } from './project.js';
3
4
  export { validate } from './validate.js';
4
5
  export { VERSION } from './version.js';
5
6
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdmodel/src/index.ts"],"sourcesContent":["export { apply, links, parse, serialize } from './document.js';\nexport { MARKDOWN_SYNTAX_PROFILE } from './profile.js';\nexport type {\n ApplyResult,\n Change,\n Document,\n Library,\n Link,\n ParseResult,\n Refusal,\n Validation,\n ValidationContext,\n} from './types.js';\nexport { validate } from './validate.js';\nexport { VERSION } from './version.js';\n"],"names":["apply","links","parse","serialize","MARKDOWN_SYNTAX_PROFILE","validate","VERSION"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC/D,SAASC,uBAAuB,QAAQ,eAAe;AAYvD,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,OAAO,QAAQ,eAAe"}
1
+ {"version":3,"sources":["/workspace/packages/mdmodel/src/index.ts"],"sourcesContent":["export { apply, links, parse, serialize } from './document.js';\nexport { MARKDOWN_SYNTAX_PROFILE } from './profile.js';\nexport { project } from './project.js';\nexport type {\n ApplyResult,\n Change,\n Document,\n Library,\n Link,\n ParseResult,\n Projection,\n ProjectionContext,\n Refusal,\n Validation,\n ValidationContext,\n} from './types.js';\nexport { validate } from './validate.js';\nexport { VERSION } from './version.js';\n"],"names":["apply","links","parse","serialize","MARKDOWN_SYNTAX_PROFILE","project","validate","VERSION"],"mappings":"AAAA,SAASA,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC/D,SAASC,uBAAuB,QAAQ,eAAe;AACvD,SAASC,OAAO,QAAQ,eAAe;AAcvC,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,OAAO,QAAQ,eAAe"}
package/dist/links.d.ts CHANGED
@@ -4,5 +4,22 @@ export type HrefOccurrence = {
4
4
  readonly end: number;
5
5
  readonly bracketed: boolean;
6
6
  };
7
+ export type LinkUse = {
8
+ readonly start: number;
9
+ readonly end: number;
10
+ readonly labelStart: number;
11
+ readonly labelEnd: number;
12
+ readonly destination: HrefOccurrence;
13
+ };
14
+ export type DefinitionBlock = {
15
+ readonly start: number;
16
+ readonly end: number;
17
+ readonly destination: HrefOccurrence;
18
+ };
19
+ export type LinkInventory = {
20
+ readonly uses: readonly LinkUse[];
21
+ readonly blocks: readonly DefinitionBlock[];
22
+ };
23
+ export declare function linkInventory(body: string): LinkInventory;
7
24
  export declare function hrefOccurrences(body: string): readonly HrefOccurrence[];
8
25
  //# sourceMappingURL=links.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AA4VA,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CA2BvE"}
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AA8WA,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC7C,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAyBzD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,CAIvE"}
package/dist/links.js CHANGED
@@ -207,7 +207,7 @@ function labelEnd(text, start) {
207
207
  }
208
208
  return depth === 0 ? i : -1;
209
209
  }
210
- function takeLink(text, index, found, defs) {
210
+ function takeLink(text, index, start, found, defs) {
211
211
  const end = labelEnd(text, index + 1);
212
212
  if (end === -1) return index + 1;
213
213
  const label = text.slice(index + 1, end - 1);
@@ -215,7 +215,13 @@ function takeLink(text, index, found, defs) {
215
215
  if (text[i] === '(') {
216
216
  const dest = destination(text, i);
217
217
  if (dest === null) return index + 1;
218
- found.push(dest.occurrence);
218
+ found.push({
219
+ start,
220
+ end: dest.end,
221
+ labelStart: index + 1,
222
+ labelEnd: end - 1,
223
+ destination: dest.occurrence
224
+ });
219
225
  return dest.end;
220
226
  }
221
227
  if (text[i] === '[') {
@@ -223,7 +229,15 @@ function takeLink(text, index, found, defs) {
223
229
  if (close === -1) return index + 1;
224
230
  const id = (text.slice(i + 1, close - 1) || label).trim().toLowerCase();
225
231
  const defined = defs.get(id);
226
- if (defined !== undefined) found.push(defined);
232
+ if (defined !== undefined) {
233
+ found.push({
234
+ start,
235
+ end: close,
236
+ labelStart: index + 1,
237
+ labelEnd: end - 1,
238
+ destination: defined
239
+ });
240
+ }
227
241
  return close;
228
242
  }
229
243
  return i;
@@ -275,6 +289,7 @@ function endsBlock(content) {
275
289
  function scanBlocks(text) {
276
290
  const fences = [];
277
291
  const definitions = new Map();
292
+ const blocks = [];
278
293
  let paragraph = false;
279
294
  let depth = 0;
280
295
  let i = 0;
@@ -302,6 +317,11 @@ function scanBlocks(text) {
302
317
  const definition = paragraph ? null : definitionAt(text, line);
303
318
  if (definition !== null) {
304
319
  if (!definitions.has(definition.id)) definitions.set(definition.id, definition.occurrence);
320
+ blocks.push({
321
+ start: line.start,
322
+ end: definition.next,
323
+ destination: definition.occurrence
324
+ });
305
325
  i = definition.next;
306
326
  continue;
307
327
  }
@@ -310,7 +330,8 @@ function scanBlocks(text) {
310
330
  }
311
331
  return {
312
332
  fences,
313
- definitions
333
+ definitions,
334
+ blocks
314
335
  };
315
336
  }
316
337
  function fenceEndAt(spans, index) {
@@ -319,9 +340,9 @@ function fenceEndAt(spans, index) {
319
340
  }
320
341
  return undefined;
321
342
  }
322
- export function hrefOccurrences(body) {
323
- const { fences, definitions } = scanBlocks(body);
324
- const found = [];
343
+ export function linkInventory(body) {
344
+ const { fences, definitions, blocks } = scanBlocks(body);
345
+ const uses = [];
325
346
  let i = 0;
326
347
  while(i < body.length){
327
348
  const fenceEnd = fenceEndAt(fences, i);
@@ -334,17 +355,23 @@ export function hrefOccurrences(body) {
334
355
  continue;
335
356
  }
336
357
  if (body[i] === '!' && body[i + 1] === '[') {
337
- i = takeLink(body, i + 1, found, definitions);
358
+ i = takeLink(body, i + 1, i, uses, definitions);
338
359
  continue;
339
360
  }
340
361
  if (body[i] === '[') {
341
- i = takeLink(body, i, found, definitions);
362
+ i = takeLink(body, i, i, uses, definitions);
342
363
  continue;
343
364
  }
344
365
  i += 1;
345
366
  }
367
+ return {
368
+ uses,
369
+ blocks
370
+ };
371
+ }
372
+ export function hrefOccurrences(body) {
346
373
  const byStart = new Map();
347
- for (const occurrence of found)byStart.set(occurrence.start, occurrence);
374
+ for (const use of linkInventory(body).uses)byStart.set(use.destination.start, use.destination);
348
375
  return [
349
376
  ...byStart.values()
350
377
  ].sort((left, right)=>left.start - right.start);
package/dist/links.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdmodel/src/links.ts"],"sourcesContent":["type Fence = {\n readonly char: string;\n readonly length: number;\n readonly depth: number;\n readonly column: number;\n readonly item: boolean;\n};\n\ntype Line = {\n readonly start: number;\n readonly end: number;\n readonly content: number;\n readonly depth: number;\n readonly item: boolean;\n readonly inner: number;\n};\n\nconst TAB_STOP = 4;\nconst CLOSING_FENCE_INDENT = 3;\n\nconst HEADING = /^#{1,6}(?:[ \\t]|$)/;\nconst BREAK = /^(?:(?:\\*[ \\t]*){3,}|(?:-[ \\t]*){3,}|(?:_[ \\t]*){3,})$/;\nconst SETEXT = /^(?:=+|-+)[ \\t]*$/;\nconst LABEL = /^\\[((?:[^\\\\\\]\\n]|\\\\.)+)\\]:[ \\t]*/;\nconst DESTINATION = /^(?:(<[^<>\\n\\r]*>)|([^\\s<][^\\s]*))/d;\nconst TITLE = /^(?:\"[^\"\\n]*\"|'[^'\\n]*'|\\([^()\\n]*\\))[ \\t]*$/;\n\nfunction endOfLine(text: string, from: number): number {\n const nl = text.indexOf('\\n', from);\n return nl === -1 ? text.length : nl;\n}\n\nfunction afterLine(text: string, end: number): number {\n return end < text.length ? end + 1 : text.length;\n}\n\nfunction itemMarker(text: string, index: number, end: number): number | null {\n let i = index;\n const bullet = text[i];\n if (bullet === '-' || bullet === '*' || bullet === '+') i += 1;\n else {\n let digits = 0;\n while (digits < 9 && i + digits < end && text[i + digits]! >= '0' && text[i + digits]! <= '9')\n digits += 1;\n const delimiter = text[i + digits];\n if (digits === 0 || (delimiter !== '.' && delimiter !== ')')) return null;\n i += digits + 1;\n }\n if (i >= end) return i;\n if (text[i] !== ' ' && text[i] !== '\\t') return null;\n return i + 1;\n}\n\nfunction readLine(text: string, start: number, end: number): Line {\n let i = start;\n let depth = 0;\n let item = false;\n let inner = start;\n for (;;) {\n let spaces = 0;\n while (spaces < 3 && i < end && text[i] === ' ') {\n i += 1;\n spaces += 1;\n }\n if (i < end && text[i] === '>') {\n depth += 1;\n i += 1;\n if (i < end && text[i] === ' ') i += 1;\n inner = i;\n continue;\n }\n const after = i < end ? itemMarker(text, i, end) : null;\n if (after === null) break;\n item = true;\n i = after;\n }\n return { start, end, content: i, depth, item, inner };\n}\n\nfunction widthOf(text: string, from: number, to: number): number {\n let width = 0;\n for (let i = from; i < to; i += 1) width += text[i] === '\\t' ? TAB_STOP - (width % TAB_STOP) : 1;\n return width;\n}\n\nfunction afterIndent(text: string, line: Line): number {\n let i = line.inner;\n while (i < line.end && (text[i] === ' ' || text[i] === '\\t')) i += 1;\n return i;\n}\n\nfunction indentWidth(text: string, line: Line): number {\n return widthOf(text, line.inner, afterIndent(text, line));\n}\n\nfunction lineText(text: string, line: Line): string {\n const raw = text.slice(line.content, line.end);\n return raw.endsWith('\\r') ? raw.slice(0, -1) : raw;\n}\n\nfunction fenceRun(\n text: string,\n at: number,\n end: number,\n): { readonly char: string; readonly length: number } | null {\n const char = text[at];\n if (char !== '`' && char !== '~') return null;\n let length = 0;\n while (at + length < end && text[at + length] === char) length += 1;\n return length < 3 ? null : { char, length };\n}\n\nfunction fenceAt(text: string, line: Line): Fence | null {\n const run = fenceRun(text, line.content, line.end);\n if (run === null) return null;\n return {\n char: run.char,\n length: run.length,\n depth: line.depth,\n column: line.item ? widthOf(text, line.inner, line.content) : 0,\n item: line.item,\n };\n}\n\nfunction closesFence(text: string, line: Line, open: Fence): boolean {\n if (line.depth !== open.depth || line.item) return false;\n const indent = indentWidth(text, line);\n if (indent < open.column || indent > open.column + CLOSING_FENCE_INDENT) return false;\n const at = afterIndent(text, line);\n const run = fenceRun(text, at, line.end);\n if (run === null || run.char !== open.char || run.length < open.length) return false;\n return text.slice(at + run.length, line.end).trim() === '';\n}\n\nfunction leavesContainer(text: string, line: Line, open: Fence): boolean {\n if (line.depth < open.depth) return true;\n if (!open.item || lineText(text, line).trim() === '') return false;\n return indentWidth(text, line) < open.column;\n}\n\nfunction fenceSpan(text: string, line: Line, open: Fence): number {\n let cursor = afterLine(text, line.end);\n while (cursor < text.length) {\n const end = endOfLine(text, cursor);\n const next = readLine(text, cursor, end);\n if (leavesContainer(text, next, open)) return cursor;\n if (closesFence(text, next, open)) return afterLine(text, end);\n cursor = afterLine(text, end);\n }\n return text.length;\n}\n\nfunction skipInlineCode(text: string, index: number): number {\n let ticks = 0;\n while (text[index + ticks] === '`') ticks += 1;\n const close = text.indexOf('`'.repeat(ticks), index + ticks);\n if (close === -1) return text.length;\n return close + ticks;\n}\n\nfunction skipLinkSpace(text: string, start: number): number {\n let i = start;\n while (text[i] === ' ' || text[i] === '\\t') i += 1;\n return i;\n}\n\nfunction skipTitle(text: string, start: number): number | null {\n const open = text[start];\n if (open !== '\"' && open !== \"'\" && open !== '(') return start;\n const close = open === '(' ? ')' : open;\n let i = start + 1;\n while (i < text.length) {\n const ch = text[i]!;\n if (ch === close) return i + 1;\n if (ch === '\\n' || ch === '\\r') return null;\n i += 1;\n }\n return null;\n}\n\nfunction destination(\n text: string,\n start: number,\n): { occurrence: HrefOccurrence; end: number } | null {\n let i = skipLinkSpace(text, start + 1);\n let occurrence: HrefOccurrence;\n if (text[i] === '<') {\n const close = text.indexOf('>', i + 1);\n if (close === -1) return null;\n occurrence = { href: text.slice(i + 1, close), start: i, end: close + 1, bracketed: true };\n i = close + 1;\n } else {\n const from = i;\n let depth = 0;\n while (i < text.length) {\n const ch = text[i]!;\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') break;\n if (ch === '(') depth += 1;\n else if (ch === ')') {\n if (depth === 0) break;\n depth -= 1;\n }\n i += 1;\n }\n occurrence = { href: text.slice(from, i), start: from, end: i, bracketed: false };\n }\n i = skipLinkSpace(text, i);\n const afterTitle = skipTitle(text, i);\n if (afterTitle === null) return null;\n i = skipLinkSpace(text, afterTitle);\n if (text[i] !== ')') return null;\n return { occurrence, end: i + 1 };\n}\n\nfunction labelEnd(text: string, start: number): number {\n let i = start;\n let depth = 1;\n while (i < text.length && depth > 0) {\n const ch = text[i]!;\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '[') depth += 1;\n else if (ch === ']') depth -= 1;\n else if (ch === '\\n' || ch === '\\r') return -1;\n i += 1;\n }\n return depth === 0 ? i : -1;\n}\n\nfunction takeLink(\n text: string,\n index: number,\n found: HrefOccurrence[],\n defs: ReadonlyMap<string, HrefOccurrence>,\n): number {\n const end = labelEnd(text, index + 1);\n if (end === -1) return index + 1;\n const label = text.slice(index + 1, end - 1);\n let i = end;\n if (text[i] === '(') {\n const dest = destination(text, i);\n if (dest === null) return index + 1;\n found.push(dest.occurrence);\n return dest.end;\n }\n if (text[i] === '[') {\n const close = labelEnd(text, i + 1);\n if (close === -1) return index + 1;\n const id = (text.slice(i + 1, close - 1) || label).trim().toLowerCase();\n const defined = defs.get(id);\n if (defined !== undefined) found.push(defined);\n return close;\n }\n return i;\n}\n\nfunction definitionDestination(text: string, from: number, to: number): HrefOccurrence | null {\n let i = from;\n while (i < to && (text[i] === ' ' || text[i] === '\\t')) i += 1;\n const match = DESTINATION.exec(text.slice(i, to));\n if (match === null) return null;\n const bracketed = match[1];\n const span = match.indices?.[1] ?? match.indices?.[2];\n const href = bracketed === undefined ? match[2] : bracketed.slice(1, -1);\n if (href === undefined || span === undefined) return null;\n return { href, start: i + span[0], end: i + span[1], bracketed: bracketed !== undefined };\n}\n\nfunction definitionAt(\n text: string,\n line: Line,\n): { id: string; occurrence: HrefOccurrence; next: number } | null {\n const head = LABEL.exec(lineText(text, line));\n if (head === null) return null;\n const id = head[1]?.trim().toLowerCase();\n if (id === undefined || id === '') return null;\n const from = line.content + head[0].length;\n let occurrence = definitionDestination(text, from, line.end);\n let next = afterLine(text, line.end);\n if (occurrence === null) {\n if (text.slice(from, line.end).trim() !== '' || next >= text.length) return null;\n const end = endOfLine(text, next);\n occurrence = definitionDestination(text, readLine(text, next, end).content, end);\n if (occurrence === null) return null;\n next = afterLine(text, end);\n }\n if (next < text.length) {\n const end = endOfLine(text, next);\n if (TITLE.test(lineText(text, readLine(text, next, end)))) next = afterLine(text, end);\n }\n return { id, occurrence, next };\n}\n\nfunction endsBlock(content: string): boolean {\n return HEADING.test(content) || BREAK.test(content) || SETEXT.test(content);\n}\n\nfunction scanBlocks(text: string): {\n readonly fences: readonly (readonly [number, number])[];\n readonly definitions: ReadonlyMap<string, HrefOccurrence>;\n} {\n const fences: [number, number][] = [];\n const definitions = new Map<string, HrefOccurrence>();\n let paragraph = false;\n let depth = 0;\n let i = 0;\n while (i < text.length) {\n const line = readLine(text, i, endOfLine(text, i));\n if (line.depth !== depth || line.item) paragraph = false;\n depth = line.depth;\n const open = fenceAt(text, line);\n if (open !== null) {\n const stop = fenceSpan(text, line, open);\n fences.push([i, stop]);\n paragraph = false;\n i = stop;\n continue;\n }\n const content = lineText(text, line);\n if (content.trim() === '') {\n paragraph = false;\n i = afterLine(text, line.end);\n continue;\n }\n const definition = paragraph ? null : definitionAt(text, line);\n if (definition !== null) {\n if (!definitions.has(definition.id)) definitions.set(definition.id, definition.occurrence);\n i = definition.next;\n continue;\n }\n paragraph = !endsBlock(content);\n i = afterLine(text, line.end);\n }\n return { fences, definitions };\n}\n\nfunction fenceEndAt(\n spans: readonly (readonly [number, number])[],\n index: number,\n): number | undefined {\n for (const [start, end] of spans) {\n if (index >= start && index < end) return end;\n }\n return undefined;\n}\n\nexport type HrefOccurrence = {\n readonly href: string;\n readonly start: number;\n readonly end: number;\n readonly bracketed: boolean;\n};\n\nexport function hrefOccurrences(body: string): readonly HrefOccurrence[] {\n const { fences, definitions } = scanBlocks(body);\n const found: HrefOccurrence[] = [];\n let i = 0;\n while (i < body.length) {\n const fenceEnd = fenceEndAt(fences, i);\n if (fenceEnd !== undefined) {\n i = fenceEnd;\n continue;\n }\n if (body[i] === '`') {\n i = skipInlineCode(body, i);\n continue;\n }\n if (body[i] === '!' && body[i + 1] === '[') {\n i = takeLink(body, i + 1, found, definitions);\n continue;\n }\n if (body[i] === '[') {\n i = takeLink(body, i, found, definitions);\n continue;\n }\n i += 1;\n }\n const byStart = new Map<number, HrefOccurrence>();\n for (const occurrence of found) byStart.set(occurrence.start, occurrence);\n return [...byStart.values()].sort((left, right) => left.start - right.start);\n}\n"],"names":["TAB_STOP","CLOSING_FENCE_INDENT","HEADING","BREAK","SETEXT","LABEL","DESTINATION","TITLE","endOfLine","text","from","nl","indexOf","length","afterLine","end","itemMarker","index","i","bullet","digits","delimiter","readLine","start","depth","item","inner","spaces","after","content","widthOf","to","width","afterIndent","line","indentWidth","lineText","raw","slice","endsWith","fenceRun","at","char","fenceAt","run","column","closesFence","open","indent","trim","leavesContainer","fenceSpan","cursor","next","skipInlineCode","ticks","close","repeat","skipLinkSpace","skipTitle","ch","destination","occurrence","href","bracketed","afterTitle","labelEnd","takeLink","found","defs","label","dest","push","id","toLowerCase","defined","get","undefined","definitionDestination","match","exec","span","indices","definitionAt","head","test","endsBlock","scanBlocks","fences","definitions","Map","paragraph","stop","definition","has","set","fenceEndAt","spans","hrefOccurrences","body","fenceEnd","byStart","values","sort","left","right"],"mappings":"AAiBA,MAAMA,WAAW;AACjB,MAAMC,uBAAuB;AAE7B,MAAMC,UAAU;AAChB,MAAMC,QAAQ;AACd,MAAMC,SAAS;AACf,MAAMC,QAAQ;AACd,MAAMC,cAAc;AACpB,MAAMC,QAAQ;AAEd,SAASC,UAAUC,IAAY,EAAEC,IAAY;IAC3C,MAAMC,KAAKF,KAAKG,OAAO,CAAC,MAAMF;IAC9B,OAAOC,OAAO,CAAC,IAAIF,KAAKI,MAAM,GAAGF;AACnC;AAEA,SAASG,UAAUL,IAAY,EAAEM,GAAW;IAC1C,OAAOA,MAAMN,KAAKI,MAAM,GAAGE,MAAM,IAAIN,KAAKI,MAAM;AAClD;AAEA,SAASG,WAAWP,IAAY,EAAEQ,KAAa,EAAEF,GAAW;IAC1D,IAAIG,IAAID;IACR,MAAME,SAASV,IAAI,CAACS,EAAE;IACtB,IAAIC,WAAW,OAAOA,WAAW,OAAOA,WAAW,KAAKD,KAAK;SACxD;QACH,IAAIE,SAAS;QACb,MAAOA,SAAS,KAAKF,IAAIE,S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,SAASM,SAASN,QAAQF,KAAK,OAAOA;IAC5C;IACA,OAAO8D;AACT;AASA,OAAO,SAASqB,gBAAgBC,IAAY;IAC1C,MAAM,EAAEX,MAAM,EAAEC,WAAW,EAAE,GAAGF,WAAWY;IAC3C,MAAM/B,QAA0B,EAAE;IAClC,IAAIlD,IAAI;IACR,MAAOA,IAAIiF,KAAKtF,MAAM,CAAE;QACtB,MAAMuF,WAAWJ,WAAWR,QAAQtE;QACpC,IAAIkF,aAAavB,WAAW;YAC1B3D,IAAIkF;YACJ;QACF;QACA,IAAID,IAAI,CAACjF,EAAE,KAAK,KAAK;YACnBA,IAAIoC,eAAe6C,MAAMjF;YACzB;QACF;QACA,IAAIiF,IAAI,CAACjF,EAAE,KAAK,OAAOiF,IAAI,CAACjF,IAAI,EAAE,KAAK,KAAK;YAC1CA,IAAIiD,SAASgC,MAAMjF,IAAI,GAAGkD,OAAOqB;YACjC;QACF;QACA,IAAIU,IAAI,CAACjF,EAAE,KAAK,KAAK;YACnBA,IAAIiD,SAASgC,MAAMjF,GAAGkD,OAAOqB;YAC7B;QACF;QACAvE,KAAK;IACP;IACA,MAAMmF,UAAU,IAAIX;IACpB,KAAK,MAAM5B,cAAcM,MAAOiC,QAAQN,GAAG,CAACjC,WAAWvC,KAAK,EAAEuC;IAC9D,OAAO;WAAIuC,QAAQC,MAAM;KAAG,CAACC,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKjF,KAAK,GAAGkF,MAAMlF,KAAK;AAC7E"}
1
+ {"version":3,"sources":["/workspace/packages/mdmodel/src/links.ts"],"sourcesContent":["type Fence = {\n readonly char: string;\n readonly length: number;\n readonly depth: number;\n readonly column: number;\n readonly item: boolean;\n};\n\ntype Line = {\n readonly start: number;\n readonly end: number;\n readonly content: number;\n readonly depth: number;\n readonly item: boolean;\n readonly inner: number;\n};\n\nconst TAB_STOP = 4;\nconst CLOSING_FENCE_INDENT = 3;\n\nconst HEADING = /^#{1,6}(?:[ \\t]|$)/;\nconst BREAK = /^(?:(?:\\*[ \\t]*){3,}|(?:-[ \\t]*){3,}|(?:_[ \\t]*){3,})$/;\nconst SETEXT = /^(?:=+|-+)[ \\t]*$/;\nconst LABEL = /^\\[((?:[^\\\\\\]\\n]|\\\\.)+)\\]:[ \\t]*/;\nconst DESTINATION = /^(?:(<[^<>\\n\\r]*>)|([^\\s<][^\\s]*))/d;\nconst TITLE = /^(?:\"[^\"\\n]*\"|'[^'\\n]*'|\\([^()\\n]*\\))[ \\t]*$/;\n\nfunction endOfLine(text: string, from: number): number {\n const nl = text.indexOf('\\n', from);\n return nl === -1 ? text.length : nl;\n}\n\nfunction afterLine(text: string, end: number): number {\n return end < text.length ? end + 1 : text.length;\n}\n\nfunction itemMarker(text: string, index: number, end: number): number | null {\n let i = index;\n const bullet = text[i];\n if (bullet === '-' || bullet === '*' || bullet === '+') i += 1;\n else {\n let digits = 0;\n while (digits < 9 && i + digits < end && text[i + digits]! >= '0' && text[i + digits]! <= '9')\n digits += 1;\n const delimiter = text[i + digits];\n if (digits === 0 || (delimiter !== '.' && delimiter !== ')')) return null;\n i += digits + 1;\n }\n if (i >= end) return i;\n if (text[i] !== ' ' && text[i] !== '\\t') return null;\n return i + 1;\n}\n\nfunction readLine(text: string, start: number, end: number): Line {\n let i = start;\n let depth = 0;\n let item = false;\n let inner = start;\n for (;;) {\n let spaces = 0;\n while (spaces < 3 && i < end && text[i] === ' ') {\n i += 1;\n spaces += 1;\n }\n if (i < end && text[i] === '>') {\n depth += 1;\n i += 1;\n if (i < end && text[i] === ' ') i += 1;\n inner = i;\n continue;\n }\n const after = i < end ? itemMarker(text, i, end) : null;\n if (after === null) break;\n item = true;\n i = after;\n }\n return { start, end, content: i, depth, item, inner };\n}\n\nfunction widthOf(text: string, from: number, to: number): number {\n let width = 0;\n for (let i = from; i < to; i += 1) width += text[i] === '\\t' ? TAB_STOP - (width % TAB_STOP) : 1;\n return width;\n}\n\nfunction afterIndent(text: string, line: Line): number {\n let i = line.inner;\n while (i < line.end && (text[i] === ' ' || text[i] === '\\t')) i += 1;\n return i;\n}\n\nfunction indentWidth(text: string, line: Line): number {\n return widthOf(text, line.inner, afterIndent(text, line));\n}\n\nfunction lineText(text: string, line: Line): string {\n const raw = text.slice(line.content, line.end);\n return raw.endsWith('\\r') ? raw.slice(0, -1) : raw;\n}\n\nfunction fenceRun(\n text: string,\n at: number,\n end: number,\n): { readonly char: string; readonly length: number } | null {\n const char = text[at];\n if (char !== '`' && char !== '~') return null;\n let length = 0;\n while (at + length < end && text[at + length] === char) length += 1;\n return length < 3 ? null : { char, length };\n}\n\nfunction fenceAt(text: string, line: Line): Fence | null {\n const run = fenceRun(text, line.content, line.end);\n if (run === null) return null;\n return {\n char: run.char,\n length: run.length,\n depth: line.depth,\n column: line.item ? widthOf(text, line.inner, line.content) : 0,\n item: line.item,\n };\n}\n\nfunction closesFence(text: string, line: Line, open: Fence): boolean {\n if (line.depth !== open.depth || line.item) return false;\n const indent = indentWidth(text, line);\n if (indent < open.column || indent > open.column + CLOSING_FENCE_INDENT) return false;\n const at = afterIndent(text, line);\n const run = fenceRun(text, at, line.end);\n if (run === null || run.char !== open.char || run.length < open.length) return false;\n return text.slice(at + run.length, line.end).trim() === '';\n}\n\nfunction leavesContainer(text: string, line: Line, open: Fence): boolean {\n if (line.depth < open.depth) return true;\n if (!open.item || lineText(text, line).trim() === '') return false;\n return indentWidth(text, line) < open.column;\n}\n\nfunction fenceSpan(text: string, line: Line, open: Fence): number {\n let cursor = afterLine(text, line.end);\n while (cursor < text.length) {\n const end = endOfLine(text, cursor);\n const next = readLine(text, cursor, end);\n if (leavesContainer(text, next, open)) return cursor;\n if (closesFence(text, next, open)) return afterLine(text, end);\n cursor = afterLine(text, end);\n }\n return text.length;\n}\n\nfunction skipInlineCode(text: string, index: number): number {\n let ticks = 0;\n while (text[index + ticks] === '`') ticks += 1;\n const close = text.indexOf('`'.repeat(ticks), index + ticks);\n if (close === -1) return text.length;\n return close + ticks;\n}\n\nfunction skipLinkSpace(text: string, start: number): number {\n let i = start;\n while (text[i] === ' ' || text[i] === '\\t') i += 1;\n return i;\n}\n\nfunction skipTitle(text: string, start: number): number | null {\n const open = text[start];\n if (open !== '\"' && open !== \"'\" && open !== '(') return start;\n const close = open === '(' ? ')' : open;\n let i = start + 1;\n while (i < text.length) {\n const ch = text[i]!;\n if (ch === close) return i + 1;\n if (ch === '\\n' || ch === '\\r') return null;\n i += 1;\n }\n return null;\n}\n\nfunction destination(\n text: string,\n start: number,\n): { occurrence: HrefOccurrence; end: number } | null {\n let i = skipLinkSpace(text, start + 1);\n let occurrence: HrefOccurrence;\n if (text[i] === '<') {\n const close = text.indexOf('>', i + 1);\n if (close === -1) return null;\n occurrence = { href: text.slice(i + 1, close), start: i, end: close + 1, bracketed: true };\n i = close + 1;\n } else {\n const from = i;\n let depth = 0;\n while (i < text.length) {\n const ch = text[i]!;\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '\\r') break;\n if (ch === '(') depth += 1;\n else if (ch === ')') {\n if (depth === 0) break;\n depth -= 1;\n }\n i += 1;\n }\n occurrence = { href: text.slice(from, i), start: from, end: i, bracketed: false };\n }\n i = skipLinkSpace(text, i);\n const afterTitle = skipTitle(text, i);\n if (afterTitle === null) return null;\n i = skipLinkSpace(text, afterTitle);\n if (text[i] !== ')') return null;\n return { occurrence, end: i + 1 };\n}\n\nfunction labelEnd(text: string, start: number): number {\n let i = start;\n let depth = 1;\n while (i < text.length && depth > 0) {\n const ch = text[i]!;\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '[') depth += 1;\n else if (ch === ']') depth -= 1;\n else if (ch === '\\n' || ch === '\\r') return -1;\n i += 1;\n }\n return depth === 0 ? i : -1;\n}\n\nfunction takeLink(\n text: string,\n index: number,\n start: number,\n found: LinkUse[],\n defs: ReadonlyMap<string, HrefOccurrence>,\n): number {\n const end = labelEnd(text, index + 1);\n if (end === -1) return index + 1;\n const label = text.slice(index + 1, end - 1);\n let i = end;\n if (text[i] === '(') {\n const dest = destination(text, i);\n if (dest === null) return index + 1;\n found.push({\n start,\n end: dest.end,\n labelStart: index + 1,\n labelEnd: end - 1,\n destination: dest.occurrence,\n });\n return dest.end;\n }\n if (text[i] === '[') {\n const close = labelEnd(text, i + 1);\n if (close === -1) return index + 1;\n const id = (text.slice(i + 1, close - 1) || label).trim().toLowerCase();\n const defined = defs.get(id);\n if (defined !== undefined) {\n found.push({\n start,\n end: close,\n labelStart: index + 1,\n labelEnd: end - 1,\n destination: defined,\n });\n }\n return close;\n }\n return i;\n}\n\nfunction definitionDestination(text: string, from: number, to: number): HrefOccurrence | null {\n let i = from;\n while (i < to && (text[i] === ' ' || text[i] === '\\t')) i += 1;\n const match = DESTINATION.exec(text.slice(i, to));\n if (match === null) return null;\n const bracketed = match[1];\n const span = match.indices?.[1] ?? match.indices?.[2];\n const href = bracketed === undefined ? match[2] : bracketed.slice(1, -1);\n if (href === undefined || span === undefined) return null;\n return { href, start: i + span[0], end: i + span[1], bracketed: bracketed !== undefined };\n}\n\nfunction definitionAt(\n text: string,\n line: Line,\n): { id: string; occurrence: HrefOccurrence; next: number } | null {\n const head = LABEL.exec(lineText(text, line));\n if (head === null) return null;\n const id = head[1]?.trim().toLowerCase();\n if (id === undefined || id === '') return null;\n const from = line.content + head[0].length;\n let occurrence = definitionDestination(text, from, line.end);\n let next = afterLine(text, line.end);\n if (occurrence === null) {\n if (text.slice(from, line.end).trim() !== '' || next >= text.length) return null;\n const end = endOfLine(text, next);\n occurrence = definitionDestination(text, readLine(text, next, end).content, end);\n if (occurrence === null) return null;\n next = afterLine(text, end);\n }\n if (next < text.length) {\n const end = endOfLine(text, next);\n if (TITLE.test(lineText(text, readLine(text, next, end)))) next = afterLine(text, end);\n }\n return { id, occurrence, next };\n}\n\nfunction endsBlock(content: string): boolean {\n return HEADING.test(content) || BREAK.test(content) || SETEXT.test(content);\n}\n\nfunction scanBlocks(text: string): {\n readonly fences: readonly (readonly [number, number])[];\n readonly definitions: ReadonlyMap<string, HrefOccurrence>;\n readonly blocks: readonly DefinitionBlock[];\n} {\n const fences: [number, number][] = [];\n const definitions = new Map<string, HrefOccurrence>();\n const blocks: DefinitionBlock[] = [];\n let paragraph = false;\n let depth = 0;\n let i = 0;\n while (i < text.length) {\n const line = readLine(text, i, endOfLine(text, i));\n if (line.depth !== depth || line.item) paragraph = false;\n depth = line.depth;\n const open = fenceAt(text, line);\n if (open !== null) {\n const stop = fenceSpan(text, line, open);\n fences.push([i, stop]);\n paragraph = false;\n i = stop;\n continue;\n }\n const content = lineText(text, line);\n if (content.trim() === '') {\n paragraph = false;\n i = afterLine(text, line.end);\n continue;\n }\n const definition = paragraph ? null : definitionAt(text, line);\n if (definition !== null) {\n if (!definitions.has(definition.id)) definitions.set(definition.id, definition.occurrence);\n blocks.push({ start: line.start, end: definition.next, destination: definition.occurrence });\n i = definition.next;\n continue;\n }\n paragraph = !endsBlock(content);\n i = afterLine(text, line.end);\n }\n return { fences, definitions, blocks };\n}\n\nfunction fenceEndAt(\n spans: readonly (readonly [number, number])[],\n index: number,\n): number | undefined {\n for (const [start, end] of spans) {\n if (index >= start && index < end) return end;\n }\n return undefined;\n}\n\nexport type HrefOccurrence = {\n readonly href: string;\n readonly start: number;\n readonly end: number;\n readonly bracketed: boolean;\n};\n\nexport type LinkUse = {\n readonly start: number;\n readonly end: number;\n readonly labelStart: number;\n readonly labelEnd: number;\n readonly destination: HrefOccurrence;\n};\n\nexport type DefinitionBlock = {\n readonly start: number;\n readonly end: number;\n readonly destination: HrefOccurrence;\n};\n\nexport type LinkInventory = {\n readonly uses: readonly LinkUse[];\n readonly blocks: readonly DefinitionBlock[];\n};\n\nexport function linkInventory(body: string): LinkInventory {\n const { fences, definitions, blocks } = scanBlocks(body);\n const uses: LinkUse[] = [];\n let i = 0;\n while (i < body.length) {\n const fenceEnd = fenceEndAt(fences, i);\n if (fenceEnd !== undefined) {\n i = fenceEnd;\n continue;\n }\n if (body[i] === '`') {\n i = skipInlineCode(body, i);\n continue;\n }\n if (body[i] === '!' && body[i + 1] === '[') {\n i = takeLink(body, i + 1, i, uses, definitions);\n continue;\n }\n if (body[i] === '[') {\n i = takeLink(body, i, i, uses, definitions);\n continue;\n }\n i += 1;\n }\n return { uses, blocks };\n}\n\nexport function hrefOccurrences(body: string): readonly HrefOccurrence[] {\n const byStart = new Map<number, HrefOccurrence>();\n for (const use of linkInventory(body).uses) byStart.set(use.destination.start, use.destination);\n return [...byStart.values()].sort((left, right) => left.start - right.start);\n}\n"],"names":["TAB_STOP","CLOSING_FENCE_INDENT","HEADING","BREAK","SETEXT","LABEL","DESTINATION","TITLE","endOfLine","text","from","nl","indexOf","length","afterLine","end","itemMarker","index","i","bullet","digits","delimiter","readLine","start","depth","item","inner","spaces","after","content","widthOf","to","width","afterIndent","line","indentWidth","lineText","raw","slice","endsWith","fenceRun","at","char","fenceAt","run","column","closesFence","open","indent","trim","leavesContainer","fenceSpan","cursor","next","skipInlineCode","ticks","close","repeat","skipLinkSpace","skipTitle","ch","destination","occurrence","href","bracketed","afterTitle","labelEnd","takeLink","found","defs","label","dest","push","labelStart","id","toLowerCase","defined","get","undefined","definitionDestination","match","exec","span","indices","definitionAt","head","test","endsBlock","scanBlocks","fences","definitions","Map","blocks","paragraph","stop","definition","has","set","fenceEndAt","spans","linkInventory","body","uses","fenceEnd","hrefOccurrences","byStart","use","values","sort","left","right"],"mappings":"AAiBA,MAAMA,WAAW;AACjB,MAAMC,uBAAuB;AAE7B,MAAMC,UAAU;AAChB,MAAMC,QAAQ;AACd,MAAMC,SAAS;AACf,MAAMC,QAAQ;AACd,MAAMC,cAAc;AACpB,MAAMC,QAAQ;AAEd,SAASC,UAAUC,IAAY,EAAEC,IAAY;IAC3C,MAAMC,KAAKF,KAAKG,OAAO,CAAC,MAAMF;IAC9B,OAAOC,OAAO,CAAC,IAAIF,KAAKI,MAAM,GAAGF;AACnC;AAEA,SAASG,UAAUL,IAAY,EAAEM,GAAW;IAC1C,OAAOA,MAAMN,KAAKI,MAAM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MZ;YACnC;QACF;QACA,IAAIW,IAAI,CAACnF,EAAE,KAAK,KAAK;YACnBA,IAAIiD,SAASkC,MAAMnF,GAAGA,GAAGoF,MAAMZ;YAC/B;QACF;QACAxE,KAAK;IACP;IACA,OAAO;QAAEoF;QAAMV;IAAO;AACxB;AAEA,OAAO,SAASY,gBAAgBH,IAAY;IAC1C,MAAMI,UAAU,IAAId;IACpB,KAAK,MAAMe,OAAON,cAAcC,MAAMC,IAAI,CAAEG,QAAQR,GAAG,CAACS,IAAI7C,WAAW,CAACtC,KAAK,EAAEmF,IAAI7C,WAAW;IAC9F,OAAO;WAAI4C,QAAQE,MAAM;KAAG,CAACC,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKtF,KAAK,GAAGuF,MAAMvF,KAAK;AAC7E"}
@@ -0,0 +1,3 @@
1
+ import type { Document, Projection, ProjectionContext } from './types.js';
2
+ export declare function project(document: Document, file: string, context?: ProjectionContext): Projection;
3
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA8C1E,wBAAgB,OAAO,CACrB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAA2C,GACnD,UAAU,CA0BZ"}
@@ -0,0 +1,96 @@
1
+ import { readDefinition } from './definition.js';
2
+ import { parse } from './document.js';
3
+ import { linkInventory } from './links.js';
4
+ import { classifyHref } from './paths.js';
5
+ import { refusal } from './refuse.js';
6
+ import { headingSpans } from './sections.js';
7
+ import { bodyStartOf } from './yaml.js';
8
+ function internalEdits(body, file, documentTargets) {
9
+ const inventory = linkInventory(body);
10
+ const internal = new Set();
11
+ const edits = [];
12
+ for (const use of inventory.uses){
13
+ const resolved = classifyHref(file, use.destination.href);
14
+ if (resolved.kind !== 'path' || !documentTargets.has(resolved.path)) continue;
15
+ internal.add(use.destination.start);
16
+ edits.push({
17
+ start: use.start,
18
+ end: use.end,
19
+ text: body.slice(use.labelStart, use.labelEnd)
20
+ });
21
+ }
22
+ for (const block of inventory.blocks){
23
+ if (!internal.has(block.destination.start)) continue;
24
+ edits.push({
25
+ start: block.start,
26
+ end: block.end,
27
+ text: ''
28
+ });
29
+ }
30
+ return edits.sort((left, right)=>left.start - right.start);
31
+ }
32
+ function projected(body, spans, edits) {
33
+ let text = '';
34
+ for (const [from, to] of spans){
35
+ let cursor = from;
36
+ for (const edit of edits){
37
+ if (edit.start < cursor || edit.end > to) continue;
38
+ text += body.slice(cursor, edit.start) + edit.text;
39
+ cursor = edit.end;
40
+ }
41
+ text += body.slice(cursor, to);
42
+ }
43
+ return text;
44
+ }
45
+ export function project(document, file, context = {
46
+ documentTargets: []
47
+ }) {
48
+ const bodyStart = bodyStartOf(document.content);
49
+ const body = document.content.slice(bodyStart);
50
+ const edits = internalEdits(body, file, new Set(context.documentTargets));
51
+ const declared = document.type;
52
+ if (declared === undefined) {
53
+ return {
54
+ ok: true,
55
+ text: projected(body, [
56
+ [
57
+ 0,
58
+ body.length
59
+ ]
60
+ ], edits)
61
+ };
62
+ }
63
+ const source = context.definition;
64
+ if (source === undefined) {
65
+ return {
66
+ ok: false,
67
+ refusal: refusal(file, 'unknown-type', {
68
+ location: 'type'
69
+ })
70
+ };
71
+ }
72
+ const definitionFile = `types/${declared}.md`;
73
+ const parsed = parse(source, definitionFile);
74
+ if (!parsed.ok) return {
75
+ ok: false,
76
+ refusal: parsed.refusal
77
+ };
78
+ const definition = readDefinition(definitionFile, parsed.document);
79
+ if ('rule' in definition) return {
80
+ ok: false,
81
+ refusal: definition
82
+ };
83
+ const free = new Set(Object.entries(definition.sections).flatMap(([name, spec])=>spec.kind === 'text' ? [
84
+ name
85
+ ] : []));
86
+ const spans = headingSpans(document.content, bodyStart).filter((span)=>free.has(span.name)).map((span)=>[
87
+ span.headingStart - bodyStart,
88
+ span.bodyEnd - bodyStart
89
+ ]);
90
+ return {
91
+ ok: true,
92
+ text: projected(body, spans, edits)
93
+ };
94
+ }
95
+
96
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdmodel/src/project.ts"],"sourcesContent":["import { readDefinition } from './definition.js';\nimport { parse } from './document.js';\nimport { linkInventory } from './links.js';\nimport { classifyHref } from './paths.js';\nimport { refusal } from './refuse.js';\nimport { headingSpans } from './sections.js';\nimport type { Document, Projection, ProjectionContext } from './types.js';\nimport { bodyStartOf } from './yaml.js';\n\ntype Span = readonly [number, number];\n\ntype Edit = {\n readonly start: number;\n readonly end: number;\n readonly text: string;\n};\n\nfunction internalEdits(body: string, file: string, documentTargets: ReadonlySet<string>): Edit[] {\n const inventory = linkInventory(body);\n const internal = new Set<number>();\n const edits: Edit[] = [];\n for (const use of inventory.uses) {\n const resolved = classifyHref(file, use.destination.href);\n if (resolved.kind !== 'path' || !documentTargets.has(resolved.path)) continue;\n internal.add(use.destination.start);\n edits.push({\n start: use.start,\n end: use.end,\n text: body.slice(use.labelStart, use.labelEnd),\n });\n }\n for (const block of inventory.blocks) {\n if (!internal.has(block.destination.start)) continue;\n edits.push({ start: block.start, end: block.end, text: '' });\n }\n return edits.sort((left, right) => left.start - right.start);\n}\n\nfunction projected(body: string, spans: readonly Span[], edits: readonly Edit[]): string {\n let text = '';\n for (const [from, to] of spans) {\n let cursor = from;\n for (const edit of edits) {\n if (edit.start < cursor || edit.end > to) continue;\n text += body.slice(cursor, edit.start) + edit.text;\n cursor = edit.end;\n }\n text += body.slice(cursor, to);\n }\n return text;\n}\n\nexport function project(\n document: Document,\n file: string,\n context: ProjectionContext = { documentTargets: [] },\n): Projection {\n const bodyStart = bodyStartOf(document.content);\n const body = document.content.slice(bodyStart);\n const edits = internalEdits(body, file, new Set(context.documentTargets));\n const declared = document.type;\n if (declared === undefined) {\n return { ok: true, text: projected(body, [[0, body.length]], edits) };\n }\n const source = context.definition;\n if (source === undefined) {\n return { ok: false, refusal: refusal(file, 'unknown-type', { location: 'type' }) };\n }\n const definitionFile = `types/${declared}.md`;\n const parsed = parse(source, definitionFile);\n if (!parsed.ok) return { ok: false, refusal: parsed.refusal };\n const definition = readDefinition(definitionFile, parsed.document);\n if ('rule' in definition) return { ok: false, refusal: definition };\n const free = new Set(\n Object.entries(definition.sections).flatMap(([name, spec]) =>\n spec.kind === 'text' ? [name] : [],\n ),\n );\n const spans = headingSpans(document.content, bodyStart)\n .filter((span) => free.has(span.name))\n .map((span): Span => [span.headingStart - bodyStart, span.bodyEnd - bodyStart]);\n return { ok: true, text: projected(body, spans, edits) };\n}\n"],"names":["readDefinition","parse","linkInventory","classifyHref","refusal","headingSpans","bodyStartOf","internalEdits","body","file","documentTargets","inventory","internal","Set","edits","use","uses","resolved","destination","href","kind","has","path","add","start","push","end","text","slice","labelStart","labelEnd","block","blocks","sort","left","right","projected","spans","from","to","cursor","edit","project","document","context","bodyStart","content","declared","type","undefined","ok","length","source","definition","location","definitionFile","parsed","free","Object","entries","sections","flatMap","name","spec","filter","span","map","headingStart","bodyEnd"],"mappings":"AAAA,SAASA,cAAc,QAAQ,kBAAkB;AACjD,SAASC,KAAK,QAAQ,gBAAgB;AACtC,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,YAAY,QAAQ,aAAa;AAC1C,SAASC,OAAO,QAAQ,cAAc;AACtC,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,SAASC,WAAW,QAAQ,YAAY;AAUxC,SAASC,cAAcC,IAAY,EAAEC,IAAY,EAAEC,eAAoC;IACrF,MAAMC,YAAYT,cAAcM;IAChC,MAAMI,WAAW,IAAIC;IACrB,MAAMC,QAAgB,EAAE;IACxB,KAAK,MAAMC,OAAOJ,UAAUK,IAAI,CAAE;QAChC,MAAMC,WAAWd,aAAaM,MAAMM,IAAIG,WAAW,CAACC,IAAI;QACxD,IAAIF,SAASG,IAAI,KAAK,UAAU,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ValidationContext = {
3
3
  readonly binaryTargets: readonly string[];
4
4
  };
5
+ export type ProjectionContext = {
6
+ readonly documentTargets: readonly string[];
7
+ readonly definition?: string;
8
+ };
5
9
  export type Document = {
6
10
  readonly content: string;
7
11
  readonly type: string | undefined;
@@ -21,6 +25,13 @@ export type Validation = {
21
25
  } | ({
22
26
  readonly verdict: 'refuse';
23
27
  } & Refusal);
28
+ export type Projection = {
29
+ readonly ok: true;
30
+ readonly text: string;
31
+ } | {
32
+ readonly ok: false;
33
+ readonly refusal: Refusal;
34
+ };
24
35
  export type ParseResult = {
25
36
  readonly ok: true;
26
37
  readonly document: Document;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,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IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,CAAC;AAEN,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAC5D;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdmodel/src/types.ts"],"sourcesContent":["export type Library = Readonly<Record<string, string>>;\n\nexport type ValidationContext = {\n readonly binaryTargets: readonly string[];\n};\n\nexport type Document = {\n readonly content: string;\n readonly type: string | undefined;\n readonly fields: Readonly<Record<string, unknown>>;\n readonly preamble: string;\n readonly sections: Readonly<Record<string, string>>;\n};\n\nexport type Refusal = {\n readonly file: string;\n readonly rule: string;\n readonly version: string;\n readonly location?: string;\n readonly referrers?: readonly string[];\n};\n\nexport type Validation =\n | { readonly verdict: 'accept' }\n | ({ readonly verdict: 'refuse' } & Refusal);\n\nexport type ParseResult =\n | { readonly ok: true; readonly document: Document }\n | { readonly ok: false; readonly refusal: Refusal };\n\nexport type Link = {\n readonly href: string;\n readonly target: string;\n};\n\nexport type Change =\n | {\n readonly kind: 'field';\n readonly name: string;\n readonly value: unknown;\n readonly prior: unknown;\n }\n | {\n readonly kind: 'section';\n readonly name: string;\n readonly value: string;\n readonly prior: string;\n }\n | {\n readonly kind: 'preamble';\n readonly value: string;\n readonly prior: string;\n }\n | {\n readonly kind: 'link';\n readonly href: string;\n readonly to: string;\n };\n\nexport type ApplyResult =\n | { readonly outcome: 'applied'; readonly document: Document }\n | { readonly outcome: 'stale'; readonly document: Document }\n | { readonly outcome: 'refuse'; readonly refusal: Refusal };\n"],"names":[],"mappings":"AA2DA,WAG8D"}
1
+ {"version":3,"sources":["/workspace/packages/mdmodel/src/types.ts"],"sourcesContent":["export type Library = Readonly<Record<string, string>>;\n\nexport type ValidationContext = {\n readonly binaryTargets: readonly string[];\n};\n\nexport type ProjectionContext = {\n readonly documentTargets: readonly string[];\n readonly definition?: string;\n};\n\nexport type Document = {\n readonly content: string;\n readonly type: string | undefined;\n readonly fields: Readonly<Record<string, unknown>>;\n readonly preamble: string;\n readonly sections: Readonly<Record<string, string>>;\n};\n\nexport type Refusal = {\n readonly file: string;\n readonly rule: string;\n readonly version: string;\n readonly location?: string;\n readonly referrers?: readonly string[];\n};\n\nexport type Validation =\n | { readonly verdict: 'accept' }\n | ({ readonly verdict: 'refuse' } & Refusal);\n\nexport type Projection =\n | { readonly ok: true; readonly text: string }\n | { readonly ok: false; readonly refusal: Refusal };\n\nexport type ParseResult =\n | { readonly ok: true; readonly document: Document }\n | { readonly ok: false; readonly refusal: Refusal };\n\nexport type Link = {\n readonly href: string;\n readonly target: string;\n};\n\nexport type Change =\n | {\n readonly kind: 'field';\n readonly name: string;\n readonly value: unknown;\n readonly prior: unknown;\n }\n | {\n readonly kind: 'section';\n readonly name: string;\n readonly value: string;\n readonly prior: string;\n }\n | {\n readonly kind: 'preamble';\n readonly value: string;\n readonly prior: string;\n }\n | {\n readonly kind: 'link';\n readonly href: string;\n readonly to: string;\n };\n\nexport type ApplyResult =\n | { readonly outcome: 'applied'; readonly document: Document }\n | { readonly outcome: 'stale'; readonly document: Document }\n | { readonly outcome: 'refuse'; readonly refusal: Refusal };\n"],"names":[],"mappings":"AAoEA,WAG8D"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.0-alpha.5";
1
+ export declare const VERSION = "0.1.0-alpha.6";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
- export const VERSION = '0.1.0-alpha.5';
1
+ export const VERSION = '0.1.0-alpha.6';
2
2
 
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdmodel/src/version.ts"],"sourcesContent":["export const VERSION = '0.1.0-alpha.5';\n"],"names":["VERSION"],"mappings":"AAAA,OAAO,MAAMA,UAAU,gBAAgB"}
1
+ {"version":3,"sources":["/workspace/packages/mdmodel/src/version.ts"],"sourcesContent":["export const VERSION = '0.1.0-alpha.6';\n"],"names":["VERSION"],"mappings":"AAAA,OAAO,MAAMA,UAAU,gBAAgB"}
@@ -21,6 +21,24 @@ The package check runs every row in ESM, CommonJS, and the browser-target VM
21
21
  bundle, also checking stale priors, immutable Documents, and conversion of the
22
22
  Runtime link rewrite into a preamble operation through public APIs.
23
23
 
24
+ ## Projection
25
+
26
+ `projection.json` exercises the public `project` seam separately from the
27
+ validation Libraries. It carries `definitions`, the MD Type definition sources
28
+ keyed by a label, and `cases`. Each case carries `name`, the `file` the Document
29
+ sits at, exact `source`, the `documentTargets` the collection holds as Markdown
30
+ documents, the `definition` label or `null`, an optional `move`, and `expected`.
31
+ A case carrying a `move` lists both the Path its target sits at and the Path the
32
+ move takes it to, because the collection holds that target either way.
33
+
34
+ Parse the source, call `project(document, file, context)` with
35
+ `{ documentTargets, definition }`, and compare against `expected`, replacing the
36
+ `<package-version>` token in a refusal the same way `cases/` does. Then check
37
+ that the source is unchanged. Where `move` is present, apply
38
+ `{ kind: 'link', href, to }`, confirm the serialized Document changed, and
39
+ confirm the projection of the moved Document is still exactly `expected`: a
40
+ moved Path rewrites destinations and leaves the projection alone.
41
+
24
42
  ## Verdict format
25
43
 
26
44
  Acceptance:
@@ -0,0 +1,156 @@
1
+ {
2
+ "definitions": {
3
+ "task": "---\ntype: definition\nfields:\n title: { kind: string, required: true }\n status: { kind: enum, values: [open, done], required: true }\n owner: { kind: reference, to: person }\nsections:\n Description: { kind: text, required: true }\n Acceptance: { kind: list }\n---\n",
4
+ "unreadable-task": "---\ntype: definition\nsections:\n Description: { kind: prose }\n---\n"
5
+ },
6
+ "cases": [
7
+ {
8
+ "name": "any body keeps labels and leaves every unsupplied destination authored",
9
+ "file": "notes/one.md",
10
+ "source": "---\ntitle: Note\n---\n\nRead [the plan](../plans/q3.md#goals \"Plan\") and ![the figure](../assets/figure.png).\nSee the [site](https://example.com/x.md) and this [anchor](#here).\nAn [unheld draft](../plans/draft.md) keeps the destination nobody supplied.\nEscaped \\[the plan\\](../plans/q3.md) stays, and so does `[the plan](../plans/q3.md)`.\n\n```sh\ncat [the plan](../plans/q3.md)\n```\n",
11
+ "documentTargets": [
12
+ "plans/q3.md",
13
+ "plans/2026-q3.md"
14
+ ],
15
+ "definition": null,
16
+ "move": {
17
+ "href": "../plans/q3.md#goals",
18
+ "to": "../plans/2026-q3.md"
19
+ },
20
+ "expected": {
21
+ "ok": true,
22
+ "text": "\nRead the plan and ![the figure](../assets/figure.png).\nSee the [site](https://example.com/x.md) and this [anchor](#here).\nAn [unheld draft](../plans/draft.md) keeps the destination nobody supplied.\nEscaped \\[the plan\\](../plans/q3.md) stays, and so does `[the plan](../plans/q3.md)`.\n\n```sh\ncat [the plan](../plans/q3.md)\n```\n"
23
+ }
24
+ },
25
+ {
26
+ "name": "any body without frontmatter projects from its first character",
27
+ "file": "notes/two.md",
28
+ "source": "# Title\n\nSee [the plan](plans/q3.md).\n",
29
+ "documentTargets": [
30
+ "notes/plans/q3.md",
31
+ "notes/plans/2026-q3.md"
32
+ ],
33
+ "definition": null,
34
+ "move": {
35
+ "href": "plans/q3.md",
36
+ "to": "plans/2026-q3.md"
37
+ },
38
+ "expected": {
39
+ "ok": true,
40
+ "text": "# Title\n\nSee the plan.\n"
41
+ }
42
+ },
43
+ {
44
+ "name": "typed Document takes its declared free-text sections alone",
45
+ "file": "tasks/one.md",
46
+ "source": "---\ntype: task\ntitle: Ship it\nstatus: open\nowner: ../people/ana.md\n---\n\nPreamble prose that mentions [the plan](../plans/q3.md).\n\n## Description\n\nFollow [the plan][plan] and [the plan][plan] again, then [read it][].\n\n[plan]: ../plans/q3.md \"Plan\"\n[read it]: ../plans/q3.md\n\n## Acceptance\n\n- [the plan](../plans/q3.md) is linked\n\n## Notes\n\nUndeclared prose about [the plan](../plans/q3.md).\n",
47
+ "documentTargets": [
48
+ "plans/q3.md",
49
+ "plans/2026-q3.md"
50
+ ],
51
+ "definition": "task",
52
+ "move": {
53
+ "href": "../plans/q3.md",
54
+ "to": "../plans/2026-q3.md"
55
+ },
56
+ "expected": {
57
+ "ok": true,
58
+ "text": "## Description\n\nFollow the plan and the plan again, then read it.\n\n\n"
59
+ }
60
+ },
61
+ {
62
+ "name": "a link definition outside the projected sections still resolves its use",
63
+ "file": "tasks/two.md",
64
+ "source": "---\ntype: task\ntitle: Ship it\nstatus: open\n---\n\n## Description\n\nFollow [the plan][plan].\n\n## Notes\n\n[plan]: ../plans/q3.md\n",
65
+ "documentTargets": [
66
+ "plans/q3.md",
67
+ "plans/2026-q3.md"
68
+ ],
69
+ "definition": "task",
70
+ "move": {
71
+ "href": "../plans/q3.md",
72
+ "to": "../plans/2026-q3.md"
73
+ },
74
+ "expected": {
75
+ "ok": true,
76
+ "text": "## Description\n\nFollow the plan.\n\n"
77
+ }
78
+ },
79
+ {
80
+ "name": "every occurrence of a declared free-text section is projected",
81
+ "file": "tasks/three.md",
82
+ "source": "---\ntype: task\ntitle: Ship it\nstatus: open\n---\n\n## Description\n\nFirst [plan](../plans/q3.md).\n\n## Description\n\nSecond note.\n",
83
+ "documentTargets": [
84
+ "plans/q3.md",
85
+ "plans/2026-q3.md"
86
+ ],
87
+ "definition": "task",
88
+ "move": {
89
+ "href": "../plans/q3.md",
90
+ "to": "../plans/2026-q3.md"
91
+ },
92
+ "expected": {
93
+ "ok": true,
94
+ "text": "## Description\n\nFirst plan.\n\n## Description\n\nSecond note.\n"
95
+ }
96
+ },
97
+ {
98
+ "name": "a declared type the caller does not supply is refused",
99
+ "file": "tasks/one.md",
100
+ "source": "---\ntype: task\ntitle: Ship it\nstatus: open\nowner: ../people/ana.md\n---\n\nPreamble prose that mentions [the plan](../plans/q3.md).\n\n## Description\n\nFollow [the plan][plan] and [the plan][plan] again, then [read it][].\n\n[plan]: ../plans/q3.md \"Plan\"\n[read it]: ../plans/q3.md\n\n## Acceptance\n\n- [the plan](../plans/q3.md) is linked\n\n## Notes\n\nUndeclared prose about [the plan](../plans/q3.md).\n",
101
+ "documentTargets": [
102
+ "plans/q3.md",
103
+ "plans/2026-q3.md"
104
+ ],
105
+ "definition": null,
106
+ "move": null,
107
+ "expected": {
108
+ "ok": false,
109
+ "refusal": {
110
+ "file": "tasks/one.md",
111
+ "rule": "unknown-type",
112
+ "version": "<package-version>",
113
+ "location": "type"
114
+ }
115
+ }
116
+ },
117
+ {
118
+ "name": "a definition the model cannot read is refused at that definition",
119
+ "file": "tasks/one.md",
120
+ "source": "---\ntype: task\ntitle: Ship it\nstatus: open\nowner: ../people/ana.md\n---\n\nPreamble prose that mentions [the plan](../plans/q3.md).\n\n## Description\n\nFollow [the plan][plan] and [the plan][plan] again, then [read it][].\n\n[plan]: ../plans/q3.md \"Plan\"\n[read it]: ../plans/q3.md\n\n## Acceptance\n\n- [the plan](../plans/q3.md) is linked\n\n## Notes\n\nUndeclared prose about [the plan](../plans/q3.md).\n",
121
+ "documentTargets": [
122
+ "plans/q3.md",
123
+ "plans/2026-q3.md"
124
+ ],
125
+ "definition": "unreadable-task",
126
+ "move": null,
127
+ "expected": {
128
+ "ok": false,
129
+ "refusal": {
130
+ "file": "types/task.md",
131
+ "rule": "definition-section-kind",
132
+ "version": "<package-version>",
133
+ "location": "Description"
134
+ }
135
+ }
136
+ },
137
+ {
138
+ "name": "an image at a supplied Markdown document target is projected like its link",
139
+ "file": "notes/four.md",
140
+ "source": "Read [the plan](../plans/q3.md) and ![the chart](../plans/q3.md).\nAlso [the plan][plan] and ![the chart][plan].\n\n[plan]: ../plans/q3.md\n",
141
+ "documentTargets": [
142
+ "plans/q3.md",
143
+ "plans/2026-q3.md"
144
+ ],
145
+ "definition": null,
146
+ "move": {
147
+ "href": "../plans/q3.md",
148
+ "to": "../plans/2026-q3.md"
149
+ },
150
+ "expected": {
151
+ "ok": true,
152
+ "text": "Read the plan and the chart.\nAlso the plan and the chart.\n\n"
153
+ }
154
+ }
155
+ ]
156
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdmodel",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "MD Type language, parser, validator, structured change application, Markdown syntax profile, and conformance fixtures",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  "access": "public"
10
10
  },
11
11
  "engines": {
12
- "node": ">=24.20.0"
12
+ "node": ">=24.21.0"
13
13
  },
14
14
  "exports": {
15
15
  ".": {