@ai-matrx/content-ir 0.16.2 → 0.18.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 +95 -1
- package/README.md +24 -0
- package/dist/index.cjs +431 -267
- 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 +430 -268
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +431 -267
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +56 -14
- package/dist/source.d.ts +56 -14
- package/dist/source.js +430 -268
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
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
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
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
|
|
@@ -420,6 +447,20 @@ declare function parseFenceOpener(line: string): {
|
|
|
420
447
|
} | null;
|
|
421
448
|
declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nests: boolean, nestedDepth: number): InnerFenceLine;
|
|
422
449
|
|
|
450
|
+
interface CodeRange {
|
|
451
|
+
/** UTF-16 offset of the first character (the fence line start, or the opening backtick run). */
|
|
452
|
+
start: number;
|
|
453
|
+
/** Offset just past the closing fence line's content / closing backtick run (the fence's last line when unclosed). */
|
|
454
|
+
end: number;
|
|
455
|
+
kind: "fence" | "span";
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Every code range in the text — fences (by the renderer's rule above) and
|
|
459
|
+
* inline code spans — sorted by start. Linear: one pass over lines, one over
|
|
460
|
+
* each paragraph's backtick runs.
|
|
461
|
+
*/
|
|
462
|
+
declare function findCodeRanges(text: string): CodeRange[];
|
|
463
|
+
|
|
423
464
|
/**
|
|
424
465
|
* `$$...$$`, `$$…$$`, `$$ · $$`: a PLACEHOLDER — prose describing the syntax,
|
|
425
466
|
* never a formula. The pair is consumed whole as literal text (neither `$$`
|
|
@@ -433,7 +474,7 @@ declare function isMathPlaceholder(inner: string): boolean;
|
|
|
433
474
|
* pairing with the next paragraph's formula.
|
|
434
475
|
*/
|
|
435
476
|
declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
|
|
436
|
-
|
|
477
|
+
|
|
437
478
|
/**
|
|
438
479
|
* STREAMING: the last `$$` token that is still unpaired AND could still pair
|
|
439
480
|
* with a `$$` not yet arrived — its span so far is short enough, carries no
|
|
@@ -442,6 +483,7 @@ declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
|
|
|
442
483
|
* streaming tokenizer treats it as provisional. -1 when there is none.
|
|
443
484
|
*/
|
|
444
485
|
declare function pendingDisplayMathOpener(text: string): number;
|
|
486
|
+
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
445
487
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
446
488
|
|
|
447
|
-
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, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
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 };
|
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
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
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
|
|
@@ -420,6 +447,20 @@ declare function parseFenceOpener(line: string): {
|
|
|
420
447
|
} | null;
|
|
421
448
|
declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nests: boolean, nestedDepth: number): InnerFenceLine;
|
|
422
449
|
|
|
450
|
+
interface CodeRange {
|
|
451
|
+
/** UTF-16 offset of the first character (the fence line start, or the opening backtick run). */
|
|
452
|
+
start: number;
|
|
453
|
+
/** Offset just past the closing fence line's content / closing backtick run (the fence's last line when unclosed). */
|
|
454
|
+
end: number;
|
|
455
|
+
kind: "fence" | "span";
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Every code range in the text — fences (by the renderer's rule above) and
|
|
459
|
+
* inline code spans — sorted by start. Linear: one pass over lines, one over
|
|
460
|
+
* each paragraph's backtick runs.
|
|
461
|
+
*/
|
|
462
|
+
declare function findCodeRanges(text: string): CodeRange[];
|
|
463
|
+
|
|
423
464
|
/**
|
|
424
465
|
* `$$...$$`, `$$…$$`, `$$ · $$`: a PLACEHOLDER — prose describing the syntax,
|
|
425
466
|
* never a formula. The pair is consumed whole as literal text (neither `$$`
|
|
@@ -433,7 +474,7 @@ declare function isMathPlaceholder(inner: string): boolean;
|
|
|
433
474
|
* pairing with the next paragraph's formula.
|
|
434
475
|
*/
|
|
435
476
|
declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
|
|
436
|
-
|
|
477
|
+
|
|
437
478
|
/**
|
|
438
479
|
* STREAMING: the last `$$` token that is still unpaired AND could still pair
|
|
439
480
|
* with a `$$` not yet arrived — its span so far is short enough, carries no
|
|
@@ -442,6 +483,7 @@ declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
|
|
|
442
483
|
* streaming tokenizer treats it as provisional. -1 when there is none.
|
|
443
484
|
*/
|
|
444
485
|
declare function pendingDisplayMathOpener(text: string): number;
|
|
486
|
+
/** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
|
|
445
487
|
declare function pairDisplayMath(text: string): Map<number, number>;
|
|
446
488
|
|
|
447
|
-
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, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
|
|
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 };
|