@ai-matrx/content-ir 0.18.0 → 0.18.2
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/CHANGELOG.md +44 -0
- package/dist/index.cjs +60 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +53 -17
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +60 -16
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +99 -13
- package/dist/source.d.ts +99 -13
- package/dist/source.js +53 -17
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
package/dist/source.d.cts
CHANGED
|
@@ -350,17 +350,6 @@ declare function looksLikeOpenInlineMath(partial: string): boolean;
|
|
|
350
350
|
*/
|
|
351
351
|
declare function singleDollarMathEnd(text: string, open: number, limit?: number): number;
|
|
352
352
|
|
|
353
|
-
/**
|
|
354
|
-
* XML tag reading + the generic-container balance scanner.
|
|
355
|
-
*
|
|
356
|
-
* Ported VERBATIM (behaviour) from matrx-frontend
|
|
357
|
-
* `components/mardown-display/blocks/xml/readXmlTag.ts` and the
|
|
358
|
-
* `XmlContainerTracker` in
|
|
359
|
-
* `components/mardown-display/markdown-classification/processors/utils/content-splitter-v2.ts`
|
|
360
|
-
* so the source tokenizer ends a generic XML section exactly where the
|
|
361
|
-
* renderer does. The renderer copies stay for rendering (PLAN decision 6);
|
|
362
|
-
* a divergence between the two is a defect in whichever changed last.
|
|
363
|
-
*/
|
|
364
353
|
interface ReadXmlTag {
|
|
365
354
|
tagName: string;
|
|
366
355
|
raw: string;
|
|
@@ -388,7 +377,8 @@ declare class XmlContainerTracker {
|
|
|
388
377
|
private inComment;
|
|
389
378
|
private inCdata;
|
|
390
379
|
private inlineTicks;
|
|
391
|
-
|
|
380
|
+
/** The open fence, read by THE one closer (source/code-ranges.ts). */
|
|
381
|
+
private fence;
|
|
392
382
|
constructor(rootTag: string);
|
|
393
383
|
consumeLine(line: string, startOffset?: number): number | null;
|
|
394
384
|
}
|
|
@@ -454,12 +444,108 @@ interface CodeRange {
|
|
|
454
444
|
end: number;
|
|
455
445
|
kind: "fence" | "span";
|
|
456
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;
|
|
501
|
+
/**
|
|
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
|
+
}
|
|
457
518
|
/**
|
|
458
519
|
* Every code range in the text — fences (by the renderer's rule above) and
|
|
459
520
|
* inline code spans — sorted by start. Linear: one pass over lines, one over
|
|
460
521
|
* each paragraph's backtick runs.
|
|
461
522
|
*/
|
|
462
523
|
declare function findCodeRanges(text: string): CodeRange[];
|
|
524
|
+
/**
|
|
525
|
+
* Rewrite every code range (fences and spans, by THE rule) through `fn`; text
|
|
526
|
+
* outside code is kept byte for byte. The one way to strip, replace or
|
|
527
|
+
* placeholder code in markdown — never a private /```…```/ regex.
|
|
528
|
+
*/
|
|
529
|
+
declare function mapCodeRanges(text: string, fn: (range: CodeRange, raw: string) => string): string;
|
|
530
|
+
/** A code span's text (CommonMark): the backtick runs off, then one padding space each side when both are there and the content is not all spaces. */
|
|
531
|
+
declare function codeSpanText(raw: string): string;
|
|
532
|
+
/**
|
|
533
|
+
* A fence range's parts: its opener, its body (the lines between the opener
|
|
534
|
+
* and the closer, blockquote prefixes kept), and whether it closed. Reads
|
|
535
|
+
* `raw` exactly as `findCodeRanges` returned it.
|
|
536
|
+
*/
|
|
537
|
+
declare function fenceParts(raw: string): {
|
|
538
|
+
opener: FenceOpener;
|
|
539
|
+
body: string;
|
|
540
|
+
closed: boolean;
|
|
541
|
+
} | null;
|
|
542
|
+
type FenceLineKind = "prose" | "open" | "body" | "close";
|
|
543
|
+
/**
|
|
544
|
+
* Where each line (the text split on "\n") sits relative to the fences
|
|
545
|
+
* `findCodeRanges` finds: its opener, its body, its closer, or prose. For a
|
|
546
|
+
* line walker that must skip code — one rule, never a private `inFence` toggle.
|
|
547
|
+
*/
|
|
548
|
+
declare function fenceLineKinds(text: string): FenceLineKind[];
|
|
463
549
|
|
|
464
550
|
/**
|
|
465
551
|
* `$$...$$`, `$$…$$`, `$$ · $$`: a PLACEHOLDER — prose describing the syntax,
|
|
@@ -486,4 +572,4 @@ declare function pendingDisplayMathOpener(text: string): number;
|
|
|
486
572
|
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
487
573
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
488
574
|
|
|
489
|
-
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, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
575
|
+
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, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
package/dist/source.d.ts
CHANGED
|
@@ -350,17 +350,6 @@ declare function looksLikeOpenInlineMath(partial: string): boolean;
|
|
|
350
350
|
*/
|
|
351
351
|
declare function singleDollarMathEnd(text: string, open: number, limit?: number): number;
|
|
352
352
|
|
|
353
|
-
/**
|
|
354
|
-
* XML tag reading + the generic-container balance scanner.
|
|
355
|
-
*
|
|
356
|
-
* Ported VERBATIM (behaviour) from matrx-frontend
|
|
357
|
-
* `components/mardown-display/blocks/xml/readXmlTag.ts` and the
|
|
358
|
-
* `XmlContainerTracker` in
|
|
359
|
-
* `components/mardown-display/markdown-classification/processors/utils/content-splitter-v2.ts`
|
|
360
|
-
* so the source tokenizer ends a generic XML section exactly where the
|
|
361
|
-
* renderer does. The renderer copies stay for rendering (PLAN decision 6);
|
|
362
|
-
* a divergence between the two is a defect in whichever changed last.
|
|
363
|
-
*/
|
|
364
353
|
interface ReadXmlTag {
|
|
365
354
|
tagName: string;
|
|
366
355
|
raw: string;
|
|
@@ -388,7 +377,8 @@ declare class XmlContainerTracker {
|
|
|
388
377
|
private inComment;
|
|
389
378
|
private inCdata;
|
|
390
379
|
private inlineTicks;
|
|
391
|
-
|
|
380
|
+
/** The open fence, read by THE one closer (source/code-ranges.ts). */
|
|
381
|
+
private fence;
|
|
392
382
|
constructor(rootTag: string);
|
|
393
383
|
consumeLine(line: string, startOffset?: number): number | null;
|
|
394
384
|
}
|
|
@@ -454,12 +444,108 @@ interface CodeRange {
|
|
|
454
444
|
end: number;
|
|
455
445
|
kind: "fence" | "span";
|
|
456
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;
|
|
501
|
+
/**
|
|
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
|
+
}
|
|
457
518
|
/**
|
|
458
519
|
* Every code range in the text — fences (by the renderer's rule above) and
|
|
459
520
|
* inline code spans — sorted by start. Linear: one pass over lines, one over
|
|
460
521
|
* each paragraph's backtick runs.
|
|
461
522
|
*/
|
|
462
523
|
declare function findCodeRanges(text: string): CodeRange[];
|
|
524
|
+
/**
|
|
525
|
+
* Rewrite every code range (fences and spans, by THE rule) through `fn`; text
|
|
526
|
+
* outside code is kept byte for byte. The one way to strip, replace or
|
|
527
|
+
* placeholder code in markdown — never a private /```…```/ regex.
|
|
528
|
+
*/
|
|
529
|
+
declare function mapCodeRanges(text: string, fn: (range: CodeRange, raw: string) => string): string;
|
|
530
|
+
/** A code span's text (CommonMark): the backtick runs off, then one padding space each side when both are there and the content is not all spaces. */
|
|
531
|
+
declare function codeSpanText(raw: string): string;
|
|
532
|
+
/**
|
|
533
|
+
* A fence range's parts: its opener, its body (the lines between the opener
|
|
534
|
+
* and the closer, blockquote prefixes kept), and whether it closed. Reads
|
|
535
|
+
* `raw` exactly as `findCodeRanges` returned it.
|
|
536
|
+
*/
|
|
537
|
+
declare function fenceParts(raw: string): {
|
|
538
|
+
opener: FenceOpener;
|
|
539
|
+
body: string;
|
|
540
|
+
closed: boolean;
|
|
541
|
+
} | null;
|
|
542
|
+
type FenceLineKind = "prose" | "open" | "body" | "close";
|
|
543
|
+
/**
|
|
544
|
+
* Where each line (the text split on "\n") sits relative to the fences
|
|
545
|
+
* `findCodeRanges` finds: its opener, its body, its closer, or prose. For a
|
|
546
|
+
* line walker that must skip code — one rule, never a private `inFence` toggle.
|
|
547
|
+
*/
|
|
548
|
+
declare function fenceLineKinds(text: string): FenceLineKind[];
|
|
463
549
|
|
|
464
550
|
/**
|
|
465
551
|
* `$$...$$`, `$$…$$`, `$$ · $$`: a PLACEHOLDER — prose describing the syntax,
|
|
@@ -486,4 +572,4 @@ declare function pendingDisplayMathOpener(text: string): number;
|
|
|
486
572
|
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
487
573
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
488
574
|
|
|
489
|
-
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, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
575
|
+
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, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
package/dist/source.js
CHANGED
|
@@ -392,7 +392,7 @@ function scan(text) {
|
|
|
392
392
|
}
|
|
393
393
|
const count = starts.length;
|
|
394
394
|
const raw = (k) => text.slice(starts[k], ends[k]);
|
|
395
|
-
const out = { ranges: [], paragraphs: [], endsInFence: false, pendingPara: -1 };
|
|
395
|
+
const out = { ranges: [], fences: [], paragraphs: [], endsInFence: false, pendingPara: -1 };
|
|
396
396
|
const rawLines = { count, line: raw };
|
|
397
397
|
let segment = 0;
|
|
398
398
|
for (let k = 0; k < count; k++) {
|
|
@@ -401,6 +401,7 @@ function scan(text) {
|
|
|
401
401
|
prose(text, starts, ends, raw, segment, k, out);
|
|
402
402
|
const end = closeFence(rawLines, k, opener);
|
|
403
403
|
out.ranges.push({ start: starts[k], end: ends[end.line], kind: "fence" });
|
|
404
|
+
out.fences.push([k, end.line, end.closed]);
|
|
404
405
|
out.pendingPara = -1;
|
|
405
406
|
if (!end.closed && end.line === count - 1) out.endsInFence = true;
|
|
406
407
|
k = end.line;
|
|
@@ -466,6 +467,7 @@ function prose(text, starts, ends, raw, from, to, out) {
|
|
|
466
467
|
};
|
|
467
468
|
const end = closeFence(src, k, opener);
|
|
468
469
|
out.ranges.push({ start: starts[k], end: ends[end.line], kind: "fence" });
|
|
470
|
+
out.fences.push([k, end.line, end.closed]);
|
|
469
471
|
if (!end.closed && end.line === starts.length - 1) out.endsInFence = true;
|
|
470
472
|
k = end.line;
|
|
471
473
|
}
|
|
@@ -529,6 +531,45 @@ function findCodeRanges(text) {
|
|
|
529
531
|
for (const [from, to] of s.paragraphs) codeSpans(text, from, to, ranges);
|
|
530
532
|
return ranges.sort((a, b) => a.start - b.start);
|
|
531
533
|
}
|
|
534
|
+
function mapCodeRanges(text, fn) {
|
|
535
|
+
let out = "";
|
|
536
|
+
let at = 0;
|
|
537
|
+
for (const r of findCodeRanges(text)) {
|
|
538
|
+
if (r.start < at) continue;
|
|
539
|
+
out += text.slice(at, r.start) + fn(r, text.slice(r.start, r.end));
|
|
540
|
+
at = r.end;
|
|
541
|
+
}
|
|
542
|
+
return out + text.slice(at);
|
|
543
|
+
}
|
|
544
|
+
function codeSpanText(raw) {
|
|
545
|
+
const ticks = backtickRunLength(raw, 0);
|
|
546
|
+
const inner = raw.slice(ticks, raw.length - ticks);
|
|
547
|
+
return inner.length >= 2 && inner.startsWith(" ") && inner.endsWith(" ") && inner.trim() !== "" ? inner.slice(1, -1) : inner;
|
|
548
|
+
}
|
|
549
|
+
function fenceParts(raw) {
|
|
550
|
+
const lines = raw.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
|
|
551
|
+
const { offset } = quotePrefix(lines[0] ?? "");
|
|
552
|
+
const opener = fenceOpenerOf((lines[0] ?? "").slice(offset).replace(/^ *(?:[-*+]|\d{1,9}[.)])(?= |\t|$) ?/, ""));
|
|
553
|
+
if (!opener) return null;
|
|
554
|
+
const rest = lines.slice(1);
|
|
555
|
+
const closed = rest.length > 0 && new FenceReader(opener, { nesting: false }).feed(rest[rest.length - 1]);
|
|
556
|
+
if (!closed) return { opener, body: rest.join("\n"), closed };
|
|
557
|
+
const last = rest[rest.length - 1];
|
|
558
|
+
const before = trimFenceLine(last).startsWith("```") ? "" : last.slice(0, last.indexOf("```"));
|
|
559
|
+
return { opener, body: [...rest.slice(0, -1), ...before.trim() ? [before] : []].join("\n"), closed };
|
|
560
|
+
}
|
|
561
|
+
function fenceLineKinds(text) {
|
|
562
|
+
const s = scan(text);
|
|
563
|
+
let count = 1;
|
|
564
|
+
for (let i = text.indexOf("\n"); i !== -1; i = text.indexOf("\n", i + 1)) count++;
|
|
565
|
+
const kinds = new Array(count).fill("prose");
|
|
566
|
+
for (const [open, last, closed] of s.fences) {
|
|
567
|
+
kinds[open] = "open";
|
|
568
|
+
for (let k = open + 1; k <= last; k++) kinds[k] = "body";
|
|
569
|
+
if (closed && last > open) kinds[last] = "close";
|
|
570
|
+
}
|
|
571
|
+
return kinds;
|
|
572
|
+
}
|
|
532
573
|
function pendingCodeSpanStart(text) {
|
|
533
574
|
const n = text.length;
|
|
534
575
|
if (n === 0 || /\n[ \t]*\n[ \t]*$/.test(text)) return -1;
|
|
@@ -827,25 +868,20 @@ var XmlContainerTracker = class {
|
|
|
827
868
|
inComment = false;
|
|
828
869
|
inCdata = false;
|
|
829
870
|
inlineTicks = 0;
|
|
830
|
-
|
|
871
|
+
/** The open fence, read by THE one closer (source/code-ranges.ts). */
|
|
872
|
+
fence = null;
|
|
831
873
|
consumeLine(line, startOffset = 0) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
return null;
|
|
841
|
-
}
|
|
842
|
-
if (char === this.fenceMarker.char && marker.length >= this.fenceMarker.ticks && suffix.trim() === "") {
|
|
843
|
-
this.fenceMarker = null;
|
|
844
|
-
}
|
|
874
|
+
if (this.fence) {
|
|
875
|
+
if (this.fence.feed(line)) this.fence = null;
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
878
|
+
if (!this.inComment && !this.inCdata && this.inlineTicks === 0) {
|
|
879
|
+
const opener = fenceOpenerOf(line);
|
|
880
|
+
if (opener) {
|
|
881
|
+
this.fence = new FenceReader(opener);
|
|
845
882
|
return null;
|
|
846
883
|
}
|
|
847
884
|
}
|
|
848
|
-
if (this.fenceMarker) return null;
|
|
849
885
|
for (let i = startOffset; i < line.length; i++) {
|
|
850
886
|
if (this.inlineTicks > 0) {
|
|
851
887
|
if (line[i] === "`") {
|
|
@@ -2335,6 +2371,6 @@ function mapRange(changes, start, end, unit = "utf16") {
|
|
|
2335
2371
|
return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
|
|
2336
2372
|
}
|
|
2337
2373
|
|
|
2338
|
-
export { CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
2374
|
+
export { BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
2339
2375
|
//# sourceMappingURL=source.js.map
|
|
2340
2376
|
//# sourceMappingURL=source.js.map
|