@orkestrel/markdown 0.0.12 → 0.0.13

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.
@@ -13,18 +13,18 @@ import { OptionalShape } from '@orkestrel/contract';
13
13
  import { StringShape } from '@orkestrel/contract';
14
14
  import { TextNode as TextNode_2 } from '@orkestrel/html';
15
15
 
16
- /** A node that can appear at the block level of a document (or inside a list item / blockquote). */
16
+ /** Represents a node that can appear at the block level of a document (or inside a list item / blockquote). */
17
17
  export declare type BlockNode = HeadingNode | ParagraphNode | ListNode | TableNode | CodeBlockNode | BlockquoteNode | ThematicBreakNode;
18
18
 
19
- /** A blockquote - `>`-prefixed lines; `children` the block content parsed from the de-quoted lines (so quotes nest). */
19
+ /** Represents a blockquote - `>`-prefixed lines; `children` the block content parsed from the de-quoted lines (so quotes nest). */
20
20
  export declare interface BlockquoteNode {
21
21
  readonly element: 'blockquote';
22
- /** The block content of the quote (the `>`-stripped lines, re-parsed as blocks). */
22
+ /** Holds the block content of the quote (the `>`-stripped lines, re-parsed as blocks). */
23
23
  readonly children: readonly BlockNode[];
24
24
  }
25
25
 
26
26
  /**
27
- * Merge adjacent text nodes into one - the inline scanner emits a text node per
27
+ * Merges adjacent text nodes into one - the inline scanner emits a text node per
28
28
  * unrecognized character, so coalescing keeps the AST clean and assertion-friendly.
29
29
  *
30
30
  * @param nodes - The inline nodes (possibly with adjacent text runs)
@@ -40,21 +40,21 @@ export declare interface BlockquoteNode {
40
40
  export declare function coalesceText(nodes: readonly InlineNode[], spans?: Map<MarkdownNode, MarkdownSpan>): readonly InlineNode[];
41
41
 
42
42
  /**
43
- * A fenced code block - ```` ```lang ````. `code` is the verbatim block content (no
43
+ * Represents a fenced code block - ```` ```lang ````. `code` is the verbatim block content (no
44
44
  * inner markdown; the closing fence and the trailing newline are stripped), `lang`
45
45
  * the info-string language tag (the first word after the opening fence), absent when
46
46
  * none was given.
47
47
  */
48
48
  export declare interface CodeBlockNode {
49
49
  readonly element: 'codeBlock';
50
- /** The info-string language tag (first word after the opening fence), if any. */
50
+ /** Holds the info-string language tag (first word after the opening fence), if any. */
51
51
  readonly lang?: string;
52
- /** The verbatim code content (no inner markdown; HTML-escaped at render). */
52
+ /** Holds the verbatim code content (no inner markdown; HTML-escaped at render). */
53
53
  readonly code: string;
54
54
  }
55
55
 
56
56
  /**
57
- * The shape of a {@link CodeBlockNode} - a fenced code block. `lang` is
57
+ * Describes the shape of a {@link CodeBlockNode} - a fenced code block. `lang` is
58
58
  * optional (absent when the opening fence carries no info-string).
59
59
  *
60
60
  * @example
@@ -74,18 +74,29 @@ export declare const codeBlockShape: ObjectShape<{
74
74
  }, false>;
75
75
 
76
76
  /**
77
- * An inline code span - `` `code` ``. `value` is the verbatim span text; no inner
77
+ * Represents the located extent of one inline code span - the value the inline phase's code
78
+ * scanner returns for a matched backtick run.
79
+ */
80
+ export declare interface CodeSpanMatch {
81
+ /** Holds the span's literal text, with one padding space stripped from each end. */
82
+ readonly value: string;
83
+ /** Holds the index one past the span's closing backtick run, exclusive. */
84
+ readonly end: number;
85
+ }
86
+
87
+ /**
88
+ * Represents an inline code span - `` `code` ``. `value` is the verbatim span text; no inner
78
89
  * markdown is parsed (code is literal), and the renderer HTML-escapes it inside a
79
90
  * `<code>` element.
80
91
  */
81
92
  export declare interface CodeSpanNode {
82
93
  readonly element: 'codeSpan';
83
- /** The verbatim code text (no inner markdown; HTML-escaped at render). */
94
+ /** Holds the verbatim code text (no inner markdown; HTML-escaped at render). */
84
95
  readonly value: string;
85
96
  }
86
97
 
87
98
  /**
88
- * The shape of a {@link CodeSpanNode} - an inline code span (`` `code` ``).
99
+ * Describes the shape of a {@link CodeSpanNode} - an inline code span (`` `code` ``).
89
100
  *
90
101
  * @example
91
102
  * ```ts
@@ -117,10 +128,7 @@ export declare const codeSpanShape: ObjectShape<{
117
128
  * collectList(splitLines('- item'), 0, 0) // { node: { element: 'list', ... }, next: 1 }
118
129
  * ```
119
130
  */
120
- export declare function collectList(lines: readonly MarkdownSource[], start: number, depth: number, spans?: Map<MarkdownNode, MarkdownSpan>, end?: number): {
121
- readonly node: ListNode;
122
- readonly next: number;
123
- };
131
+ export declare function collectList(lines: readonly MarkdownSource[], start: number, depth: number, spans?: Map<MarkdownNode, MarkdownSpan>, end?: number): ListCollection;
124
132
 
125
133
  /**
126
134
  * Collects a GFM table starting at a header row, parsing the header, the
@@ -136,13 +144,10 @@ export declare function collectList(lines: readonly MarkdownSource[], start: num
136
144
  * collectTable(splitLines('| a |\n| - |'), 0) // { node: { element: 'table', ... }, next: 2 }
137
145
  * ```
138
146
  */
139
- export declare function collectTable(lines: readonly MarkdownSource[], start: number, spans?: Map<MarkdownNode, MarkdownSpan>): {
140
- readonly node: TableNode;
141
- readonly next: number;
142
- };
147
+ export declare function collectTable(lines: readonly MarkdownSource[], start: number, spans?: Map<MarkdownNode, MarkdownSpan>): TableCollection;
143
148
 
144
149
  /**
145
- * The count of leading space / tab characters on `line` (a tab counts as one) - the
150
+ * Counts the leading space / tab characters on `line` (a tab counts as one) - the
146
151
  * indent that decides whether a list item's continuation belongs to the item.
147
152
  *
148
153
  * @param line - The line to measure
@@ -156,9 +161,9 @@ export declare function collectTable(lines: readonly MarkdownSource[], start: nu
156
161
  export declare function countIndent(line: string): number;
157
162
 
158
163
  /**
159
- * Compile the {@link codeBlockShape} into a {@link ContractInterface} for
164
+ * Compiles the {@link codeBlockShape} into a {@link ContractInterface} for
160
165
  * {@link CodeBlockNode} - a guard, coercing parser, JSON Schema, and seeded
161
- * generator from one shape declaration (AGENTS §14).
166
+ * generator from one shape declaration.
162
167
  *
163
168
  * @returns A `CodeBlockNode` contract bundling `schema` / `is` / `parse` / `generate`
164
169
  *
@@ -173,9 +178,9 @@ export declare function countIndent(line: string): number;
173
178
  export declare function createCodeBlockContract(): ContractInterface<CodeBlockNode>;
174
179
 
175
180
  /**
176
- * Compile the {@link codeSpanShape} into a {@link ContractInterface} for
181
+ * Compiles the {@link codeSpanShape} into a {@link ContractInterface} for
177
182
  * {@link CodeSpanNode} - a guard, coercing parser, JSON Schema, and seeded
178
- * generator from one shape declaration (AGENTS §14).
183
+ * generator from one shape declaration.
179
184
  *
180
185
  * @returns A `CodeSpanNode` contract bundling `schema` / `is` / `parse` / `generate`
181
186
  *
@@ -190,7 +195,7 @@ export declare function createCodeBlockContract(): ContractInterface<CodeBlockNo
190
195
  export declare function createCodeSpanContract(): ContractInterface<CodeSpanNode>;
191
196
 
192
197
  /**
193
- * Compile the {@link lineBreakShape} into a {@link ContractInterface} for
198
+ * Compiles the {@link lineBreakShape} into a {@link ContractInterface} for
194
199
  * {@link LineBreakNode}.
195
200
  *
196
201
  * @returns A `LineBreakNode` contract bundling `schema` / `is` / `parse` / `generate`
@@ -205,7 +210,7 @@ export declare function createCodeSpanContract(): ContractInterface<CodeSpanNode
205
210
  export declare function createLineBreakContract(): ContractInterface<LineBreakNode>;
206
211
 
207
212
  /**
208
- * Create a stateful markdown handle from a markdown string or an already-parsed
213
+ * Creates a stateful markdown handle from a markdown string or an already-parsed
209
214
  * {@link MarkdownDocument} - a typed AST plus the query, rewrite, and fold operations
210
215
  * {@link MarkdownInterface} exposes.
211
216
  *
@@ -233,7 +238,7 @@ export declare function createLineBreakContract(): ContractInterface<LineBreakNo
233
238
  export declare function createMarkdown(input: string | MarkdownDocument): MarkdownInterface;
234
239
 
235
240
  /**
236
- * Create an HTML-to-markdown projection with absent fields defaulted from
241
+ * Builds an HTML-to-markdown projection with absent fields defaulted from
237
242
  * {@link EMPTY_PROJECTION} and the block/inline exclusivity invariant enforced.
238
243
  *
239
244
  * @remarks
@@ -255,9 +260,9 @@ export declare function createMarkdown(input: string | MarkdownDocument): Markdo
255
260
  export declare function createProjection(parts?: Partial<MarkdownProjection>): MarkdownProjection;
256
261
 
257
262
  /**
258
- * Compile the {@link textShape} into a {@link ContractInterface} for
263
+ * Compiles the {@link textShape} into a {@link ContractInterface} for
259
264
  * {@link TextNode} - a guard, coercing parser, JSON Schema, and seeded
260
- * generator from one shape declaration (AGENTS §14).
265
+ * generator from one shape declaration.
261
266
  *
262
267
  * @returns A `TextNode` contract bundling `schema` / `is` / `parse` / `generate`
263
268
  *
@@ -272,9 +277,9 @@ export declare function createProjection(parts?: Partial<MarkdownProjection>): M
272
277
  export declare function createTextContract(): ContractInterface<TextNode>;
273
278
 
274
279
  /**
275
- * Compile the {@link thematicBreakShape} into a {@link ContractInterface} for
280
+ * Compiles the {@link thematicBreakShape} into a {@link ContractInterface} for
276
281
  * {@link ThematicBreakNode} - a guard, coercing parser, JSON Schema, and
277
- * seeded generator from one shape declaration (AGENTS §14).
282
+ * seeded generator from one shape declaration.
278
283
  *
279
284
  * @returns A `ThematicBreakNode` contract bundling `schema` / `is` / `parse` / `generate`
280
285
  *
@@ -289,7 +294,7 @@ export declare function createTextContract(): ContractInterface<TextNode>;
289
294
  export declare function createThematicBreakContract(): ContractInterface<ThematicBreakNode>;
290
295
 
291
296
  /**
292
- * Derive the per-column {@link TableAlign} list from a GFM delimiter row - `:---`
297
+ * Derives the per-column {@link TableAlign} list from a GFM delimiter row - `:---`
293
298
  * left, `---:` right, `:---:` center, and `---` as the explicit no-alignment
294
299
  * marker represented by `null`.
295
300
  *
@@ -304,21 +309,47 @@ export declare function createThematicBreakContract(): ContractInterface<Themati
304
309
  export declare function delimiterToAlignments(delimiter: string): ReadonlyArray<TableAlign | null>;
305
310
 
306
311
  /**
307
- * Emphasized inline content - `*italic*` / `_italic_` (`strong: false`) or
312
+ * Represents the located content and syntax bounds of one emphasis run - the value the inline
313
+ * phase's emphasis locator returns for a matched marker run.
314
+ */
315
+ export declare interface EmphasisBounds {
316
+ /** Holds `true` for a doubled marker (`**strong**`), `false` for a single one (`*em*`). */
317
+ readonly strong: boolean;
318
+ /** Holds the index of the run's first content character. */
319
+ readonly open: number;
320
+ /** Holds the index of the closing marker run's first character. */
321
+ readonly close: number;
322
+ /** Holds the index one past the closing marker run, exclusive. */
323
+ readonly end: number;
324
+ }
325
+
326
+ /**
327
+ * Represents emphasized inline content - `*italic*` / `_italic_` (`strong: false`) or
308
328
  * `**bold**` / `__bold__` (`strong: true`). `children` are the nested inline nodes,
309
329
  * so emphasis composes (a `**bold _and italic_**` is a strong node wrapping a text
310
330
  * node and an emphasis node).
311
331
  */
312
332
  export declare interface EmphasisNode {
313
333
  readonly element: 'emphasis';
314
- /** `true` for strong (`**` / `__`, → `<strong>`); `false` for ordinary emphasis (`*` / `_`, → `<em>`). */
334
+ /** Holds `true` for strong (`**` / `__`, → `<strong>`); `false` for ordinary emphasis (`*` / `_`, → `<em>`). */
315
335
  readonly strong: boolean;
316
- /** The emphasized inline content. */
336
+ /** Holds the emphasized inline content. */
317
337
  readonly children: readonly InlineNode[];
318
338
  }
319
339
 
320
340
  /**
321
- * The frozen empty HTML-to-markdown projection from which projection factories
341
+ * Represents the scanned result of one emphasis run - the node the inline phase's emphasis
342
+ * scanner built from {@link EmphasisBounds} and where the scan resumes.
343
+ */
344
+ export declare interface EmphasisScan {
345
+ /** Holds the scanned emphasis run, its content already scanned into inline children. */
346
+ readonly node: EmphasisNode;
347
+ /** Holds the index one past the closing marker run, exclusive. */
348
+ readonly end: number;
349
+ }
350
+
351
+ /**
352
+ * Holds the frozen empty HTML-to-markdown projection from which projection factories
322
353
  * default every absent field.
323
354
  *
324
355
  * @example
@@ -330,7 +361,7 @@ export declare interface EmphasisNode {
330
361
  export declare const EMPTY_PROJECTION: MarkdownProjection;
331
362
 
332
363
  /**
333
- * Extract a fenced-code opening line (```` ``` ```` or `~~~`, optionally with an info
364
+ * Extracts a fenced-code opening line (```` ``` ```` or `~~~`, optionally with an info
334
365
  * string) into its `{ marker, lang }`, or `undefined` when `line` is not a fence
335
366
  * opener. `marker` is the exact fence run (the closer must match the same character +
336
367
  * at least the same length); `lang` is the first word of the info string.
@@ -343,10 +374,7 @@ export declare const EMPTY_PROJECTION: MarkdownProjection;
343
374
  * extractFence('```ts') // { marker: '```', lang: 'ts' }
344
375
  * ```
345
376
  */
346
- export declare function extractFence(line: string): {
347
- readonly marker: string;
348
- readonly lang: string | undefined;
349
- } | undefined;
377
+ export declare function extractFence(line: string): FenceMatch | undefined;
350
378
 
351
379
  /**
352
380
  * Extracts an ATX heading line (`#` … `######` followed by text) into its level,
@@ -362,14 +390,10 @@ export declare function extractFence(line: string): {
362
390
  * extractHeading('## Title') // { level: 2, text: 'Title', offset: 3 }
363
391
  * ```
364
392
  */
365
- export declare function extractHeading(line: string): {
366
- readonly level: number;
367
- readonly text: string;
368
- readonly offset: number;
369
- } | undefined;
393
+ export declare function extractHeading(line: string): HeadingMatch | undefined;
370
394
 
371
395
  /**
372
- * Extract a list-item line (`-` / `*` / `+` bullet, or `1.` / `1)` ordinal, followed by
396
+ * Extracts a list-item line (`-` / `*` / `+` bullet, or `1.` / `1)` ordinal, followed by
373
397
  * a space) into its {@link ListItemMatch}, or `undefined` when `line` is not a list
374
398
  * item. `content` is the text after the marker; `marker` is the full marker-plus-space
375
399
  * width (for measuring a continuation's indent).
@@ -385,7 +409,18 @@ export declare function extractHeading(line: string): {
385
409
  export declare function extractListItem(line: string): ListItemMatch | undefined;
386
410
 
387
411
  /**
388
- * Concatenate the `value` / `code` content of every descendant text / code-span /
412
+ * Represents the parsed parts of a fenced-code opening line - the value the block phase's fence
413
+ * detector returns for a ```` ``` ```` or `~~~` opener.
414
+ */
415
+ export declare interface FenceMatch {
416
+ /** Holds the exact fence run; a closer must repeat the same character at least as long. */
417
+ readonly marker: string;
418
+ /** Holds the first word of the info string, or `undefined` when the fence declares none. */
419
+ readonly lang: string | undefined;
420
+ }
421
+
422
+ /**
423
+ * Concatenates the `value` / `code` content of every descendant text / code-span /
389
424
  * code-block node under `node`, including image alternative content, in walk order -
390
425
  * the plain-text projection of an AST (search indexing, word counts, a text-only
391
426
  * preview).
@@ -409,7 +444,7 @@ export declare function extractListItem(line: string): ListItemMatch | undefined
409
444
  export declare function flattenText(node: MarkdownNode): string;
410
445
 
411
446
  /**
412
- * Fold a {@link MarkdownNode} into a `T` via a total catamorphism - children are
447
+ * Folds a {@link MarkdownNode} into a `T` through a total catamorphism - children are
413
448
  * folded first (post-order), then the node's own {@link MarkdownHandler} is invoked
414
449
  * with the already-folded children.
415
450
  *
@@ -426,35 +461,48 @@ export declare function flattenText(node: MarkdownNode): string;
426
461
  * with an empty children list instead of recursing further.
427
462
  *
428
463
  * @param node - The AST node to fold
429
- * @param handlers - The total {@link MarkdownHandlers} table, one handler per element
464
+ * @param handlers - The total {@link MarkdownHandlerMap} table, one handler per element
430
465
  * @param depth - The starting recursion depth (pass `0` at the entry point)
431
466
  * @returns The folded `T`
432
467
  *
433
468
  * @example
434
469
  * ```ts
435
- * const countHandlers: MarkdownHandlers<number> = {
470
+ * const countHandlers: MarkdownHandlerMap<number> = {
436
471
  * document: (_, children) => children.reduce((a, b) => a + b, 1),
437
472
  * // ...one handler per element, each summing its folded children
438
473
  * }
439
474
  * foldNode(document, countHandlers, 0) // total node count
440
475
  * ```
441
476
  */
442
- export declare function foldNode<T>(node: MarkdownNode, handlers: MarkdownHandlers<T>, depth: number): T;
477
+ export declare function foldNode<T>(node: MarkdownNode, handlers: MarkdownHandlerMap<T>, depth: number): T;
443
478
 
444
479
  /**
445
- * An ATX heading - `#` `######`. `level` is 1–6 (the number of leading `#`),
480
+ * Represents the parsed parts of a single ATX heading line - the value the block phase's heading
481
+ * detector returns for a `#` … `######` line.
482
+ */
483
+ export declare interface HeadingMatch {
484
+ /** Holds the heading's level, 1 to 6. */
485
+ readonly level: number;
486
+ /** Holds the heading's raw inline text, with an optional closing `#` run stripped. */
487
+ readonly text: string;
488
+ /** Holds the offset of {@link HeadingMatch.text} inside the original line. */
489
+ readonly offset: number;
490
+ }
491
+
492
+ /**
493
+ * Represents an ATX heading - `#` … `######`. `level` is 1–6 (the number of leading `#`),
446
494
  * `children` the inline content of the heading text.
447
495
  */
448
496
  export declare interface HeadingNode {
449
497
  readonly element: 'heading';
450
- /** The heading level, 1 (`#`) through 6 (`######`). */
498
+ /** Holds the heading level, 1 (`#`) through 6 (`######`). */
451
499
  readonly level: number;
452
- /** The inline content of the heading text. */
500
+ /** Holds the inline content of the heading text. */
453
501
  readonly children: readonly InlineNode[];
454
502
  }
455
503
 
456
504
  /**
457
- * Project an `@orkestrel/html` {@link HTMLNode} into a {@link MarkdownDocument} - the
505
+ * Projects an `@orkestrel/html` {@link HTMLNode} into a {@link MarkdownDocument} - the
458
506
  * HTML→markdown direction, and the inverse of {@link markdownToHTML}.
459
507
  *
460
508
  * @remarks
@@ -500,27 +548,27 @@ export declare interface HeadingNode {
500
548
  export declare function htmlToMarkdown(node: HTMLNode): MarkdownDocument;
501
549
 
502
550
  /**
503
- * An inline image - `![alt](src)`. `children` are the inline nodes of the
551
+ * Represents an inline image - `![alt](src)`. `children` are the inline nodes of the
504
552
  * alternative content and `src` is the image destination.
505
553
  */
506
554
  export declare interface ImageNode {
507
555
  readonly element: 'image';
508
- /** The image destination. */
556
+ /** Holds the image destination. */
509
557
  readonly src: string;
510
- /** The inline alternative content. */
558
+ /** Holds the inline alternative content. */
511
559
  readonly children: readonly InlineNode[];
512
560
  }
513
561
 
514
- /** A node that can appear inside inline content (a heading / paragraph / cell / list item / link text). */
562
+ /** Represents a node that can appear inside inline content (a heading / paragraph / cell / list item / link text). */
515
563
  export declare type InlineNode = TextNode | EmphasisNode | CodeSpanNode | LineBreakNode | LinkNode | ImageNode;
516
564
 
517
565
  /**
518
- * Whether `line` is blank - empty, or containing only whitespace - the markdown
566
+ * Checks whether `line` is blank - empty, or containing only whitespace - the markdown
519
567
  * definition of a blank line that block parsing uses to separate paragraphs, skip
520
568
  * gaps, and end list continuations.
521
569
  *
522
570
  * @param line - The candidate line
523
- * @returns `true` when the line is blank
571
+ * @returns True if the line is blank; false otherwise
524
572
  *
525
573
  * @example
526
574
  * ```ts
@@ -530,19 +578,19 @@ export declare type InlineNode = TextNode | EmphasisNode | CodeSpanNode | LineBr
530
578
  export declare function isBlankLine(line: string): boolean;
531
579
 
532
580
  /**
533
- * Determine whether an arbitrary value is a valid {@link BlockNode} - a
581
+ * Determines whether an arbitrary value is a valid {@link BlockNode} - a
534
582
  * heading, paragraph, list, table, code block, blockquote, or thematic break,
535
583
  * recursively validated.
536
584
  *
537
585
  * @remarks
538
586
  * Total: never throws, even on cyclic or pathologically deep input - every
539
587
  * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is
540
- * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).
588
+ * throw-contained per the `@orkestrel/contract` guard contract.
541
589
  * A list item's shape is inlined here (and in {@link isMarkdownNode}) rather
542
590
  * than named separately - it is used at exactly these two sites.
543
591
  *
544
592
  * @param value - The value to test
545
- * @returns `true` when `value` is a well-formed {@link BlockNode}
593
+ * @returns True if `value` is a well-formed {@link BlockNode}; false otherwise
546
594
  *
547
595
  * @example
548
596
  * ```ts
@@ -555,7 +603,10 @@ export declare function isBlankLine(line: string): boolean;
555
603
  export declare const isBlockNode: Guard<BlockNode>;
556
604
 
557
605
  /**
558
- * Determine whether a node is a blockquote block.
606
+ * Determines whether a node is a blockquote block.
607
+ *
608
+ * @param node - The AST node to test
609
+ * @returns True if the node is a {@link BlockquoteNode}; false otherwise
559
610
  *
560
611
  * @example
561
612
  * ```ts
@@ -565,7 +616,10 @@ export declare const isBlockNode: Guard<BlockNode>;
565
616
  export declare function isBlockquoteNode(node: MarkdownNode): node is BlockquoteNode;
566
617
 
567
618
  /**
568
- * Determine whether a node is a fenced code block.
619
+ * Determines whether a node is a fenced code block.
620
+ *
621
+ * @param node - The AST node to test
622
+ * @returns True if the node is a {@link CodeBlockNode}; false otherwise
569
623
  *
570
624
  * @example
571
625
  * ```ts
@@ -575,12 +629,15 @@ export declare function isBlockquoteNode(node: MarkdownNode): node is Blockquote
575
629
  export declare function isCodeBlockNode(node: MarkdownNode): node is CodeBlockNode;
576
630
 
577
631
  /**
578
- * Determine whether a node is an inline code span.
632
+ * Determines whether a node is an inline code span.
579
633
  *
580
634
  * @remarks
581
635
  * Narrows to {@link CodeSpanNode} - the node whose `element` discriminant is
582
636
  * `'codeSpan'`.
583
637
  *
638
+ * @param node - The AST node to test
639
+ * @returns True if the node is a {@link CodeSpanNode}; false otherwise
640
+ *
584
641
  * @example
585
642
  * ```ts
586
643
  * isCodeSpanNode({ element: 'codeSpan', value: 'x' }) // true
@@ -589,7 +646,10 @@ export declare function isCodeBlockNode(node: MarkdownNode): node is CodeBlockNo
589
646
  export declare function isCodeSpanNode(node: MarkdownNode): node is CodeSpanNode;
590
647
 
591
648
  /**
592
- * Determine whether a node is an emphasis run (`*em*` / `**strong**`).
649
+ * Determines whether a node is an emphasis run (`*em*` / `**strong**`).
650
+ *
651
+ * @param node - The AST node to test
652
+ * @returns True if the node is an {@link EmphasisNode}; false otherwise
593
653
  *
594
654
  * @example
595
655
  * ```ts
@@ -599,11 +659,11 @@ export declare function isCodeSpanNode(node: MarkdownNode): node is CodeSpanNode
599
659
  export declare function isEmphasisNode(node: MarkdownNode): node is EmphasisNode;
600
660
 
601
661
  /**
602
- * Whether `character` is escapable by a leading backslash - the ASCII punctuation
662
+ * Checks whether `character` is escapable by a leading backslash - the ASCII punctuation
603
663
  * markdown gives meaning to (so `\*` becomes `*` but `\.` stays `\.`).
604
664
  *
605
665
  * @param character - The single character after a backslash
606
- * @returns `true` when a backslash before it is an escape
666
+ * @returns True if a backslash before it is an escape; false otherwise
607
667
  *
608
668
  * @example
609
669
  * ```ts
@@ -614,12 +674,12 @@ export declare function isEmphasisNode(node: MarkdownNode): node is EmphasisNode
614
674
  export declare function isEscapable(character: string): boolean;
615
675
 
616
676
  /**
617
- * Whether `line` closes a fence opened by `marker` - the same fence character, a run
677
+ * Checks whether `line` closes a fence opened by `marker` - the same fence character, a run
618
678
  * at least as long, and nothing else but surrounding whitespace.
619
679
  *
620
680
  * @param line - The candidate closing line
621
681
  * @param marker - The opening fence's marker run (from {@link extractFence})
622
- * @returns `true` when `line` closes the fence
682
+ * @returns True if `line` closes the fence; false otherwise
623
683
  *
624
684
  * @example
625
685
  * ```ts
@@ -629,11 +689,11 @@ export declare function isEscapable(character: string): boolean;
629
689
  export declare function isFenceClose(line: string, marker: string): boolean;
630
690
 
631
691
  /**
632
- * Whether `character` is a regex-`\s`-equivalent whitespace character - the
692
+ * Checks whether `character` is a regex-`\s`-equivalent whitespace character - the
633
693
  * character class {@link isFenceClose}'s scan treats as surrounding padding.
634
694
  *
635
695
  * @param character - The single character to test, or `undefined` past the end of a line
636
- * @returns `true` when it is whitespace
696
+ * @returns True if it is whitespace; false otherwise
637
697
  *
638
698
  * @example
639
699
  * ```ts
@@ -643,11 +703,39 @@ export declare function isFenceClose(line: string, marker: string): boolean;
643
703
  */
644
704
  export declare function isFenceWhitespace(character: string | undefined): boolean;
645
705
 
646
- /** Determine whether a node is a heading block. */
706
+ /**
707
+ * Checks whether `character` is whitespace under the emphasis flanking rule - a space, a
708
+ * tab, or a newline.
709
+ *
710
+ * @param character - The character to test
711
+ * @returns True if the flanking rule counts it as whitespace; false otherwise
712
+ *
713
+ * @example
714
+ * ```ts
715
+ * isFlankingWhitespace(' ') // true
716
+ * isFlankingWhitespace('a') // false
717
+ * ```
718
+ */
719
+ export declare function isFlankingWhitespace(character: string): boolean;
720
+
721
+ /**
722
+ * Determines whether a node is a heading block.
723
+ *
724
+ * @param node - The AST node to test
725
+ * @returns True if the node is a {@link HeadingNode}; false otherwise
726
+ *
727
+ * @example
728
+ * ```ts
729
+ * isHeadingNode({ element: 'heading', level: 1, children: [] }) // true
730
+ * ```
731
+ */
647
732
  export declare function isHeadingNode(node: MarkdownNode): node is HeadingNode;
648
733
 
649
734
  /**
650
- * Determine whether a node is an image.
735
+ * Determines whether a node is an image.
736
+ *
737
+ * @param node - The AST node to test
738
+ * @returns True if the node is an {@link ImageNode}; false otherwise
651
739
  *
652
740
  * @example
653
741
  * ```ts
@@ -657,16 +745,16 @@ export declare function isHeadingNode(node: MarkdownNode): node is HeadingNode;
657
745
  export declare function isImageNode(node: MarkdownNode): node is ImageNode;
658
746
 
659
747
  /**
660
- * Determine whether an arbitrary value is a valid {@link InlineNode} - a text
748
+ * Determines whether an arbitrary value is a valid {@link InlineNode} - a text
661
749
  * run, emphasis, code span, hard break, link, or image, recursively validated.
662
750
  *
663
751
  * @remarks
664
752
  * Total: never throws, even on cyclic or pathologically deep input - every
665
753
  * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is
666
- * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).
754
+ * throw-contained per the `@orkestrel/contract` guard contract.
667
755
  *
668
756
  * @param value - The value to test
669
- * @returns `true` when `value` is a well-formed {@link InlineNode}
757
+ * @returns True if `value` is a well-formed {@link InlineNode}; false otherwise
670
758
  *
671
759
  * @example
672
760
  * ```ts
@@ -679,7 +767,10 @@ export declare function isImageNode(node: MarkdownNode): node is ImageNode;
679
767
  export declare const isInlineNode: Guard<InlineNode>;
680
768
 
681
769
  /**
682
- * Determine whether a node is a GFM hard line break.
770
+ * Determines whether a node is a GFM hard line break.
771
+ *
772
+ * @param node - The AST node to test
773
+ * @returns True if the node is a {@link LineBreakNode}; false otherwise
683
774
  *
684
775
  * @example
685
776
  * ```ts
@@ -688,11 +779,24 @@ export declare const isInlineNode: Guard<InlineNode>;
688
779
  */
689
780
  export declare function isLineBreakNode(node: MarkdownNode): node is LineBreakNode;
690
781
 
691
- /** Determine whether a node is a link. */
782
+ /**
783
+ * Determines whether a node is a link.
784
+ *
785
+ * @param node - The AST node to test
786
+ * @returns True if the node is a {@link LinkNode}; false otherwise
787
+ *
788
+ * @example
789
+ * ```ts
790
+ * isLinkNode({ element: 'link', href: 'https://example.dev', children: [] }) // true
791
+ * ```
792
+ */
692
793
  export declare function isLinkNode(node: MarkdownNode): node is LinkNode;
693
794
 
