@ai-matrx/content-ir 0.15.0 → 0.16.0
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 +45 -0
- package/dist/index.cjs +114 -9
- 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 +114 -10
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +114 -9
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +26 -3
- package/dist/source.d.ts +26 -3
- package/dist/source.js +114 -10
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
package/dist/source.d.cts
CHANGED
|
@@ -118,6 +118,16 @@ interface TokenizeOptions {
|
|
|
118
118
|
* Omit for stored text: a complete document's last line is final.
|
|
119
119
|
*/
|
|
120
120
|
readonly streaming?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* DIAGNOSTIC — complexity tests only. When given, every loop that walks the
|
|
123
|
+
* text itself adds the characters it visits to `meter.work`, so a test can
|
|
124
|
+
* assert the tokenizer's work grows linearly with its input (deterministic,
|
|
125
|
+
* unlike wall-clock timing). Loops over a slice are not charged here: the
|
|
126
|
+
* slice's own cost covers them. Omit in production.
|
|
127
|
+
*/
|
|
128
|
+
readonly meter?: {
|
|
129
|
+
work: number;
|
|
130
|
+
};
|
|
121
131
|
}
|
|
122
132
|
declare function tokenizeSource(text: string, options?: TokenizeOptions): SourceBlock[];
|
|
123
133
|
/** The exact source the blocks were cut from. */
|
|
@@ -425,9 +435,22 @@ declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nest
|
|
|
425
435
|
* a lone `$$` (a stray closer, or an opener that never closed) never locks
|
|
426
436
|
* anything. Linear time: one regex pass per code shape, one sweep.
|
|
427
437
|
*/
|
|
428
|
-
/**
|
|
429
|
-
|
|
438
|
+
/**
|
|
439
|
+
* The guard's `looksLikeMath`. `flow` = the opener is alone on its line: a
|
|
440
|
+
* flow block may span blank lines (like a fence); a `$$` with text beside it
|
|
441
|
+
* never crosses one — TeX's rule, and what keeps a stray prose `$$` from
|
|
442
|
+
* pairing with the next paragraph's formula.
|
|
443
|
+
*/
|
|
444
|
+
declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
|
|
430
445
|
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
446
|
+
/**
|
|
447
|
+
* STREAMING: the last `$$` token that is still unpaired AND could still pair
|
|
448
|
+
* with a `$$` not yet arrived — its span so far is short enough, carries no
|
|
449
|
+
* markdown structure, not too many prose words, and (unless it opens a flow
|
|
450
|
+
* block) no blank line. Everything after it may yet become math, so a
|
|
451
|
+
* streaming tokenizer treats it as provisional. -1 when there is none.
|
|
452
|
+
*/
|
|
453
|
+
declare function pendingDisplayMathOpener(text: string): number;
|
|
431
454
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
432
455
|
|
|
433
|
-
export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, 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, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
456
|
+
export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, 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, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
package/dist/source.d.ts
CHANGED
|
@@ -118,6 +118,16 @@ interface TokenizeOptions {
|
|
|
118
118
|
* Omit for stored text: a complete document's last line is final.
|
|
119
119
|
*/
|
|
120
120
|
readonly streaming?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* DIAGNOSTIC — complexity tests only. When given, every loop that walks the
|
|
123
|
+
* text itself adds the characters it visits to `meter.work`, so a test can
|
|
124
|
+
* assert the tokenizer's work grows linearly with its input (deterministic,
|
|
125
|
+
* unlike wall-clock timing). Loops over a slice are not charged here: the
|
|
126
|
+
* slice's own cost covers them. Omit in production.
|
|
127
|
+
*/
|
|
128
|
+
readonly meter?: {
|
|
129
|
+
work: number;
|
|
130
|
+
};
|
|
121
131
|
}
|
|
122
132
|
declare function tokenizeSource(text: string, options?: TokenizeOptions): SourceBlock[];
|
|
123
133
|
/** The exact source the blocks were cut from. */
|
|
@@ -425,9 +435,22 @@ declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nest
|
|
|
425
435
|
* a lone `$$` (a stray closer, or an opener that never closed) never locks
|
|
426
436
|
* anything. Linear time: one regex pass per code shape, one sweep.
|
|
427
437
|
*/
|
|
428
|
-
/**
|
|
429
|
-
|
|
438
|
+
/**
|
|
439
|
+
* The guard's `looksLikeMath`. `flow` = the opener is alone on its line: a
|
|
440
|
+
* flow block may span blank lines (like a fence); a `$$` with text beside it
|
|
441
|
+
* never crosses one — TeX's rule, and what keeps a stray prose `$$` from
|
|
442
|
+
* pairing with the next paragraph's formula.
|
|
443
|
+
*/
|
|
444
|
+
declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
|
|
430
445
|
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
446
|
+
/**
|
|
447
|
+
* STREAMING: the last `$$` token that is still unpaired AND could still pair
|
|
448
|
+
* with a `$$` not yet arrived — its span so far is short enough, carries no
|
|
449
|
+
* markdown structure, not too many prose words, and (unless it opens a flow
|
|
450
|
+
* block) no blank line. Everything after it may yet become math, so a
|
|
451
|
+
* streaming tokenizer treats it as provisional. -1 when there is none.
|
|
452
|
+
*/
|
|
453
|
+
declare function pendingDisplayMathOpener(text: string): number;
|
|
431
454
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
432
455
|
|
|
433
|
-
export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, 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, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
456
|
+
export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, 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, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
package/dist/source.js
CHANGED
|
@@ -319,15 +319,20 @@ var STRUCTURAL_MARKDOWN = /\]\(|https?:\/\/|\*\*|(?:^|\n)[ \t]{0,3}#{1,6}[ \t]|(
|
|
|
319
319
|
var LATEX_COMMAND = /\\[a-zA-Z]/;
|
|
320
320
|
var PROSE_WORD = /[A-Za-z]{3,}/g;
|
|
321
321
|
var PROSE_WORD_LIMIT = 6;
|
|
322
|
-
function
|
|
322
|
+
function opensFlowBlock(text, open) {
|
|
323
|
+
for (let k = open - 1; k >= 0 && text[k] !== "\n"; k--) if (text[k] !== " " && text[k] !== " ") return false;
|
|
324
|
+
for (let k = open + 2; k < text.length && text[k] !== "\n"; k++) if (text[k] !== " " && text[k] !== " " && text[k] !== "\r") return false;
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
function looksLikeDisplayMath(inner, flow = false) {
|
|
323
328
|
const s = inner.trim();
|
|
324
329
|
if (!s) return false;
|
|
325
330
|
if (STRUCTURAL_MARKDOWN.test(s)) return false;
|
|
326
331
|
if (s.length > MAX_MATH_SPAN) return false;
|
|
332
|
+
if (!flow && /\n[ \t]*\n/.test(inner)) return false;
|
|
327
333
|
if (LATEX_COMMAND.test(s)) {
|
|
328
334
|
return (s.match(PROSE_WORD) ?? []).length < PROSE_WORD_LIMIT * 3;
|
|
329
335
|
}
|
|
330
|
-
if (/\n[ \t]*\n/.test(s)) return false;
|
|
331
336
|
return (s.match(PROSE_WORD) ?? []).length < PROSE_WORD_LIMIT;
|
|
332
337
|
}
|
|
333
338
|
function codeRanges(text) {
|
|
@@ -341,6 +346,50 @@ function codeRanges(text) {
|
|
|
341
346
|
}
|
|
342
347
|
return ranges.sort((a, b) => a[0] - b[0]);
|
|
343
348
|
}
|
|
349
|
+
function pendingDisplayMathOpener(text) {
|
|
350
|
+
if (!text.includes("$$")) return -1;
|
|
351
|
+
const ranges = codeRanges(text);
|
|
352
|
+
const tokens = [];
|
|
353
|
+
let r = 0;
|
|
354
|
+
let maxEnd = -1;
|
|
355
|
+
for (let i = text.indexOf("$$"); i !== -1 && i < text.length - 1; i = text.indexOf("$$", i)) {
|
|
356
|
+
while (r < ranges.length && ranges[r][0] <= i) {
|
|
357
|
+
maxEnd = Math.max(maxEnd, ranges[r][1]);
|
|
358
|
+
r++;
|
|
359
|
+
}
|
|
360
|
+
if (maxEnd <= i) tokens.push(i);
|
|
361
|
+
i += 2;
|
|
362
|
+
}
|
|
363
|
+
const paired = /* @__PURE__ */ new Set();
|
|
364
|
+
let j = 0;
|
|
365
|
+
while (j < tokens.length) {
|
|
366
|
+
const open = tokens[j];
|
|
367
|
+
const close = tokens[j + 1];
|
|
368
|
+
if (close === void 0) break;
|
|
369
|
+
if (looksLikeDisplayMath(text.slice(open + 2, close), opensFlowBlock(text, open))) {
|
|
370
|
+
paired.add(open);
|
|
371
|
+
paired.add(close);
|
|
372
|
+
j += 2;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
j += 1;
|
|
376
|
+
}
|
|
377
|
+
let trail = 0;
|
|
378
|
+
while (trail < text.length && /\s/.test(text[text.length - 1 - trail])) trail++;
|
|
379
|
+
for (const token of tokens) {
|
|
380
|
+
if (paired.has(token)) continue;
|
|
381
|
+
let lead = 0;
|
|
382
|
+
while (lead <= MAX_MATH_SPAN && /\s/.test(text[token + 2 + lead] ?? "x")) lead++;
|
|
383
|
+
if (text.length - (token + 2) - lead - trail > MAX_MATH_SPAN) continue;
|
|
384
|
+
const inner = text.slice(token + 2);
|
|
385
|
+
const s = inner.trim();
|
|
386
|
+
if (STRUCTURAL_MARKDOWN.test(s) || s.length > MAX_MATH_SPAN) continue;
|
|
387
|
+
if (!opensFlowBlock(text, token) && /\n[ \t]*\n/.test(inner)) continue;
|
|
388
|
+
if ((s.match(PROSE_WORD) ?? []).length >= PROSE_WORD_LIMIT * 3) continue;
|
|
389
|
+
return token;
|
|
390
|
+
}
|
|
391
|
+
return -1;
|
|
392
|
+
}
|
|
344
393
|
function pairDisplayMath(text) {
|
|
345
394
|
const pairs = /* @__PURE__ */ new Map();
|
|
346
395
|
if (!text.includes("$$")) return pairs;
|
|
@@ -361,7 +410,7 @@ function pairDisplayMath(text) {
|
|
|
361
410
|
const open = tokens[j];
|
|
362
411
|
const close = tokens[j + 1];
|
|
363
412
|
if (close === void 0) break;
|
|
364
|
-
if (looksLikeDisplayMath(text.slice(open + 2, close))) {
|
|
413
|
+
if (looksLikeDisplayMath(text.slice(open + 2, close), opensFlowBlock(text, open))) {
|
|
365
414
|
pairs.set(open, close);
|
|
366
415
|
j += 2;
|
|
367
416
|
continue;
|
|
@@ -689,11 +738,15 @@ function isSplitterTreeLine(line) {
|
|
|
689
738
|
}
|
|
690
739
|
var MEDIA_REF_PREFIXES = ["[Image URL:", "[Video URL:", "[Audio URL:"];
|
|
691
740
|
var Tokenizer = class {
|
|
692
|
-
constructor(text, streaming = false) {
|
|
741
|
+
constructor(text, streaming = false, meter = void 0) {
|
|
693
742
|
this.text = text;
|
|
694
743
|
this.streaming = streaming;
|
|
744
|
+
this.meter = meter;
|
|
695
745
|
this.n = text.length;
|
|
746
|
+
this.tick(text.length);
|
|
696
747
|
this.mathPairs = pairDisplayMath(text);
|
|
748
|
+
this.provisionalFrom = streaming ? pendingDisplayMathOpener(text) : -1;
|
|
749
|
+
if (this.provisionalFrom === -1) this.provisionalFrom = Number.POSITIVE_INFINITY;
|
|
697
750
|
let start = 0;
|
|
698
751
|
for (let i = 0; i < text.length; i++) {
|
|
699
752
|
if (text.charCodeAt(i) === 10) {
|
|
@@ -704,13 +757,15 @@ var Tokenizer = class {
|
|
|
704
757
|
}
|
|
705
758
|
}
|
|
706
759
|
if (start < text.length || text.length === 0) {
|
|
760
|
+
this.pendingCR = streaming && text.length > start && text.charCodeAt(text.length - 1) === 13;
|
|
707
761
|
this.lineStarts.push(start);
|
|
708
|
-
this.contentEnds.push(text.length);
|
|
762
|
+
this.contentEnds.push(this.pendingCR ? text.length - 1 : text.length);
|
|
709
763
|
this.lineEnds.push(text.length);
|
|
710
764
|
}
|
|
711
765
|
}
|
|
712
766
|
text;
|
|
713
767
|
streaming;
|
|
768
|
+
meter;
|
|
714
769
|
n;
|
|
715
770
|
lineStarts = [];
|
|
716
771
|
contentEnds = [];
|
|
@@ -725,6 +780,23 @@ var Tokenizer = class {
|
|
|
725
780
|
/** `$$` opener → closer for the pairs the core renders as math. */
|
|
726
781
|
mathPairs;
|
|
727
782
|
finder = (needle, from) => this.next(needle, from);
|
|
783
|
+
/** Streaming: where provisional text starts (a pending `$$`), or +∞. */
|
|
784
|
+
provisionalFrom = Number.POSITIVE_INFINITY;
|
|
785
|
+
/** Streaming: the text ends in a lone CR whose LF has not arrived yet. */
|
|
786
|
+
pendingCR = false;
|
|
787
|
+
/**
|
|
788
|
+
* Streaming: an open last line that begins with `{` is undecided — each new
|
|
789
|
+
* byte can balance or unbalance its braces and flip the whole line between
|
|
790
|
+
* prose and a JSON island — so it is provisional until it ends (G5).
|
|
791
|
+
*/
|
|
792
|
+
markOpenJsonTail() {
|
|
793
|
+
const last = this.lineStarts.length - 1;
|
|
794
|
+
if (!this.isOpenTail(last)) return;
|
|
795
|
+
const start = this.lineStarts[last];
|
|
796
|
+
if (this.lineText(last).trimStart().startsWith("{")) {
|
|
797
|
+
this.provisionalFrom = Math.min(this.provisionalFrom, start);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
728
800
|
/**
|
|
729
801
|
* `text.indexOf(needle, from)` in O(log k): the first query for a needle
|
|
730
802
|
* indexes all of its occurrences once, so repeated searches for a closer
|
|
@@ -748,9 +820,21 @@ var Tokenizer = class {
|
|
|
748
820
|
}
|
|
749
821
|
return lo < list.length ? list[lo] : -1;
|
|
750
822
|
}
|
|
823
|
+
/** Charge `n` visited characters to the diagnostic meter (complexity tests). */
|
|
824
|
+
tick(n) {
|
|
825
|
+
if (this.meter) this.meter.work += n;
|
|
826
|
+
}
|
|
827
|
+
/** Streaming only: a paragraph ending at `pe` may still be continued by a line not yet arrived. */
|
|
828
|
+
paragraphMayGrow(pe) {
|
|
829
|
+
if (!this.streaming) return false;
|
|
830
|
+
const rest = this.n - pe;
|
|
831
|
+
if (rest === 0) return true;
|
|
832
|
+
const tail = this.text.slice(pe);
|
|
833
|
+
return tail === "\n" || tail === "\r\n" || tail === "\r";
|
|
834
|
+
}
|
|
751
835
|
/** Streaming only: the final line, still waiting for its terminator. */
|
|
752
836
|
isOpenTail(k) {
|
|
753
|
-
return this.streaming && k === this.lineStarts.length - 1 && this.lineEnds[k] === this.contentEnds[k];
|
|
837
|
+
return this.streaming && k === this.lineStarts.length - 1 && (this.lineEnds[k] === this.contentEnds[k] || this.pendingCR);
|
|
754
838
|
}
|
|
755
839
|
get lineCount() {
|
|
756
840
|
return this.lineStarts.length;
|
|
@@ -775,6 +859,7 @@ var Tokenizer = class {
|
|
|
775
859
|
return this.text.slice(this.lineStarts[li], this.contentEnds[li]);
|
|
776
860
|
}
|
|
777
861
|
run() {
|
|
862
|
+
if (this.streaming) this.markOpenJsonTail();
|
|
778
863
|
let pos = 0;
|
|
779
864
|
while (pos < this.n) {
|
|
780
865
|
const li = this.lineOf(pos);
|
|
@@ -783,6 +868,10 @@ var Tokenizer = class {
|
|
|
783
868
|
pos = this.gap(pos, li);
|
|
784
869
|
continue;
|
|
785
870
|
}
|
|
871
|
+
if (pos >= this.provisionalFrom) {
|
|
872
|
+
this.push({ kind: "prose", start: pos, end: this.n, island: null, inlines: [] });
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
786
875
|
const island = this.detectBlock(pos, li, true);
|
|
787
876
|
if (island) {
|
|
788
877
|
this.push({ kind: "island", start: island.start, end: island.end, island, inlines: [] });
|
|
@@ -986,6 +1075,7 @@ var Tokenizer = class {
|
|
|
986
1075
|
continue;
|
|
987
1076
|
}
|
|
988
1077
|
if (FOOTNOTE_DEF.test(line.trimStart()) || this.detectBlock(this.lineStarts[k], k, false)) break;
|
|
1078
|
+
if (this.isOpenTail(k)) break;
|
|
989
1079
|
last = k;
|
|
990
1080
|
}
|
|
991
1081
|
return this.island("footnote_def", p, this.contentEnds[last], true, { id: open[1] });
|
|
@@ -1147,6 +1237,7 @@ var Tokenizer = class {
|
|
|
1147
1237
|
const li = this.lineOf(tp);
|
|
1148
1238
|
const ce = this.contentEnds[li];
|
|
1149
1239
|
const tag = readXmlTag(this.text, tp, this.finder);
|
|
1240
|
+
this.tick(tag ? tag.raw.length : 1);
|
|
1150
1241
|
let openEnd;
|
|
1151
1242
|
if (tag && !tag.isClosing) {
|
|
1152
1243
|
if (tag.isSelfClosing) {
|
|
@@ -1231,7 +1322,7 @@ var Tokenizer = class {
|
|
|
1231
1322
|
return this.island("html_block", p, close.index + close[0].length, true, { tag: name });
|
|
1232
1323
|
}
|
|
1233
1324
|
const typeSix = HTML_BLOCK_LEVEL_TAGS.has(name);
|
|
1234
|
-
const typeSeven = atParaStart && t.trimEnd() === tag.raw;
|
|
1325
|
+
const typeSeven = atParaStart && t.trimEnd() === tag.raw && !this.isOpenTail(li);
|
|
1235
1326
|
if (!typeSix && !typeSeven) return null;
|
|
1236
1327
|
let end = this.contentEnds[li];
|
|
1237
1328
|
for (let k = li + 1; k < this.lineCount && !this.lineIsBlank(k); k++) {
|
|
@@ -1323,6 +1414,10 @@ var Tokenizer = class {
|
|
|
1323
1414
|
let breakLine = -1;
|
|
1324
1415
|
for (let k = li + 1; k < this.lineCount; k++) {
|
|
1325
1416
|
if (this.lineIsBlank(k)) break;
|
|
1417
|
+
if (this.lineStarts[k] >= this.provisionalFrom) {
|
|
1418
|
+
end = this.n;
|
|
1419
|
+
break;
|
|
1420
|
+
}
|
|
1326
1421
|
if (this.detectBlock(this.lineStarts[k], k, false)) {
|
|
1327
1422
|
breakLine = k;
|
|
1328
1423
|
break;
|
|
@@ -1388,6 +1483,7 @@ var Tokenizer = class {
|
|
|
1388
1483
|
scanInline(ps, pe) {
|
|
1389
1484
|
const text = this.text;
|
|
1390
1485
|
const inlines = [];
|
|
1486
|
+
this.tick(pe - ps);
|
|
1391
1487
|
const hasKind = text.slice(ps, pe).includes("__kind");
|
|
1392
1488
|
let kindBudget = 4 * (pe - ps) + 65536;
|
|
1393
1489
|
const stop = (island, orphan = false) => ({ inlines, breakIsland: island, orphan });
|
|
@@ -1398,6 +1494,7 @@ var Tokenizer = class {
|
|
|
1398
1494
|
let runs = null;
|
|
1399
1495
|
const codeSpanClose = (n, from) => {
|
|
1400
1496
|
if (!runs) {
|
|
1497
|
+
this.tick(pe - ps);
|
|
1401
1498
|
runs = /* @__PURE__ */ new Map();
|
|
1402
1499
|
for (let k = ps; k < pe; ) {
|
|
1403
1500
|
if (text.charCodeAt(k) !== 96) {
|
|
@@ -1424,7 +1521,8 @@ var Tokenizer = class {
|
|
|
1424
1521
|
return at !== void 0 && at + n <= pe ? at : -1;
|
|
1425
1522
|
};
|
|
1426
1523
|
let i = ps;
|
|
1427
|
-
|
|
1524
|
+
const scanEnd = Math.min(pe, this.provisionalFrom);
|
|
1525
|
+
while (i < scanEnd) {
|
|
1428
1526
|
const ch = text[i];
|
|
1429
1527
|
if (ch === "\\") {
|
|
1430
1528
|
const nextCh = text[i + 1];
|
|
@@ -1442,6 +1540,9 @@ var Tokenizer = class {
|
|
|
1442
1540
|
if (ch === "`") {
|
|
1443
1541
|
const n = backtickRunLength(text, i);
|
|
1444
1542
|
const close = codeSpanClose(n, i + n);
|
|
1543
|
+
if (close === -1 && this.streaming && this.paragraphMayGrow(pe)) {
|
|
1544
|
+
return { inlines, breakIsland: null, orphan: false };
|
|
1545
|
+
}
|
|
1445
1546
|
i = close === -1 ? i + n : close + n;
|
|
1446
1547
|
continue;
|
|
1447
1548
|
}
|
|
@@ -1458,6 +1559,7 @@ var Tokenizer = class {
|
|
|
1458
1559
|
continue;
|
|
1459
1560
|
}
|
|
1460
1561
|
const end = singleDollarMathEnd(text, i, pe);
|
|
1562
|
+
this.tick(end > 0 ? end - i : Math.min(403, pe - i));
|
|
1461
1563
|
if (end > 0 && !(this.streaming && end === this.n)) {
|
|
1462
1564
|
inlines.push(this.island("math_inline", i, end, true, { delimiter: "$" }));
|
|
1463
1565
|
i = end;
|
|
@@ -1485,6 +1587,7 @@ var Tokenizer = class {
|
|
|
1485
1587
|
const limit = Math.min(pe, i + 65536);
|
|
1486
1588
|
const end = matchingJsonObjectEnd(text, i, limit);
|
|
1487
1589
|
kindBudget -= (end ?? limit) - i;
|
|
1590
|
+
this.tick((end ?? limit) - i);
|
|
1488
1591
|
if (end !== null) {
|
|
1489
1592
|
const kind = declaredKind(text.slice(i, end));
|
|
1490
1593
|
if (kind) {
|
|
@@ -1546,6 +1649,7 @@ var Tokenizer = class {
|
|
|
1546
1649
|
continue;
|
|
1547
1650
|
}
|
|
1548
1651
|
const tag = readXmlTag(text, i, this.finder);
|
|
1652
|
+
this.tick(tag ? tag.raw.length : 1);
|
|
1549
1653
|
if (tag && i + tag.raw.length <= pe) {
|
|
1550
1654
|
const name = tag.tagName;
|
|
1551
1655
|
const tagEnd = i + tag.raw.length;
|
|
@@ -1594,7 +1698,7 @@ var Tokenizer = class {
|
|
|
1594
1698
|
}
|
|
1595
1699
|
};
|
|
1596
1700
|
function tokenizeSource(text, options = {}) {
|
|
1597
|
-
const raw = new Tokenizer(text, options.streaming ?? false).run();
|
|
1701
|
+
const raw = new Tokenizer(text, options.streaming ?? false, options.meter).run();
|
|
1598
1702
|
const cp = buildCodePointIndex(text);
|
|
1599
1703
|
const inline = (island) => ({
|
|
1600
1704
|
islandType: island.type,
|
|
@@ -1947,6 +2051,6 @@ function mapRange(changes, start, end, unit = "utf16") {
|
|
|
1947
2051
|
return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
|
|
1948
2052
|
}
|
|
1949
2053
|
|
|
1950
|
-
export { CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
2054
|
+
export { CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
1951
2055
|
//# sourceMappingURL=source.js.map
|
|
1952
2056
|
//# sourceMappingURL=source.js.map
|