@ai-matrx/content-ir 0.17.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/source.d.cts CHANGED
@@ -300,21 +300,48 @@ declare function toCodePointOffset(text: string, utf16: number): number;
300
300
  declare function toUtf16Offset(text: string, codePoint: number): number;
301
301
 
302
302
  /**
303
- * THE single-dollar math rule — the one predicate that decides whether
304
- * `$…$` is inline math or currency.
303
+ * THE single-dollar math rule — the one predicate that decides whether a
304
+ * CLOSED `$…$` is inline math or currency, on screen, in every export and in
305
+ * the editor's islands (the renderer's normalizer, the source tokenizer and
306
+ * print all ask it).
305
307
  *
306
- * Moved here from matrx-frontend `components/markdown-core/math-normalizer.ts`
307
- * (2026-09-23) so the renderer's normalizer and the source tokenizer can never
308
- * disagree about which bytes are math: the normalizer imports this function.
309
- *
310
- * Pandoc's rule — the opening `$` is not followed by whitespace, the closing
311
- * `$` is not preceded by whitespace and not followed by a digit — plus a math
312
- * signal: a TeX command or operator (`\alpha`, `^`, `_`, `{`, `=`, …), a
313
- * lone variable (`$x$`, `$n$`, `$x'$`), or a single-letter math shape
314
- * (`$f(g(x))$`, `$u v$`, `$f'(x)$` — see `isMathShape`). Content that opens with a digit needs
315
- * a real TeX signal, so a price range can never read as math.
308
+ * Pandoc's `tex_math_dollars` delimiters (what remark-math approximates, and
309
+ * how ChatGPT and Claude render): the opening `$` is followed by a
310
+ * non-space, the closing `$` is preceded by a non-space and not followed by a
311
+ * digit — so `$5 and $10`, `$5-$10`, `$5/$10` stay currency while `$FC$`,
312
+ * `$AB$`, `$5$` and `$(0, 0)$` are math. On top of that, content that reads as
313
+ * something other than a formula is refused — each guard is a false positive
314
+ * measured in stored answers (matrx-frontend
315
+ * `scripts/measure-single-dollar-rule.ts`, 2026-09-25: over 85k assistant
316
+ * messages and 4k notes the widening adds 128 spans, every one a formula
317
+ * (`$FC$`, `$(0, 0)$`, `$3x + 6 = 15$`), and drops 22 the old rule drew as
318
+ * math that were code, template literals, a printf or broken TeX):
319
+ * - an unescaped `%` — TeX's comment character, and a percentage
320
+ * (`$\ge$20% owners**…**$`, a printf `%1$s`);
321
+ * - a closing bracket or `/` first, or an opening bracket last
322
+ * (`[$X] plus [$Y]`, `($/SF/Yr) | High-Cost Market ($`, a regex
323
+ * `/…/, '').replace(/…$`), or a straight quote at either end (`["$", "$"]`
324
+ * in data);
325
+ * - `:` `;` `,` `/` last — a separator between two `$` words
326
+ * (`$HOME/.local/bin:$PATH`, `$AAPL/$TSLA`);
327
+ * - a number glued to a following letter (`$10$N9qo…`, a bcrypt cost);
328
+ * - a placeholder (`$...$`);
329
+ * - prose, unless a TeX command or operator says otherwise: two plain
330
+ * words (`$Tipping (fee)$`), a contraction (`$I'm$`, never `$X'Y$`), an
331
+ * abbreviation (`$e.g. (x)$`).
316
332
  */
317
333
  declare function isSingleDollarMath(content: string, after: string | undefined): boolean;