694
795
  /**
695
- * Determine whether a node is a list block.
796
+ * Determines whether a node is a list block.
797
+ *
798
+ * @param node - The AST node to test
799
+ * @returns True if the node is a {@link ListNode}; false otherwise
696
800
  *
697
801
  * @example
698
802
  * ```ts
@@ -702,17 +806,17 @@ export declare function isLinkNode(node: MarkdownNode): node is LinkNode;
702
806
  export declare function isListNode(node: MarkdownNode): node is ListNode;
703
807
 
704
808
  /**
705
- * Determine whether an arbitrary value is a valid {@link MarkdownDocument} -
809
+ * Determines whether an arbitrary value is a valid {@link MarkdownDocument} -
706
810
  * the parsed-AST root {@link parseDocument} returns, recursively
707
811
  * validated.
708
812
  *
709
813
  * @remarks
710
814
  * Total: never throws, even on cyclic or pathologically deep input - every
711
815
  * combinator involved (`recordOf`, `arrayOf`) is throw-contained per the
712
- * `@orkestrel/contract` guard contract (AGENTS §14).
816
+ * `@orkestrel/contract` guard contract.
713
817
  *
714
818
  * @param value - The value to test
715
- * @returns `true` when `value` is a well-formed {@link MarkdownDocument}
819
+ * @returns True if `value` is a well-formed {@link MarkdownDocument}; false otherwise
716
820
  *
717
821
  * @example
718
822
  * ```ts
@@ -725,19 +829,19 @@ export declare function isListNode(node: MarkdownNode): node is ListNode;
725
829
  export declare const isMarkdownDocument: Guard<MarkdownDocument>;
726
830
 
727
831
  /**
728
- * Determine whether an arbitrary value is a valid {@link MarkdownNode} - the
832
+ * Determines whether an arbitrary value is a valid {@link MarkdownNode} - the
729
833
  * {@link MarkdownDocument} root, a {@link BlockNode}, a {@link ListItemNode}, or
730
834
  * an {@link InlineNode}, recursively validated.
731
835
  *
732
836
  * @remarks
733
837
  * Total: never throws, even on cyclic or pathologically deep input - every
734
838
  * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is
735
- * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).
839
+ * throw-contained per the `@orkestrel/contract` guard contract.
736
840
  * A list item's shape is inlined here (and in {@link isBlockNode}) rather than
737
841
  * named separately - it is used at exactly these two sites.
738
842
  *
739
843
  * @param value - The value to test
740
- * @returns `true` when `value` is a well-formed {@link MarkdownNode}
844
+ * @returns True if `value` is a well-formed {@link MarkdownNode}; false otherwise
741
845
  *
742
846
  * @example
743
847
  * ```ts
@@ -750,7 +854,10 @@ export declare const isMarkdownDocument: Guard<MarkdownDocument>;
750
854
  export declare const isMarkdownNode: Guard<MarkdownNode>;
751
855
 
752
856
  /**
753
- * Determine whether a node is a paragraph block.
857
+ * Determines whether a node is a paragraph block.
858
+ *
859
+ * @param node - The AST node to test
860
+ * @returns True if the node is a {@link ParagraphNode}; false otherwise
754
861
  *
755
862
  * @example
756
863
  * ```ts
@@ -760,11 +867,11 @@ export declare const isMarkdownNode: Guard<MarkdownNode>;
760
867
  export declare function isParagraphNode(node: MarkdownNode): node is ParagraphNode;
761
868
 
762
869
  /**
763
- * Whether `line` is a blockquote line (`>` optionally indented up to three spaces) -
870
+ * Checks whether `line` is a blockquote line (`>` optionally indented up to three spaces) -
764
871
  * its content is de-quoted by {@link stripQuote}.
765
872
  *
766
873
  * @param line - The candidate line
767
- * @returns `true` when the line begins a blockquote
874
+ * @returns True if the line begins a blockquote; false otherwise
768
875
  *
769
876
  * @example
770
877
  * ```ts
@@ -773,17 +880,27 @@ export declare function isParagraphNode(node: MarkdownNode): node is ParagraphNo
773
880
  */
774
881
  export declare function isQuote(line: string): boolean;
775
882
 
776
- /** Determine whether a node is a GFM table block. */
883
+ /**
884
+ * Determines whether a node is a GFM table block.
885
+ *
886
+ * @param node - The AST node to test
887
+ * @returns True if the node is a {@link TableNode}; false otherwise
888
+ *
889
+ * @example
890
+ * ```ts
891
+ * isTableNode({ element: 'table', header: [], rows: [], align: [] }) // true
892
+ * ```
893
+ */
777
894
  export declare function isTableNode(node: MarkdownNode): node is TableNode;
778
895
 
779
896
  /**
780
- * Whether the pair (`header`, `delimiter`) opens a GFM table - `delimiter` is a row of
897
+ * Checks whether the pair (`header`, `delimiter`) opens a GFM table - `delimiter` is a row of
781
898
  * `|`-separated cells each matching `:?-+:?`, the GFM rule that a table requires a
782
899
  * header row IMMEDIATELY followed by a delimiter row.
783
900
  *
784
901
  * @param header - The candidate header line
785
902
  * @param delimiter - The line after it (the candidate delimiter)
786
- * @returns `true` when the two lines open a table
903
+ * @returns True if the two lines open a table; false otherwise
787
904
  *
788
905
  * @example
789
906
  * ```ts
@@ -793,7 +910,10 @@ export declare function isTableNode(node: MarkdownNode): node is TableNode;
793
910
  export declare function isTableStart(header: string, delimiter: string | undefined): boolean;
794
911
 
795
912
  /**
796
- * Determine whether a node is a plain text run.
913
+ * Determines whether a node is a plain text run.
914
+ *
915
+ * @param node - The AST node to test
916
+ * @returns True if the node is a {@link TextNode}; false otherwise
797
917
  *
798
918
  * @example
799
919
  * ```ts
@@ -803,12 +923,12 @@ export declare function isTableStart(header: string, delimiter: string | undefin
803
923
  export declare function isTextNode(node: MarkdownNode): node is TextNode;
804
924
 
805
925
  /**
806
- * Whether `line` is a thematic break (horizontal rule) - three or more of the SAME
926
+ * Checks whether `line` is a thematic break (horizontal rule) - three or more of the SAME
807
927
  * marker `-`, `*`, or `_` (optionally space-separated) and nothing else (`---`,
808
928
  * `***`, `___`, `- - -`).
809
929
  *
810
930
  * @param line - The candidate line
811
- * @returns `true` when the line is a thematic break
931
+ * @returns True if the line is a thematic break; false otherwise
812
932
  *
813
933
  * @example
814
934
  * ```ts
@@ -818,7 +938,10 @@ export declare function isTextNode(node: MarkdownNode): node is TextNode;
818
938
  export declare function isThematicBreak(line: string): boolean;
819
939
 
820
940
  /**
821
- * Determine whether a node is a thematic break (horizontal rule) block.
941
+ * Determines whether a node is a thematic break (horizontal rule) block.
942
+ *
943
+ * @param node - The AST node to test
944
+ * @returns True if the node is a {@link ThematicBreakNode}; false otherwise
822
945
  *
823
946
  * @example
824
947
  * ```ts
@@ -827,21 +950,6 @@ export declare function isThematicBreak(line: string): boolean;
827
950
  */
828
951
  export declare function isThematicBreakNode(node: MarkdownNode): node is ThematicBreakNode;
829
952
 
830
- /**
831
- * Whether `character` is an inline whitespace character (space / tab / newline) - the
832
- * emphasis flanking rule's space test.
833
- *
834
- * @param character - The character to test
835
- * @returns `true` when it is inline whitespace
836
- *
837
- * @example
838
- * ```ts
839
- * isWhitespace(' ') // true
840
- * isWhitespace('a') // false
841
- * ```
842
- */
843
- export declare function isWhitespace(character: string): boolean;
844
-
845
953
  /**
846
954
  * Joins offset-bearing markdown sources while mapping a separator to the original
847
955
  * region between adjacent mapped sources.
@@ -858,13 +966,13 @@ export declare function isWhitespace(character: string): boolean;
858
966
  */
859
967
  export declare function joinSources(sources: readonly MarkdownSource[], separator: string): MarkdownSource;
860
968
 
861
- /** A GFM hard line break - two or more trailing spaces before a newline. */
969
+ /** Represents a GFM hard line break - two or more trailing spaces before a newline. */
862
970
  export declare interface LineBreakNode {
863
971
  readonly element: 'break';
864
972
  }
865
973
 
866
974
  /**
867
- * The shape of a {@link LineBreakNode} - a GFM hard line-break leaf.
975
+ * Describes the shape of a {@link LineBreakNode} - a GFM hard line-break leaf.
868
976
  *
869
977
  * @example
870
978
  * ```ts
@@ -880,37 +988,70 @@ export declare const lineBreakShape: ObjectShape<{
880
988
  }, false>;
881
989
 
882
990
  /**
883
- * An inline link - `[text](href)`. `children` are the inline nodes of the link text.
991
+ * Represents the located syntax bounds of one `[text](href)` link - the value the inline phase's
992
+ * link locator returns for a balanced label followed by a destination.
993
+ */
994
+ export declare interface LinkBounds {
995
+ /** Holds the index of the label's closing `]`. */
996
+ readonly close: number;
997
+ /** Holds the index one past the destination's closing `)`, exclusive. */
998
+ readonly end: number;
999
+ }
1000
+
1001
+ /**
1002
+ * Represents an inline link - `[text](href)`. `children` are the inline nodes of the link text.
884
1003
  * At render, html's floor removes a refused `href` attribute and the link keeps its
885
1004
  * text; {@link htmlToMarkdown} instead stores a refused destination as `''`.
886
1005
  */
887
1006
  export declare interface LinkNode {
888
1007
  readonly element: 'link';
889
- /** The link destination (sanitized + attribute-escaped at render). */
1008
+ /** Holds the link destination (sanitized + attribute-escaped at render). */
890
1009
  readonly href: string;
891
- /** The inline content of the link text. */
1010
+ /** Holds the inline content of the link text. */
892
1011
  readonly children: readonly InlineNode[];
893
1012
  }
894
1013
 
895
1014
  /**
896
- * The parsed parts of a single list-item line - the value the block phase's
1015
+ * Represents the scanned result of one `[text](href)` link - the node the inline phase's link
1016
+ * scanner built from {@link LinkBounds} and where the scan resumes.
1017
+ */
1018
+ export declare interface LinkScan {
1019
+ /** Holds the scanned link, its text already scanned into inline children. */
1020
+ readonly node: LinkNode;
1021
+ /** Holds the index one past the destination's closing `)`, exclusive. */
1022
+ readonly end: number;
1023
+ }
1024
+
1025
+ /**
1026
+ * Represents the result of collecting one list - the node the construct scanner built and where
1027
+ * the block phase resumes.
1028
+ */
1029
+ export declare interface ListCollection {
1030
+ /** Holds the collected list. */
1031
+ readonly node: ListNode;
1032
+ /** Holds the index of the first line after the list. */
1033
+ readonly next: number;
1034
+ }
1035
+
1036
+ /**
1037
+ * Represents the parsed parts of a single list-item line - the value the block phase's
897
1038
  * list detector returns for a `-` / `*` / `+` bullet or a `1.` / `1)` ordinal line.
898
1039
  */
899
1040
  export declare interface ListItemMatch {
900
- /** `true` for an ordered (`1.` / `1)`) item, `false` for a bullet (`-` / `*` / `+`). */
1041
+ /** Holds `true` for an ordered (`1.` / `1)`) item, `false` for a bullet (`-` / `*` / `+`). */
901
1042
  readonly ordered: boolean;
902
- /** The ordinal of an ordered item (its number); `1` for a bullet. */
1043
+ /** Holds the ordinal of an ordered item (its number); `1` for a bullet. */
903
1044
  readonly start: number;
904
- /** The item's text after the marker. */
1045
+ /** Holds the item's text after the marker. */
905
1046
  readonly content: string;
906
- /** The leading-space indent of the marker. */
1047
+ /** Holds the leading-space indent of the marker. */
907
1048
  readonly indent: number;
908
- /** The full marker width (indent + bullet/ordinal + the following space) - the continuation indent. */
1049
+ /** Holds the full marker width (indent + bullet/ordinal + the following space) - the continuation indent. */
909
1050
  readonly marker: number;
910
1051
  }
911
1052
 
912
1053
  /**
913
- * The shape of {@link ListItemMatch} - the parsed parts of a single list-item
1054
+ * Describes the shape of {@link ListItemMatch} - the parsed parts of a single list-item
914
1055
  * line the block phase's list detector returns. Fully non-recursive (no
915
1056
  * nested node fields), so every field shapes directly.
916
1057
  *
@@ -931,26 +1072,26 @@ export declare const listItemMatchShape: ObjectShape<{
931
1072
  marker: NumberShape;
932
1073
  }, false>;
933
1074
 
934
- /** One item of a {@link ListNode} - `children` the block content of the item (typically one paragraph, plus any nested list). */
1075
+ /** Represents one item of a {@link ListNode} - `children` the block content of the item (typically one paragraph, plus any nested list). */
935
1076
  export declare interface ListItemNode {
936
1077
  readonly element: 'listItem';
937
- /** The block content of the list item (its text as a paragraph, plus any nested list). */
1078
+ /** Holds the block content of the list item (its text as a paragraph, plus any nested list). */
938
1079
  readonly children: readonly BlockNode[];
939
1080
  }
940
1081
 
941
1082
  /**
942
- * A list - bulleted (`-` / `*` / `+`, `ordered: false`) or numbered (`1.` / `1)`,
1083
+ * Represents a list - bulleted (`-` / `*` / `+`, `ordered: false`) or numbered (`1.` / `1)`,
943
1084
  * `ordered: true`). `start` is the first ordinal of an ordered list (usually `1`).
944
1085
  * Nesting is expressed by a {@link ListNode} appearing in a {@link ListItemNode}'s
945
1086
  * `children`.
946
1087
  */
947
1088
  export declare interface ListNode {
948
1089
  readonly element: 'list';
949
- /** `true` for an ordered (numbered) list (→ `<ol>`); `false` for a bulleted list (→ `<ul>`). */
1090
+ /** Holds `true` for an ordered (numbered) list (→ `<ol>`); `false` for a bulleted list (→ `<ul>`). */
950
1091
  readonly ordered: boolean;
951
- /** The starting ordinal of an ordered list (the first item's number); `1` for a bulleted list. */
1092
+ /** Holds the starting ordinal of an ordered list (the first item's number); `1` for a bulleted list. */
952
1093
  readonly start: number;
953
- /** The list's items, in order. */
1094
+ /** Holds the list's items, in order. */
954
1095
  readonly items: readonly ListItemNode[];
955
1096
  }
956
1097
 
@@ -972,12 +1113,7 @@ export declare interface ListNode {
972
1113
  * locateEmphasis('*em*', 0, 4) // { strong: false, open: 1, close: 3, end: 4 }
973
1114
  * ```
974
1115
  */
975
- export declare function locateEmphasis(source: string, start: number, to: number): {
976
- readonly strong: boolean;
977
- readonly open: number;
978
- readonly close: number;
979
- readonly end: number;
980
- } | undefined;
1116
+ export declare function locateEmphasis(source: string, start: number, to: number): EmphasisBounds | undefined;
981
1117
 
982
1118
  /**
983
1119
  * Locates a link `[text](href)` at `start` - the text runs to a BALANCED `]`, then `(`
@@ -995,13 +1131,10 @@ export declare function locateEmphasis(source: string, start: number, to: number
995
1131
  * locateLink('[text](url)', 0, 11) // { close: 5, end: 11 }
996
1132
  * ```
997
1133
  */
998
- export declare function locateLink(source: string, start: number, to: number): {
999
- readonly close: number;
1000
- readonly end: number;
1001
- } | undefined;
1134
+ export declare function locateLink(source: string, start: number, to: number): LinkBounds | undefined;
1002
1135
 
1003
1136
  /**
1004
- * A stateful, parsed markdown document - wraps a typed {@link MarkdownDocument} AST
1137
+ * Wraps a typed {@link MarkdownDocument} AST as a stateful, parsed markdown document
1005
1138
  * with the query (`find` / `filter` / `reduce` / iteration), rewrite (`map`), fold, and
1006
1139
  * streaming operations {@link MarkdownInterface} declares.
1007
1140
  *
@@ -1026,7 +1159,7 @@ export declare function locateLink(source: string, start: number, to: number): {
1026
1159
  * instance; the document root invariant (`element: 'document'`) always holds. An
1027
1160
  * identity rewrite still returns a new handle, over the same document tree.
1028
1161
  * - **Traversal order.** {@link walk} and the `find` / `filter` / `reduce` queries built
1029
- * on it walk the AST depth-first, pre-order, root-inclusive (via {@link walkNodes});
1162
+ * on it walk the AST depth-first, pre-order, root-inclusive (through {@link walkNodes});
1030
1163
  * `stream` is shallow - only the document's direct block children.
1031
1164
  *
1032
1165
  * @example
@@ -1044,7 +1177,7 @@ export declare function locateLink(source: string, start: number, to: number): {
1044
1177
  export declare class Markdown implements MarkdownInterface {
1045
1178
  #private;
1046
1179
  constructor(input: string | MarkdownDocument);
1047
- /** The stored {@link MarkdownDocument} AST root. */
1180
+ /** Holds the stored {@link MarkdownDocument} AST root. */
1048
1181
  get document(): MarkdownDocument;
1049
1182
  /**
1050
1183
  * Reads the region of the original markdown string a node of this handle's tree was
@@ -1065,7 +1198,7 @@ export declare class Markdown implements MarkdownInterface {
1065
1198
  */
1066
1199
  span(node: MarkdownNode): MarkdownSpan | undefined;
1067
1200
  /**
1068
- * THE deep traversal - a lazy, depth-first, pre-order, root-inclusive generator
1201
+ * Returns THE deep traversal - a lazy, depth-first, pre-order, root-inclusive generator
1069
1202
  * over every {@link MarkdownNode} in the document. `find` / `filter` / `reduce`
1070
1203
  * all iterate this single traversal.
1071
1204
  *
@@ -1098,10 +1231,10 @@ export declare class Markdown implements MarkdownInterface {
1098
1231
  map(rewrite: MarkdownRewriteHandler): MarkdownInterface;
1099
1232
  /** Folds the AST depth-first, pre-order into an accumulator. */
1100
1233
  reduce<T>(callback: (accumulator: T, node: MarkdownNode) => T, initial: T): T;
1101
- /** Runs a total catamorphism over the document using a {@link MarkdownHandlers} table. */
1102
- fold<T>(handlers: MarkdownHandlers<T>): T;
1234
+ /** Runs a total catamorphism over the document using a {@link MarkdownHandlerMap} table. */
1235
+ fold<T>(handlers: MarkdownHandlerMap<T>): T;
1103
1236
  /**
1104
- * A web-standard {@link ReadableStream} over the document's top-level block nodes
1237
+ * Returns a web-standard {@link ReadableStream} over the document's top-level block nodes
1105
1238
  * (shallow, source order) - a fresh, pull-based source per call: one block is
1106
1239
  * enqueued per `pull`, so a slow reader's backpressure is respected. Cancellable,
1107
1240
  * async-iterable wherever the platform supports it (Node, Deno), and pipeable
@@ -1116,7 +1249,7 @@ export declare class Markdown implements MarkdownInterface {
1116
1249
  * }
1117
1250
  *
1118
1251
  * // Node / Deno / Firefox support async iteration of ReadableStream natively;
1119
- * // other environments should use the reader loop above instead.
1252
+ * // other environments use the reader loop shown earlier.
1120
1253
  * for await (const block of markdown.stream()) {
1121
1254
  * console.log(block)
1122
1255
  * }
@@ -1125,11 +1258,11 @@ export declare class Markdown implements MarkdownInterface {
1125
1258
  stream(): ReadableStream<BlockNode>;
1126
1259
  }
1127
1260
 
1128
- /** One projected table cell - the inline content and alignment of a `th` / `td`. */
1261
+ /** Represents one projected table cell - the inline content and alignment of a `th` / `td`. */
1129
1262
  export declare interface MarkdownCell {
1130
- /** The alignment the cell's `align` attribute declared; `undefined` when it declared none. */
1263
+ /** Holds the alignment the cell's `align` attribute declared; `undefined` when it declared none. */
1131
1264
  readonly align: TableAlign | undefined;
1132
- /** The cell's inline content - a table cell is inline-only, so block content flattens to text. */
1265
+ /** Holds the cell's inline content - a table cell is inline-only, so block content flattens to text. */
1133
1266
  readonly inlines: readonly InlineNode[];
1134
1267
  }
1135
1268
 
@@ -1163,28 +1296,28 @@ derivations: ReadonlyMap<MarkdownNode, MarkdownNode | undefined>
1163
1296
  ];
1164
1297
 
1165
1298
  /**
1166
- * The root of a parsed markdown AST - the ordered block children of the whole
1299
+ * Represents the root of a parsed markdown AST - the ordered block children of the whole
1167
1300
  * document. The value {@link MarkdownInterface.document} holds.
1168
1301
  */
1169
1302
  export declare interface MarkdownDocument {
1170
1303
  readonly element: 'document';
1171
- /** The document's top-level block nodes, in source order. */
1304
+ /** Holds the document's top-level block nodes, in source order. */
1172
1305
  readonly children: readonly BlockNode[];
1173
1306
  }
1174
1307
 
1175
1308
  /**
1176
- * A fold handler for one AST element - receives the node and its children
1309
+ * Represents a fold handler for one AST element - receives the node and its children
1177
1310
  * ALREADY folded to `T`, and produces the node's own `T`. The building block of a
1178
- * {@link MarkdownHandlers} catamorphism table.
1311
+ * {@link MarkdownHandlerMap} catamorphism table.
1179
1312
  */
1180
1313
  export declare type MarkdownHandler<TNode, T> = (node: TNode, children: readonly T[]) => T;
1181
1314
 
1182
1315
  /**
1183
- * The total catamorphism table for {@link MarkdownInterface.fold} - one
1316
+ * Represents the total catamorphism table for {@link MarkdownInterface.fold} - one
1184
1317
  * {@link MarkdownHandler} per AST element, keyed by its `element` discriminant. Every
1185
1318
  * key is required: a fold is total over the AST, so there is no element it can skip.
1186
1319
  */
1187
- export declare interface MarkdownHandlers<T> {
1320
+ export declare interface MarkdownHandlerMap<T> {
1188
1321
  /** Folds a {@link MarkdownDocument} root from its already-folded block children. */
1189
1322
  readonly document: MarkdownHandler<MarkdownDocument, T>;
1190
1323
  /** Folds a {@link HeadingNode} from its already-folded inline children. */
@@ -1224,7 +1357,7 @@ export declare interface MarkdownHandlers<T> {
1224
1357
  }
1225
1358
 
1226
1359
  /**
1227
- * A stateful, parsed markdown document: the typed {@link MarkdownDocument} AST plus
1360
+ * Represents a stateful, parsed markdown document: the typed {@link MarkdownDocument} AST plus
1228
1361
  * the query, rewrite, and fold operations over it.
1229
1362
  *
1230
1363
  * @remarks
@@ -1237,7 +1370,7 @@ export declare interface MarkdownHandlers<T> {
1237
1370
  * - **`stream`.** Returns a web-standard {@link ReadableStream} over the top-level
1238
1371
  * blocks - a fresh, pull-based source per call: exactly one block is enqueued per
1239
1372
  * `pull`, so a slow consumer's backpressure is respected and no work happens ahead
1240
- * of demand. Cancellable via the returned stream's own `cancel()`, async-iterable
1373
+ * of demand. Cancellable through the returned stream's own `cancel()`, async-iterable
1241
1374
  * wherever the platform supports it (Node, Deno, and browsers that ship the
1242
1375
  * proposal), and pipeable through any {@link TransformStream} / {@link WritableStream}.
1243
1376
  * - **The surface.** `document` (the AST root), `walk` (the deep traversal), `find` /
@@ -1246,10 +1379,10 @@ export declare interface MarkdownHandlers<T> {
1246
1379
  * total catamorphism), and `stream` (the shallow, backpressured top-level source).
1247
1380
  */
1248
1381
  export declare interface MarkdownInterface {
1249
- /** The stored {@link MarkdownDocument} AST root. */
1382
+ /** Holds the stored {@link MarkdownDocument} AST root. */
1250
1383
  readonly document: MarkdownDocument;
1251
1384
  /**
1252
- * THE deep traversal - a lazy, depth-first, pre-order, root-inclusive
1385
+ * Returns THE deep traversal - a lazy, depth-first, pre-order, root-inclusive
1253
1386
  * {@link Generator} over every {@link MarkdownNode} in the document. The sync
1254
1387
  * `for (const node of markdown.walk())` surface is also consumable by
1255
1388
  * `for await (const node of markdown.walk())` (JavaScript accepts a sync
@@ -1290,10 +1423,10 @@ export declare interface MarkdownInterface {
1290
1423
  map(rewrite: MarkdownRewriteHandler): MarkdownInterface;
1291
1424
  /** Folds the AST depth-first, pre-order into an accumulator. */
1292
1425
  reduce<T>(callback: (accumulator: T, node: MarkdownNode) => T, initial: T): T;
1293
- /** Runs a total catamorphism over the document using a {@link MarkdownHandlers} table. */
1294
- fold<T>(handlers: MarkdownHandlers<T>): T;
1426
+ /** Runs a total catamorphism over the document using a {@link MarkdownHandlerMap} table. */
1427
+ fold<T>(handlers: MarkdownHandlerMap<T>): T;
1295
1428
  /**
1296
- * A web-standard {@link ReadableStream} over the document's top-level block nodes
1429
+ * Returns a web-standard {@link ReadableStream} over the document's top-level block nodes
1297
1430
  * (shallow, source order) - a lazy, pull-based, backpressure-respecting source. A
1298
1431
  * fresh, independently-replayable stream every call; never mutates the document.
1299
1432
  */
@@ -1301,7 +1434,7 @@ export declare interface MarkdownInterface {
1301
1434
  }
1302
1435
 
1303
1436
  /**
1304
- * Any node in a markdown AST - the {@link MarkdownDocument} root, a {@link BlockNode},
1437
+ * Represents any node in a markdown AST - the {@link MarkdownDocument} root, a {@link BlockNode},
1305
1438
  * a {@link ListItemNode}, or an {@link InlineNode}. The exhaustive set every
1306
1439
  * projection's `switch` covers.
1307
1440
  */
@@ -1326,7 +1459,7 @@ spans: ReadonlyMap<MarkdownNode, MarkdownSpan>
1326
1459
  ];
1327
1460
 
1328
1461
  /**
1329
- * What one HTML node projects to on the way to markdown - the fold value
1462
+ * Represents what one HTML node projects to on the way to markdown - the fold value
1330
1463
  * `htmlToMarkdown` carries up the AST.
1331
1464
  *
1332
1465
  * @remarks
@@ -1348,20 +1481,20 @@ spans: ReadonlyMap<MarkdownNode, MarkdownSpan>
1348
1481
  * them untouched; whatever never reaches a table degrades to paragraphs.
1349
1482
  */
1350
1483
  export declare interface MarkdownProjection {
1351
- /** The node's block content, with any surrounding inline runs already wrapped into paragraphs. */
1484
+ /** Holds the node's block content, with any surrounding inline runs already wrapped into paragraphs. */
1352
1485
  readonly blocks: readonly BlockNode[];
1353
- /** The node's inline content; empty whenever `blocks` is not. */
1486
+ /** Holds the node's inline content; empty whenever `blocks` is not. */
1354
1487
  readonly inlines: readonly InlineNode[];
1355
- /** The raw subtree text, whitespace uncollapsed and escapes unresolved. */
1488
+ /** Holds the raw subtree text, whitespace uncollapsed and escapes unresolved. */
1356
1489
  readonly text: string;
1357
- /** The cells this node contributes to an enclosing row. */
1490
+ /** Holds the cells this node contributes to an enclosing row. */
1358
1491
  readonly cells: readonly MarkdownCell[];
1359
- /** The rows this node contributes to an enclosing table - each its cells, in column order. */
1492
+ /** Holds the rows this node contributes to an enclosing table - each its cells, in column order. */
1360
1493
  readonly rows: ReadonlyArray<readonly MarkdownCell[]>;
1361
1494
  }
1362
1495
 
1363
1496
  /**
1364
- * A copy-on-write node rewrite applied bottom-up by {@link MarkdownInterface.map} -
1497
+ * Represents a copy-on-write node rewrite applied bottom-up by {@link MarkdownInterface.map} -
1365
1498
  * receives one node (its own children already rewritten) and returns its
1366
1499
  * replacement (the same node, unchanged, or a new node).
1367
1500
  */
@@ -1395,11 +1528,11 @@ export declare type MarkdownRewriteHandler = (node: MarkdownNode) => MarkdownNod
1395
1528
  * The mapping is therefore affine strictly inside a run and clamped at its end.
1396
1529
  */
1397
1530
  export declare interface MarkdownSegment {
1398
- /** The first code unit of the run inside {@link MarkdownSource.text}. */
1531
+ /** Holds the first code unit of the run inside {@link MarkdownSource.text}. */
1399
1532
  readonly offset: number;
1400
- /** The first code unit of the original-string region the run was produced from, inclusive. */
1533
+ /** Holds the first code unit of the original-string region the run was produced from, inclusive. */
1401
1534
  readonly start: number;
1402
- /** The code unit one past that region's last, exclusive. */
1535
+ /** Holds the code unit one past that region's last, exclusive. */
1403
1536
  readonly end: number;
1404
1537
  }
1405
1538
 
@@ -1423,9 +1556,9 @@ export declare interface MarkdownSegment {
1423
1556
  * coverage with `projectSpan` rather than assuming it.
1424
1557
  */
1425
1558
  export declare interface MarkdownSource {
1426
- /** The derived text a parser reads. */
1559
+ /** Holds the derived text a parser reads. */
1427
1560
  readonly text: string;
1428
- /** The runs mapping `text` back to the original string, in ascending `offset` order. */
1561
+ /** Holds the runs mapping `text` back to the original string, in ascending `offset` order. */
1429
1562
  readonly segments: readonly MarkdownSegment[];
1430
1563
  }
1431
1564
 
@@ -1446,14 +1579,14 @@ export declare interface MarkdownSource {
1446
1579
  * is `end - start`; no length member exists to drift from the two offsets.
1447
1580
  */
1448
1581
  export declare interface MarkdownSpan {
1449
- /** The first code unit of the region, inclusive. */
1582
+ /** Holds the first code unit of the region, inclusive. */
1450
1583
  readonly start: number;
1451
- /** The code unit one past the region's last, exclusive. */
1584
+ /** Holds the code unit one past the region's last, exclusive. */
1452
1585
  readonly end: number;
1453
1586
  }
1454
1587
 
1455
1588
  /**
1456
- * Project a {@link MarkdownNode} into an unsanitized {@link HTMLDocument}.
1589
+ * Projects a {@link MarkdownNode} into an unsanitized {@link HTMLDocument}.
1457
1590
  *
1458
1591
  * @remarks
1459
1592
  * The projection is pure and iterative. Text and attribute values remain literal for
@@ -1474,10 +1607,10 @@ export declare interface MarkdownSpan {
1474
1607
  export declare function markdownToHTML(node: MarkdownNode): HTMLDocument;
1475
1608
 
1476
1609
  /**
1477
- * The maximum recursion depth the parse pipeline (`parseDocument` and its
1478
- * `parsers.ts` helpers) and the `helpers.ts` traversal / projection functions
1479
- * (`markdownToHTML`, `renderHTML`, `renderMarkdown`, `walkNodes`, `foldNode`,
1480
- * `rewriteDocument`) honor before degrading. It bounds blockquote nesting, inline
1610
+ * Caps the recursion depth the parse pipeline (`parseDocument` and its
1611
+ * `parsers.ts` helpers), the `helpers.ts` traversal / projection functions
1612
+ * (`markdownToHTML`, `renderMarkdown`, `walkNodes`, `foldNode`, `rewriteDocument`),
1613
+ * and the `compilers.ts` renderer (`renderHTML`) honor before degrading. It bounds blockquote nesting, inline
1481
1614
  * nesting (emphasis / links), and traversal / projection recursion so pathological
1482
1615
  * or hostile input cannot exhaust the call stack. {@link htmlToMarkdown} is the
1483
1616
  * inherited exception: its fold and depth cap belong to `@orkestrel/html`.
@@ -1485,7 +1618,7 @@ export declare function markdownToHTML(node: MarkdownNode): HTMLDocument;
1485
1618
  export declare const MAX_DEPTH = 64;
1486
1619
 
1487
1620
  /**
1488
- * Combine the projections of one node's children into the projection of that node -
1621
+ * Combines the projections of one node's children into the projection of that node -
1489
1622
  * the single place inline runs become paragraphs, so no ancestor has to decide it
1490
1623
  * twice.
1491
1624
  *
@@ -1513,7 +1646,7 @@ export declare const MAX_DEPTH = 64;
1513
1646
  export declare function mergeProjections(children: readonly MarkdownProjection[]): MarkdownProjection;
1514
1647
 
1515
1648
  /**
1516
- * Reduce an inline run to the shape markdown can actually write back: adjacent text
1649
+ * Reduces an inline run to the shape markdown can actually write back: adjacent text
1517
1650
  * coalesced, empty text dropped, and every hard break either kept as a real line
1518
1651
  * ending or spent as a space.
1519
1652
  *
@@ -1526,8 +1659,8 @@ export declare function mergeProjections(children: readonly MarkdownProjection[]
1526
1659
  * becomes the space it stood for.
1527
1660
  *
1528
1661
  * @param nodes - The inline run to normalize
1529
- * @param breaks - Whether the target context can carry a hard break at all; `false` for
1530
- * a heading or a table cell, where every break becomes a space
1662
+ * @param breaks - If `true`, keeps each hard break as a real line ending; if `false`, spends
1663
+ * every break as the space it stood for, as a heading or a table cell requires
1531
1664
  * @returns The normalized run
1532
1665
  *
1533
1666
  * @example
@@ -1554,10 +1687,10 @@ export declare function normalizeInlines(nodes: readonly InlineNode[], breaks: b
1554
1687
  */
1555
1688
  export declare function normalizeParagraphLine(source: MarkdownSource, breaks: boolean): MarkdownSource;
1556
1689
 
1557
- /** A paragraph - a run of non-blank lines that is not another block; `children` its inline content. */
1690
+ /** Represents a paragraph - a run of non-blank lines that is not another block; `children` its inline content. */
1558
1691
  export declare interface ParagraphNode {
1559
1692
  readonly element: 'paragraph';
1560
- /** The inline content of the paragraph. */
1693
+ /** Holds the inline content of the paragraph. */
1561
1694
  readonly children: readonly InlineNode[];
1562
1695
  }
1563
1696
 
@@ -1579,11 +1712,16 @@ export declare interface ParagraphNode {
1579
1712
  export declare function parseBlocks(lines: readonly MarkdownSource[], depth: number, spans?: Map<MarkdownNode, MarkdownSpan>, end?: number): readonly BlockNode[];
1580
1713
 
1581
1714
  /**
1582
- * Parses a markdown string into a typed {@link MarkdownDocument} AST via the
1715
+ * Parses a markdown string into a typed {@link MarkdownDocument} AST through the
1583
1716
  * block phase.
1584
1717
  *
1585
1718
  * @param markdown - The markdown source to parse.
1586
1719
  * @returns The parsed document.
1720
+ *
1721
+ * @example
1722
+ * ```ts
1723
+ * parseDocument('# Hi') // { element: 'document', children: [{ element: 'heading', ... }] }
1724
+ * ```
1587
1725
  */
1588
1726
  export declare function parseDocument(markdown: string): MarkdownDocument;
1589
1727
 
@@ -1593,6 +1731,11 @@ export declare function parseDocument(markdown: string): MarkdownDocument;
1593
1731
  *
1594
1732
  * @param text - The inline markdown text to parse.
1595
1733
  * @returns The parsed inline nodes.
1734
+ *
1735
+ * @example
1736
+ * ```ts
1737
+ * parseInline('a *b*') // [{ element: 'text', value: 'a ' }, { element: 'emphasis', ... }]
1738
+ * ```
1596
1739
  */
1597
1740
  export declare function parseInline(text: string): readonly InlineNode[];
1598
1741
 
@@ -1601,11 +1744,17 @@ export declare function parseInline(text: string): readonly InlineNode[];
1601
1744
  *
1602
1745
  * @param markdown - The markdown source to parse.
1603
1746
  * @returns The parsed document and its node-identity span map.
1747
+ *
1748
+ * @example
1749
+ * ```ts
1750
+ * const [document, spans] = parseProvenance('# Hi')
1751
+ * spans.get(document) // { start: 0, end: 4 }
1752
+ * ```
1604
1753
  */
1605
1754
  export declare function parseProvenance(markdown: string): MarkdownParseResult;
1606
1755
 
1607
1756
  /**
1608
- * Project one HTML leaf - a text node, a comment, or a doctype - to its
1757
+ * Projects one HTML leaf - a text node, a comment, or a doctype - to its
1609
1758
  * {@link MarkdownProjection}.
1610
1759
  *
1611
1760
  * @remarks
@@ -1626,7 +1775,7 @@ export declare function parseProvenance(markdown: string): MarkdownParseResult;
1626
1775
  export declare function projectHTMLLeaf(leaf: CommentNode | DoctypeNode | TextNode_2): MarkdownProjection;
1627
1776
 
1628
1777
  /**
1629
- * Project one HTML container - the document root or an element - from its children's
1778
+ * Projects one HTML container - the document root or an element - from its children's
1630
1779
  * already-computed projections. THE element mapping, and the only place that decides
1631
1780
  * what an HTML tag becomes in markdown.
1632
1781
  *
@@ -1663,7 +1812,7 @@ export declare function projectHTMLLeaf(leaf: CommentNode | DoctypeNode | TextNo
1663
1812
  export declare function projectHTMLNode(node: ElementNode | HTMLDocument, children: readonly MarkdownProjection[]): MarkdownProjection;
1664
1813
 
1665
1814
  /**
1666
- * Read a projection as BLOCK content - the view a document, a blockquote, and a list
1815
+ * Reads a projection as BLOCK content - the view a document, a blockquote, and a list
1667
1816
  * item each need.
1668
1817
  *
1669
1818
  * @remarks
@@ -1684,7 +1833,7 @@ export declare function projectHTMLNode(node: ElementNode | HTMLDocument, childr
1684
1833
  export declare function projectionToBlocks(projection: MarkdownProjection): readonly BlockNode[];
1685
1834
 
1686
1835
  /**
1687
- * Read a projection as INLINE content - the view a link, an emphasis, and a table cell
1836
+ * Reads a projection as INLINE content - the view a link, an emphasis, and a table cell
1688
1837
  * each need.
1689
1838
  *
1690
1839
  * @remarks
@@ -1722,7 +1871,7 @@ export declare function projectionToInlines(projection: MarkdownProjection): rea
1722
1871
  export declare function projectSpan(source: MarkdownSource, from: number, to: number): MarkdownSpan | undefined;
1723
1872
 
1724
1873
  /**
1725
- * Render a {@link MarkdownNode} to sanitized canonical HTML.
1874
+ * Renders a {@link MarkdownNode} to sanitized canonical HTML.
1726
1875
  *
1727
1876
  * @remarks
1728
1877
  * Markdown widens `@orkestrel/html`'s attribute floor by exactly `src`, because image
@@ -1743,7 +1892,7 @@ export declare function projectSpan(source: MarkdownSource, from: number, to: nu
1743
1892
  export declare function renderHTML(node: MarkdownNode): string;
1744
1893
 
1745
1894
  /**
1746
- * Render a {@link MarkdownNode} to its CANONICAL markdown source - the inverse
1895
+ * Renders a {@link MarkdownNode} to its CANONICAL markdown source - the inverse
1747
1896
  * projection of `renderHTML`, and the serializer a `parse(renderMarkdown(doc))`
1748
1897
  * round-trip is built on. Canonical forms: `*` / `**` emphasis at even emphasis
1749
1898
  * nesting depths and `_` / `__` at odd depths, `- ` bullets, `N. ` sequential
@@ -1752,8 +1901,8 @@ export declare function renderHTML(node: MarkdownNode): string;
1752
1901
  * `> `-prefixed blockquote lines, GFM tables (1-space-padded cells, `\|`-escaped
1753
1902
  * pipes, an alignment delimiter row), `[text](href)` links, `![alt](src)` images,
1754
1903
  * and two-space hard breaks. A `text` node's literal content is backslash-escaped
1755
- * wherever it would otherwise re-parse as markup (AGENTS §14 parse↔render
1756
- * soundness).
1904
+ * wherever it would otherwise re-parse as markup, so parsing the rendered source
1905
+ * returns the node it was rendered from.
1757
1906
  *
1758
1907
  * @remarks
1759
1908
  * Total: never throws. At {@link MAX_DEPTH} a value-bearing node degrades to its
@@ -1774,7 +1923,7 @@ export declare function renderHTML(node: MarkdownNode): string;
1774
1923
  export declare function renderMarkdown(node: MarkdownNode): string;
1775
1924
 
1776
1925
  /**
1777
- * Rewrite a {@link MarkdownDocument} bottom-up (copy-on-write) - each node's children
1926
+ * Rewrites a {@link MarkdownDocument} bottom-up (copy-on-write) - each node's children
1778
1927
  * are rewritten first (post-order), then `rewrite` is applied to the node itself; the
1779
1928
  * document ROOT is never passed to `rewrite` (the `element: 'document'` invariant
1780
1929
  * always holds). A table's inline cells and a list's items ARE rewritten.
@@ -1809,7 +1958,7 @@ export declare function renderMarkdown(node: MarkdownNode): string;
1809
1958
  export declare function rewriteDocument(document: MarkdownDocument, rewrite: MarkdownRewriteHandler): MarkdownDerivation<MarkdownDocument>;
1810
1959
 
1811
1960
  /**
1812
- * Scan an inline code span at `start` (a `` ` ``-run … a matching `` ` ``-run of the
1961
+ * Scans an inline code span at `start` (a `` ` ``-run … a matching `` ` ``-run of the
1813
1962
  * SAME length, the CommonMark rule that lets a span contain backticks). Returns the
1814
1963
  * span's literal text + end index, or `undefined` when no matching closer exists (it
1815
1964
  * then degrades to literal backticks).
@@ -1824,10 +1973,7 @@ export declare function rewriteDocument(document: MarkdownDocument, rewrite: Mar
1824
1973
  * scanCode('`code`', 0, 6) // { value: 'code', end: 6 }
1825
1974
  * ```
1826
1975
  */
1827
- export declare function scanCode(source: string, start: number, to: number): {
1828
- readonly value: string;
1829
- readonly end: number;
1830
- } | undefined;
1976
+ export declare function scanCode(source: string, start: number, to: number): CodeSpanMatch | undefined;
1831
1977
 
1832
1978
  /**
1833
1979
  * Scans an emphasis run at `start` (`*` / `_`, doubled for strong) - finds the nearest
@@ -1851,13 +1997,10 @@ export declare function scanCode(source: string, start: number, to: number): {
1851
1997
  * // { node: { element: 'emphasis', strong: false, children: [{ element: 'text', value: 'em' }] }, end: 4 }
1852
1998
  * ```
1853
1999
  */
1854
- export declare function scanEmphasis(source: string, start: number, to: number, depth?: number): {
1855
- readonly node: EmphasisNode;
1856
- readonly end: number;
1857
- } | undefined;
2000
+ export declare function scanEmphasis(source: string, start: number, to: number, depth?: number): EmphasisScan | undefined;
1858
2001
 
1859
2002
  /**
1860
- * Scan the window `[from, to)` of `source` into inline nodes - the single recursive
2003
+ * Scans the window `[from, to)` of `source` into inline nodes - the single recursive
1861
2004
  * engine the inline phase runs on (emphasis, link text, and image alternative
1862
2005
  * content recurse through it). Linear:
1863
2006
  * each character is consumed once; a failed construct emits its opening character as
@@ -1867,10 +2010,11 @@ export declare function scanEmphasis(source: string, start: number, to: number,
1867
2010
  * @param from - The inclusive start of the scan window
1868
2011
  * @param to - The exclusive end of the scan window
1869
2012
  * @param depth - The current inline-recursion depth (defaults to 0 at the entry point);
1870
- * incremented by one on every recursive descent through {@link scanLink} /
1871
- * {@link scanEmphasis}. At {@link MAX_DEPTH} the window is never scanned for markup -
1872
- * it emits as a single literal text node - so pathological nesting (`[[[[…`,
1873
- * `****…`) cannot exhaust the call stack.
2013
+ * incremented by one on every recursive descent {@link scanInlineSource} makes into
2014
+ * itself for a link's text, an image's alternative content, or an emphasis run's
2015
+ * children. At {@link MAX_DEPTH} the window is never scanned for markup - it emits as
2016
+ * a single literal text node - so pathological nesting (`[[[[…`, `****…`) cannot
2017
+ * exhaust the call stack.
1874
2018
  * @returns The parsed inline nodes (NOT yet coalesced)
1875
2019
  *
1876
2020
  * @example
@@ -1888,7 +2032,9 @@ export declare function scanInline(source: string, from: number, to: number, dep
1888
2032
  * @param from - The inclusive start of the scan window
1889
2033
  * @param to - The exclusive end of the scan window
1890
2034
  * @param spans - The operation-owned node span recorder
1891
- * @param depth - The current inline-recursion depth
2035
+ * @param depth - The current inline-recursion depth, incremented by one on every
2036
+ * recursive descent this function makes into itself for a link's text, an image's
2037
+ * alternative content, or an emphasis run's children
1892
2038
  * @returns The parsed inline nodes before adjacent text coalescing
1893
2039
  *
1894
2040
  * @example
@@ -1925,10 +2071,7 @@ export declare function scanInlineSource(source: MarkdownSource, from: number, t
1925
2071
  * // { node: { element: 'link', href: 'url', children: [{ element: 'text', value: 'text' }] }, end: 11 }
1926
2072
  * ```
1927
2073
  */
1928
- export declare function scanLink(source: string, start: number, to: number, depth?: number): {
1929
- readonly node: LinkNode;
1930
- readonly end: number;
1931
- } | undefined;
2074
+ export declare function scanLink(source: string, start: number, to: number, depth?: number): LinkScan | undefined;
1932
2075
 
1933
2076
  /**
1934
2077
  * Slices derived markdown text and narrows each intersecting source segment to the
@@ -1963,7 +2106,7 @@ export declare function sliceSource(source: MarkdownSource, from: number, to: nu
1963
2106
  export declare function splitLines(markdown: string): readonly MarkdownSource[];
1964
2107
 
1965
2108
  /**
1966
- * Split one GFM table row into its cell strings - outer pipes are optional, an escaped
2109
+ * Splits one GFM table row into its cell strings - outer pipes are optional, an escaped
1967
2110
  * pipe (`\|`) inside a cell is NOT a separator (it becomes a literal `|`), and the
1968
2111
  * empty leading / trailing cell produced by an outer `|` is dropped. Derives the string
1969
2112
  * form from {@link splitTableSources}, which owns the escaped-pipe splitting rule.
@@ -1993,7 +2136,7 @@ export declare function splitTableRow(row: string): readonly string[];
1993
2136
  export declare function splitTableSources(row: MarkdownSource): readonly MarkdownSource[];
1994
2137
 
1995
2138
  /**
1996
- * Whether the line at `index` starts a NEW block kind (heading / fence / thematic
2139
+ * Checks whether the line at `index` starts a NEW block kind (heading / fence / thematic
1997
2140
  * break / blockquote / list / table) - the paragraph collector stops at such a line
1998
2141
  * so a block following a paragraph without a blank line still parses (a trusted-input
1999
2142
  * caller writing a `##` heading directly under a paragraph, with no intervening blank
@@ -2001,7 +2144,7 @@ export declare function splitTableSources(row: MarkdownSource): readonly Markdow
2001
2144
  *
2002
2145
  * @param lines - The document's lines
2003
2146
  * @param index - The line index to test
2004
- * @returns `true` when the line begins a different block
2147
+ * @returns True if the line begins a different block; false otherwise
2005
2148
  *
2006
2149
  * @example
2007
2150
  * ```ts
@@ -2027,7 +2170,7 @@ export declare function startsBlock(lines: readonly string[], index: number): bo
2027
2170
  export declare function stripQuote(source: MarkdownSource): MarkdownSource;
2028
2171
 
2029
2172
  /**
2030
- * The horizontal alignment of a GFM table column, as declared by its delimiter row
2173
+ * Names the horizontal alignment of a GFM table column, as declared by its delimiter row
2031
2174
  * (`:---` left, `---:` right, `:---:` center). A bare `---` delimiter is represented
2032
2175
  * by `null` in {@link TableNode.align}: the positional array requires one entry per
2033
2176
  * column, JSON cannot carry `undefined` in an array, and the bare delimiter is an
@@ -2036,7 +2179,7 @@ export declare function stripQuote(source: MarkdownSource): MarkdownSource;
2036
2179
  export declare type TableAlign = 'left' | 'right' | 'center';
2037
2180
 
2038
2181
  /**
2039
- * The shape of a {@link TableAlign} - the per-column GFM table alignment
2182
+ * Describes the shape of a {@link TableAlign} - the per-column GFM table alignment
2040
2183
  * literal.
2041
2184
  *
2042
2185
  * @example
@@ -2053,19 +2196,30 @@ export declare type TableAlign = 'left' | 'right' | 'center';
2053
2196
  export declare const tableAlignShape: LiteralShape<readonly ["left", "right", "center"]>;
2054
2197
 
2055
2198
  /**
2056
- * A GFM table - `header` the inline content of each header cell, `rows` the body
2199
+ * Represents the result of collecting one GFM table - the node the construct scanner built and
2200
+ * where the block phase resumes.
2201
+ */
2202
+ export declare interface TableCollection {
2203
+ /** Holds the collected table. */
2204
+ readonly node: TableNode;
2205
+ /** Holds the index of the first line after the table. */
2206
+ readonly next: number;
2207
+ }
2208
+
2209
+ /**
2210
+ * Represents a GFM table - `header` the inline content of each header cell, `rows` the body
2057
2211
  * rows (each a list of cells, each cell inline content), `align` the per-column
2058
2212
  * alignment from the delimiter row. A short body row is padded with empty cells; an
2059
2213
  * over-long one is truncated to the header's column count.
2060
2214
  */
2061
2215
  export declare interface TableNode {
2062
2216
  readonly element: 'table';
2063
- /** The header row - one cell of inline content per column. */
2217
+ /** Holds the header row - one cell of inline content per column. */
2064
2218
  readonly header: ReadonlyArray<readonly InlineNode[]>;
2065
- /** The body rows - each a list of cells, each cell inline content. */
2219
+ /** Holds the body rows - each a list of cells, each cell inline content. */
2066
2220
  readonly rows: ReadonlyArray<ReadonlyArray<readonly InlineNode[]>>;
2067
2221
  /**
2068
- * The per-column alignment from the delimiter row, in column order. `null`
2222
+ * Holds the per-column alignment from the delimiter row, in column order. `null`
2069
2223
  * represents a bare `---` delimiter because this positional array requires one
2070
2224
  * entry per column, JSON cannot carry `undefined` in an array, and the delimiter
2071
2225
  * is an explicit no-alignment marker rather than an omitted value.
@@ -2074,19 +2228,19 @@ export declare interface TableNode {
2074
2228
  }
2075
2229
 
2076
2230
  /**
2077
- * A run of plain text - the leaf inline node. `value` is the decoded text with
2231
+ * Represents a run of plain text - the leaf inline node. `value` is the decoded text with
2078
2232
  * markdown escapes (`\*`, `\_`, …) already resolved to their literal characters;
2079
2233
  * html's text encoder escapes `&`, `<`, `>` on the way out; `"` and `'` stay literal
2080
2234
  * in character data.
2081
2235
  */
2082
2236
  export declare interface TextNode {
2083
2237
  readonly element: 'text';
2084
- /** The literal text content (escapes resolved, NOT yet HTML-escaped). */
2238
+ /** Holds the literal text content (escapes resolved, NOT yet HTML-escaped). */
2085
2239
  readonly value: string;
2086
2240
  }
2087
2241
 
2088
2242
  /**
2089
- * The shape of a {@link TextNode} - a plain-text leaf inline run.
2243
+ * Describes the shape of a {@link TextNode} - a plain-text leaf inline run.
2090
2244
  *
2091
2245
  * @example
2092
2246
  * ```ts
@@ -2102,13 +2256,13 @@ export declare const textShape: ObjectShape<{
2102
2256
  value: StringShape;
2103
2257
  }, false>;
2104
2258
 
2105
- /** A thematic break - a horizontal rule (`---` / `***` / `___` on its own line). */
2259
+ /** Represents a thematic break - a horizontal rule (`---` / `***` / `___` on its own line). */
2106
2260
  export declare interface ThematicBreakNode {
2107
2261
  readonly element: 'thematicBreak';
2108
2262
  }
2109
2263
 
2110
2264
  /**
2111
- * The shape of a {@link ThematicBreakNode} - a horizontal rule. Carries no
2265
+ * Describes the shape of a {@link ThematicBreakNode} - a horizontal rule. Carries no
2112
2266
  * fields beyond its `element` discriminant.
2113
2267
  *
2114
2268
  * @example
@@ -2125,7 +2279,7 @@ export declare const thematicBreakShape: ObjectShape<{
2125
2279
  }, false>;
2126
2280
 
2127
2281
  /**
2128
- * Trim the whitespace at the two ends of an inline run - the leading whitespace of a
2282
+ * Trims the whitespace at the two ends of an inline run - the leading whitespace of a
2129
2283
  * leading text node and the trailing whitespace of a trailing one - dropping either
2130
2284
  * node when nothing survives.
2131
2285
  *
@@ -2159,7 +2313,7 @@ export declare function trimInlines(nodes: readonly InlineNode[]): readonly Inli
2159
2313
  export declare function trimSource(source: MarkdownSource): MarkdownSource;
2160
2314
 
2161
2315
  /**
2162
- * Resolve backslash escapes in a raw string to their literal characters - used for a
2316
+ * Resolves backslash escapes in a raw string to their literal characters - used for a
2163
2317
  * link `href` (which is not otherwise inline-parsed) and any plain text run.
2164
2318
  *
2165
2319
  * @param text - The raw text possibly carrying `\x` escapes
@@ -2173,7 +2327,7 @@ export declare function trimSource(source: MarkdownSource): MarkdownSource;
2173
2327
  export declare function unescapeText(text: string): string;
2174
2328
 
2175
2329
  /**
2176
- * Depth-first, pre-order, root-inclusive traversal of a {@link MarkdownNode} - yields
2330
+ * Walks a {@link MarkdownNode} depth-first, pre-order, root-inclusive - yields
2177
2331
  * the node itself, then recurses into its children (block children, list items,
2178
2332
  * image/link inline children, table header/row cells' inline nodes) in walk order.
2179
2333
  *