334
+ /**
335
+ * Whether an UNCLOSED `$…` already reads as a formula — for a stream that
336
+ * must decide before the closing `$` arrives (matrx-frontend `stream-heal`
337
+ * holds such a tail back instead of printing raw TeX). Stricter than
338
+ * {@link isSingleDollarMath} on purpose: with no closer there are no Pandoc
339
+ * delimiter facts yet, so it needs a math SIGNAL — a TeX command or operator
340
+ * (`\alpha`, `^`, `_`, `{`, `=`, …), a lone variable (`x`, `x'`), or a
341
+ * single-letter math shape (`f(g(x))`, `u v`). Content that opens with a digit
342
+ * needs a real TeX command, so `$35 per stop` keeps showing while it streams.
343
+ */
344
+ declare function looksLikeOpenInlineMath(partial: string): boolean;
318
345
  /**
319
346
  * Where a single-dollar math span opened at `open` (a lone `$`) closes, or -1.
320
347
  * Same scan the normalizer uses: same line, backslash-escapes skipped, the
@@ -323,17 +350,6 @@ declare function isSingleDollarMath(content: string, after: string | undefined):
323
350
  */
324
351
  declare function singleDollarMathEnd(text: string, open: number, limit?: number): number;
325
352
 
326
- /**
327
- * XML tag reading + the generic-container balance scanner.
328
- *
329
- * Ported VERBATIM (behaviour) from matrx-frontend
330
- * `components/mardown-display/blocks/xml/readXmlTag.ts` and the
331
- * `XmlContainerTracker` in
332
- * `components/mardown-display/markdown-classification/processors/utils/content-splitter-v2.ts`
333
- * so the source tokenizer ends a generic XML section exactly where the
334
- * renderer does. The renderer copies stay for rendering (PLAN decision 6);
335
- * a divergence between the two is a defect in whichever changed last.
336
- */
337
353
  interface ReadXmlTag {
338
354
  tagName: string;
339
355
  raw: string;
@@ -361,7 +377,8 @@ declare class XmlContainerTracker {
361
377
  private inComment;
362
378
  private inCdata;
363
379
  private inlineTicks;
364
- private fenceMarker;
380
+ /** The open fence, read by THE one closer (source/code-ranges.ts). */
381
+ private fence;
365
382
  constructor(rootTag: string);
366
383
  consumeLine(line: string, startOffset?: number): number | null;
367
384
  }
@@ -423,26 +440,94 @@ declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nest
423
440
  interface CodeRange {
424
441
  /** UTF-16 offset of the first character (the fence line start, or the opening backtick run). */
425
442
  start: number;
426
- /** Offset just past the closing fence line's last character / closing backtick run (end of text when unclosed). */
443
+ /** Offset just past the closing fence line's content / closing backtick run (the fence's last line when unclosed). */
427
444
  end: number;
428
445
  kind: "fence" | "span";
429
446
  }
447
+ interface FenceOpener {
448
+ char: "`" | "~";
449
+ /** Length of the opening run. */
450
+ ticks: number;
451
+ /** The info string's first word ("" when none). */
452
+ lang: string;
453
+ }
454
+ /**
455
+ * THE opener rule for one line's content (container prefixes already
456
+ * removed; for a tilde fence, `content` starts at the container's column).
457
+ */
458
+ declare function fenceOpenerOf(content: string): FenceOpener | null;
459
+ /** The lines a fence is read from. */
460
+ interface FenceLines {
461
+ count: number;
462
+ /** Line `k`'s content (no terminator), or null when the fence's container has ended before it. */
463
+ line(k: number): string | null;
464
+ /** Streaming: line `k` has not ended yet, so it closes nothing. */
465
+ openTail?(k: number): boolean;
466
+ }
467
+ interface FenceEnd {
468
+ /** The closing line when `closed`; otherwise the fence's last line (text end, or the line before its container ended). */
469
+ line: number;
470
+ closed: boolean;
471
+ }
472
+ /**
473
+ * THE closer rule, read line by line — the one implementation behind
474
+ * `closeFence` and every streaming walker. Feed each following line
475
+ * (container prefixes removed); `feed` returns true on the line that closes
476
+ * the fence. A backtick fence closes by the nested-fence rule or the
477
+ * renderer's line-end closer (`code````), and inside ```json a backtick run in
478
+ * a JSON string is text; a tilde fence closes on `~~~` (≥ its length, ≤ 3
479
+ * spaces). `nesting: false` forces strict CommonMark (the retry `closeFence`
480
+ * makes when a nested fence is left open at the end; a streaming reader
481
+ * cannot look ahead, so it reads with nesting and never retries).
482
+ */
483
+ declare class FenceReader {
484
+ readonly opener: FenceOpener;
485
+ private state;
486
+ private depth;
487
+ /** A nested fence was opened at some point. */
488
+ sawNested: boolean;
489
+ private readonly isJson;
490
+ private readonly nesting;
491
+ private readonly tildeCloser;
492
+ constructor(opener: FenceOpener, options?: {
493
+ nesting?: boolean;
494
+ });
495
+ /** How many nested fences are open right now. */
496
+ get nestedDepth(): number;
497
+ feed(line: string): boolean;
498
+ }
499
+ /** Where the fence opened on line `open` ends. */
500
+ declare function closeFence(src: FenceLines, open: number, opener: FenceOpener): FenceEnd;
430
501
  /**
431
- * Where code is, by CommonMark — THE ONE code-range rule for every package.
432
- * Math pairing (`pairDisplayMath`), the tokenizer's math islands, print's math
433
- * lifting and kit's delimiter guard all ask this function; a second copy of
434
- * code detection anywhere in `apps/shared` fails
435
- * `__tests__/one-code-range-rule.test.ts`.
436
- * - A fence opens only at the START of a line (≤ 3 spaces of indent): a
437
- * mid-sentence "```python" is text, not a fence that swallows everything
438
- * after it (verify-RC-B9: one inline ``` turned math off for the rest of
439
- * the answer). Closing follows THE ONE nested-fence rule
440
- * (`classifyInnerFenceLine`); an unclosed fence runs to the end.
441
- * - An inline code span closes only at a backtick run of the SAME length in
442
- * the same paragraph; an unmatched run is literal text.
443
- * Linear: one pass over lines, one over each paragraph's backtick runs.
502
+ * THE code-span pairing table for one paragraph, text[from, to): a backtick
503
+ * run closes at the first LATER run of exactly its length; a run with none is
504
+ * literal text. `findCodeRanges` pairs runs in order; the tokenizer's inline
505
+ * scanner asks `next` in the renderer's leftmost-first inline order.
506
+ */
507
+ declare class BacktickRuns {
508
+ /** Every run, in order: [start, length]. */
509
+ readonly all: Array<[number, number]>;
510
+ private readonly byLength;
511
+ private readonly indexOf;
512
+ constructor(text: string, from: number, to: number);
513
+ /** Start of the first run of exactly `n` backticks at or after `after`, or -1. */
514
+ next(n: number, after: number): number;
515
+ /** Index of the run starting at `start` in `all`. */
516
+ index(start: number): number;
517
+ }
518
+ /**
519
+ * Every code range in the text — fences (by the renderer's rule above) and
520
+ * inline code spans — sorted by start. Linear: one pass over lines, one over
521
+ * each paragraph's backtick runs.
444
522
  */
445
523
  declare function findCodeRanges(text: string): CodeRange[];
524
+ type FenceLineKind = "prose" | "open" | "body" | "close";
525
+ /**
526
+ * Where each line (the text split on "\n") sits relative to the fences
527
+ * `findCodeRanges` finds: its opener, its body, its closer, or prose. For a
528
+ * line walker that must skip code — one rule, never a private `inFence` toggle.
529
+ */
530
+ declare function fenceLineKinds(text: string): FenceLineKind[];
446
531
 
447
532
  /**
448
533
  * `$$...$$`, `$$…$$`, `$$ · $$`: a PLACEHOLDER — prose describing the syntax,
@@ -469,4 +554,4 @@ declare function pendingDisplayMathOpener(text: string): number;
469
554
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
470
555
  declare function pairDisplayMath(text: string): Map<number, number>;
471
556
 
472
- export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
557
+ export { BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
package/dist/source.d.ts CHANGED
@@ -300,21 +300,48 @@ declare function toCodePointOffset(text: string, utf16: number): number;
300
300
  declare function toUtf16Offset(text: string, codePoint: number): number;
301
301
 
302
302
  /**
303
- * THE single-dollar math rule — the one predicate that decides whether
304
- * `$…$` is inline math or currency.
303
+ * THE single-dollar math rule — the one predicate that decides whether a
304
+ * CLOSED `$…$` is inline math or currency, on screen, in every export and in
305
+ * the editor's islands (the renderer's normalizer, the source tokenizer and
306
+ * print all ask it).
305
307
  *
306
- * Moved here from matrx-frontend `components/markdown-core/math-normalizer.ts`
307
- * (2026-09-23) so the renderer's normalizer and the source tokenizer can never
308
- * disagree about which bytes are math: the normalizer imports this function.
309
- *
310
- * Pandoc's rule — the opening `$` is not followed by whitespace, the closing
311
- * `$` is not preceded by whitespace and not followed by a digit — plus a math
312
- * signal: a TeX command or operator (`\alpha`, `^`, `_`, `{`, `=`, …), a
313
- * lone variable (`$x$`, `$n$`, `$x'$`), or a single-letter math shape
314
- * (`$f(g(x))$`, `$u v$`, `$f'(x)$` — see `isMathShape`). Content that opens with a digit needs
315
- * a real TeX signal, so a price range can never read as math.
308
+ * Pandoc's `tex_math_dollars` delimiters (what remark-math approximates, and
309
+ * how ChatGPT and Claude render): the opening `$` is followed by a
310
+ * non-space, the closing `$` is preceded by a non-space and not followed by a
311
+ * digit — so `$5 and $10`, `$5-$10`, `$5/$10` stay currency while `$FC$`,
312
+ * `$AB$`, `$5$` and `$(0, 0)$` are math. On top of that, content that reads as
313
+ * something other than a formula is refused — each guard is a false positive
314
+ * measured in stored answers (matrx-frontend
315
+ * `scripts/measure-single-dollar-rule.ts`, 2026-09-25: over 85k assistant
316
+ * messages and 4k notes the widening adds 128 spans, every one a formula
317
+ * (`$FC$`, `$(0, 0)$`, `$3x + 6 = 15$`), and drops 22 the old rule drew as
318
+ * math that were code, template literals, a printf or broken TeX):
319
+ * - an unescaped `%` — TeX's comment character, and a percentage
320
+ * (`$\ge$20% owners**…**$`, a printf `%1$s`);
321
+ * - a closing bracket or `/` first, or an opening bracket last
322
+ * (`[$X] plus [$Y]`, `($/SF/Yr) | High-Cost Market ($`, a regex
323
+ * `/…/, '').replace(/…$`), or a straight quote at either end (`["$", "$"]`
324
+ * in data);
325
+ * - `:` `;` `,` `/` last — a separator between two `$` words
326
+ * (`$HOME/.local/bin:$PATH`, `$AAPL/$TSLA`);
327
+ * - a number glued to a following letter (`$10$N9qo…`, a bcrypt cost);
328
+ * - a placeholder (`$...$`);
329
+ * - prose, unless a TeX command or operator says otherwise: two plain
330
+ * words (`$Tipping (fee)$`), a contraction (`$I'm$`, never `$X'Y$`), an
331
+ * abbreviation (`$e.g. (x)$`).
316
332
  */
317
333
  declare function isSingleDollarMath(content: string, after: string | undefined): boolean;
334
+ /**
335
+ * Whether an UNCLOSED `$…` already reads as a formula — for a stream that
336
+ * must decide before the closing `$` arrives (matrx-frontend `stream-heal`
337
+ * holds such a tail back instead of printing raw TeX). Stricter than
338
+ * {@link isSingleDollarMath} on purpose: with no closer there are no Pandoc
339
+ * delimiter facts yet, so it needs a math SIGNAL — a TeX command or operator
340
+ * (`\alpha`, `^`, `_`, `{`, `=`, …), a lone variable (`x`, `x'`), or a
341
+ * single-letter math shape (`f(g(x))`, `u v`). Content that opens with a digit
342
+ * needs a real TeX command, so `$35 per stop` keeps showing while it streams.
343
+ */
344
+ declare function looksLikeOpenInlineMath(partial: string): boolean;
318
345
  /**
319
346
  * Where a single-dollar math span opened at `open` (a lone `$`) closes, or -1.
320
347
  * Same scan the normalizer uses: same line, backslash-escapes skipped, the
@@ -323,17 +350,6 @@ declare function isSingleDollarMath(content: string, after: string | undefined):
323
350
  */
324
351
  declare function singleDollarMathEnd(text: string, open: number, limit?: number): number;
325
352
 
326
- /**
327
- * XML tag reading + the generic-container balance scanner.
328
- *
329
- * Ported VERBATIM (behaviour) from matrx-frontend
330
- * `components/mardown-display/blocks/xml/readXmlTag.ts` and the
331
- * `XmlContainerTracker` in
332
- * `components/mardown-display/markdown-classification/processors/utils/content-splitter-v2.ts`
333
- * so the source tokenizer ends a generic XML section exactly where the
334
- * renderer does. The renderer copies stay for rendering (PLAN decision 6);
335
- * a divergence between the two is a defect in whichever changed last.
336
- */
337
353
  interface ReadXmlTag {
338
354
  tagName: string;
339
355
  raw: string;
@@ -361,7 +377,8 @@ declare class XmlContainerTracker {
361
377
  private inComment;
362
378
  private inCdata;
363
379
  private inlineTicks;
364
- private fenceMarker;
380
+ /** The open fence, read by THE one closer (source/code-ranges.ts). */
381
+ private fence;
365
382
  constructor(rootTag: string);
366
383
  consumeLine(line: string, startOffset?: number): number | null;
367
384
  }
@@ -423,26 +440,94 @@ declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nest
423
440
  interface CodeRange {
424
441
  /** UTF-16 offset of the first character (the fence line start, or the opening backtick run). */
425
442
  start: number;
426
- /** Offset just past the closing fence line's last character / closing backtick run (end of text when unclosed). */
443
+ /** Offset just past the closing fence line's content / closing backtick run (the fence's last line when unclosed). */
427
444
  end: number;
428
445
  kind: "fence" | "span";
429
446
  }
447
+ interface FenceOpener {
448
+ char: "`" | "~";
449
+ /** Length of the opening run. */
450
+ ticks: number;
451
+ /** The info string's first word ("" when none). */
452
+ lang: string;
453
+ }
454
+ /**
455
+ * THE opener rule for one line's content (container prefixes already
456
+ * removed; for a tilde fence, `content` starts at the container's column).
457
+ */
458
+ declare function fenceOpenerOf(content: string): FenceOpener | null;
459
+ /** The lines a fence is read from. */
460
+ interface FenceLines {
461
+ count: number;
462
+ /** Line `k`'s content (no terminator), or null when the fence's container has ended before it. */
463
+ line(k: number): string | null;
464
+ /** Streaming: line `k` has not ended yet, so it closes nothing. */
465
+ openTail?(k: number): boolean;
466
+ }
467
+ interface FenceEnd {
468
+ /** The closing line when `closed`; otherwise the fence's last line (text end, or the line before its container ended). */
469
+ line: number;
470
+ closed: boolean;
471
+ }
472
+ /**
473
+ * THE closer rule, read line by line — the one implementation behind
474
+ * `closeFence` and every streaming walker. Feed each following line
475
+ * (container prefixes removed); `feed` returns true on the line that closes
476
+ * the fence. A backtick fence closes by the nested-fence rule or the
477
+ * renderer's line-end closer (`code````), and inside ```json a backtick run in
478
+ * a JSON string is text; a tilde fence closes on `~~~` (≥ its length, ≤ 3
479
+ * spaces). `nesting: false` forces strict CommonMark (the retry `closeFence`
480
+ * makes when a nested fence is left open at the end; a streaming reader
481
+ * cannot look ahead, so it reads with nesting and never retries).
482
+ */
483
+ declare class FenceReader {
484
+ readonly opener: FenceOpener;
485
+ private state;
486
+ private depth;
487
+ /** A nested fence was opened at some point. */
488
+ sawNested: boolean;
489
+ private readonly isJson;
490
+ private readonly nesting;
491
+ private readonly tildeCloser;
492
+ constructor(opener: FenceOpener, options?: {
493
+ nesting?: boolean;
494
+ });
495
+ /** How many nested fences are open right now. */
496
+ get nestedDepth(): number;
497
+ feed(line: string): boolean;
498
+ }
499
+ /** Where the fence opened on line `open` ends. */
500
+ declare function closeFence(src: FenceLines, open: number, opener: FenceOpener): FenceEnd;
430
501
  /**
431
- * Where code is, by CommonMark — THE ONE code-range rule for every package.
432
- * Math pairing (`pairDisplayMath`), the tokenizer's math islands, print's math
433
- * lifting and kit's delimiter guard all ask this function; a second copy of
434
- * code detection anywhere in `apps/shared` fails
435
- * `__tests__/one-code-range-rule.test.ts`.
436
- * - A fence opens only at the START of a line (≤ 3 spaces of indent): a
437
- * mid-sentence "```python" is text, not a fence that swallows everything
438
- * after it (verify-RC-B9: one inline ``` turned math off for the rest of
439
- * the answer). Closing follows THE ONE nested-fence rule
440
- * (`classifyInnerFenceLine`); an unclosed fence runs to the end.
441
- * - An inline code span closes only at a backtick run of the SAME length in
442
- * the same paragraph; an unmatched run is literal text.
443
- * Linear: one pass over lines, one over each paragraph's backtick runs.
502
+ * THE code-span pairing table for one paragraph, text[from, to): a backtick
503
+ * run closes at the first LATER run of exactly its length; a run with none is
504
+ * literal text. `findCodeRanges` pairs runs in order; the tokenizer's inline
505
+ * scanner asks `next` in the renderer's leftmost-first inline order.
506
+ */
507
+ declare class BacktickRuns {
508
+ /** Every run, in order: [start, length]. */
509
+ readonly all: Array<[number, number]>;
510
+ private readonly byLength;
511
+ private readonly indexOf;
512
+ constructor(text: string, from: number, to: number);
513
+ /** Start of the first run of exactly `n` backticks at or after `after`, or -1. */
514
+ next(n: number, after: number): number;
515
+ /** Index of the run starting at `start` in `all`. */
516
+ index(start: number): number;
517
+ }
518
+ /**
519
+ * Every code range in the text — fences (by the renderer's rule above) and
520
+ * inline code spans — sorted by start. Linear: one pass over lines, one over
521
+ * each paragraph's backtick runs.
444
522
  */
445
523
  declare function findCodeRanges(text: string): CodeRange[];
524
+ type FenceLineKind = "prose" | "open" | "body" | "close";
525
+ /**
526
+ * Where each line (the text split on "\n") sits relative to the fences
527
+ * `findCodeRanges` finds: its opener, its body, its closer, or prose. For a
528
+ * line walker that must skip code — one rule, never a private `inFence` toggle.
529
+ */
530
+ declare function fenceLineKinds(text: string): FenceLineKind[];
446
531
 
447
532
  /**
448
533
  * `$$...$$`, `$$…$$`, `$$ · $$`: a PLACEHOLDER — prose describing the syntax,
@@ -469,4 +554,4 @@ declare function pendingDisplayMathOpener(text: string): number;
469
554
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
470
555
  declare function pairDisplayMath(text: string): Map<number, number>;
471
556
 
472
- export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
557
+ export { BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };