@ai-matrx/content-ir 0.20.1 → 0.21.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/CHANGELOG.md +32 -0
- package/dist/index.cjs +487 -35
- 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 +464 -36
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +487 -35
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +157 -1
- package/dist/source.d.ts +157 -1
- package/dist/source.js +464 -36
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -7,5 +7,5 @@ export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateR
|
|
|
7
7
|
export { ArrayItemKindBinding, BlockSchemaDraft, CONTROL_KEYS, CONTROL_KEY_FIELDS, ControlKey, ControlKeysMode, ConversionProblem, DroppedMetadata, FieldComparison, ItemKindRefCheck, JsonSchemaNode, KindJsonSchemaExport, KindJsonSchemaOptions, KindSchemaFromJsonOptions, KindSchemaFromJsonResult, RECORD_DISPOSITION, SavePlanEntry, SavePlanValidation, SchemaConversionResult, WithControlKeysOptions, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, controlKeysApplyTo, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, stripControlKeys, validateBlockSchemaSavePlan, withControlKeyFields, withControlKeys } from './convert.cjs';
|
|
8
8
|
export { AnyPartialKindEvent, IR_PARTIAL_KEY, KindVerdict, NODE_OUTCOME_KIND, NodeOutcomeWrapper, PartialKindEvent, PartialKindNode, PartialKindState, RUN_RESULT_KIND, RetractedKindEvent, RunResultWrapper, SupersededKindEvent, advancePartialKind, emitPayloadFence, emitPayloadJson, isProvisionalKind, isTerminalKindEvent, kindVerdictOf, makePartialKindStalenessGate, readNodeOutcomeValue, readOutputRef, readPartialKindEvent, readRunResultValue, rehydrateNodeOutcome, rehydrateRunResult, sanitizeInboundPartialKindMetadata, withRootKind } from './wire.cjs';
|
|
9
9
|
export { ACTION_BY_CLASS, CAPABILITY_BY_CLASS, CLASSES, DIRECTIVE_VERSION, DecodedDirective, DirectiveCapability, DirectiveClass, DirectiveDecodeError, DirectiveDisplay, DirectiveItemKindLookup, DirectiveItemsEdge, DirectiveNounCatalog, DirectiveNounEntry, DirectiveSlug, IN_CONTENT_CLASSES, ItemFact, KindDirectiveShell, RESERVED_PREFIX, SIDE_EFFECT_CLASSES, SLUG_PREFIX, asKindInstance, buildDirectiveSlug, buildKindDirective, capabilityOf, decodeDirective, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, executesAtOutputRoot, isDirectiveClass, isKindDirective, isLegacyShell, isReservedDirectiveSlug, itemFacts, itemSubtitle, itemTitle, legacyShellUses, looksLikeDirectiveHead, nounFamily, nounLabel, nounTitleColumn, parseDirectiveSlug, resetLegacyShellUses, resolvesInContent, titleCaseToken, tryDecodeDirective, tryDecodeDirectiveContent } from './directives.cjs';
|
|
10
|
-
export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceOpener, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes } from './source.cjs';
|
|
10
|
+
export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DIRECTIVE_CONTAINER_OPEN, DirectiveContainerTracker, DisturbedIsland, FENCE_META_KEY, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceInfo, FenceLineKind, FenceLines, FenceMeta, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TITLED_IMAGE_LINE, TokenizeOptions, XmlBalanceOptions, XmlBalanceState, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, cleanMarkdown, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findBalancedXmlClose, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, findWholeTableStart, hasUnclosedBacktickRun, indexOutsideInlineCode, initialXmlBalance, isEscapedBracketMath, isGfmDelimiterRow, isGrowingDelimiterRow, isHtmlBlockTagName, isInsideInlineCode, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, markdownToPlainText, mathToReadable, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceMeta, parseFenceOpener, parseLineRanges, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, removeCodeSpans, replaceFences, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, soleFence, spliceSave, splitFenceInfo, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsLikeTableRow, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trailingTableStart, trimFenceLine, unescapeCellPipes, unwrapCodeSpans, unwrapKindEnvelopes } from './source.cjs';
|
|
11
11
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateR
|
|
|
7
7
|
export { ArrayItemKindBinding, BlockSchemaDraft, CONTROL_KEYS, CONTROL_KEY_FIELDS, ControlKey, ControlKeysMode, ConversionProblem, DroppedMetadata, FieldComparison, ItemKindRefCheck, JsonSchemaNode, KindJsonSchemaExport, KindJsonSchemaOptions, KindSchemaFromJsonOptions, KindSchemaFromJsonResult, RECORD_DISPOSITION, SavePlanEntry, SavePlanValidation, SchemaConversionResult, WithControlKeysOptions, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, controlKeysApplyTo, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, stripControlKeys, validateBlockSchemaSavePlan, withControlKeyFields, withControlKeys } from './convert.js';
|
|
8
8
|
export { AnyPartialKindEvent, IR_PARTIAL_KEY, KindVerdict, NODE_OUTCOME_KIND, NodeOutcomeWrapper, PartialKindEvent, PartialKindNode, PartialKindState, RUN_RESULT_KIND, RetractedKindEvent, RunResultWrapper, SupersededKindEvent, advancePartialKind, emitPayloadFence, emitPayloadJson, isProvisionalKind, isTerminalKindEvent, kindVerdictOf, makePartialKindStalenessGate, readNodeOutcomeValue, readOutputRef, readPartialKindEvent, readRunResultValue, rehydrateNodeOutcome, rehydrateRunResult, sanitizeInboundPartialKindMetadata, withRootKind } from './wire.js';
|
|
9
9
|
export { ACTION_BY_CLASS, CAPABILITY_BY_CLASS, CLASSES, DIRECTIVE_VERSION, DecodedDirective, DirectiveCapability, DirectiveClass, DirectiveDecodeError, DirectiveDisplay, DirectiveItemKindLookup, DirectiveItemsEdge, DirectiveNounCatalog, DirectiveNounEntry, DirectiveSlug, IN_CONTENT_CLASSES, ItemFact, KindDirectiveShell, RESERVED_PREFIX, SIDE_EFFECT_CLASSES, SLUG_PREFIX, asKindInstance, buildDirectiveSlug, buildKindDirective, capabilityOf, decodeDirective, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, executesAtOutputRoot, isDirectiveClass, isKindDirective, isLegacyShell, isReservedDirectiveSlug, itemFacts, itemSubtitle, itemTitle, legacyShellUses, looksLikeDirectiveHead, nounFamily, nounLabel, nounTitleColumn, parseDirectiveSlug, resetLegacyShellUses, resolvesInContent, titleCaseToken, tryDecodeDirective, tryDecodeDirectiveContent } from './directives.js';
|
|
10
|
-
export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceOpener, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes } from './source.js';
|
|
10
|
+
export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DIRECTIVE_CONTAINER_OPEN, DirectiveContainerTracker, DisturbedIsland, FENCE_META_KEY, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceInfo, FenceLineKind, FenceLines, FenceMeta, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TITLED_IMAGE_LINE, TokenizeOptions, XmlBalanceOptions, XmlBalanceState, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, cleanMarkdown, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findBalancedXmlClose, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, findWholeTableStart, hasUnclosedBacktickRun, indexOutsideInlineCode, initialXmlBalance, isEscapedBracketMath, isGfmDelimiterRow, isGrowingDelimiterRow, isHtmlBlockTagName, isInsideInlineCode, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, markdownToPlainText, mathToReadable, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceMeta, parseFenceOpener, parseLineRanges, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, removeCodeSpans, replaceFences, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, soleFence, spliceSave, splitFenceInfo, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsLikeTableRow, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trailingTableStart, trimFenceLine, unescapeCellPipes, unwrapCodeSpans, unwrapKindEnvelopes } from './source.js';
|
|
11
11
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -6412,6 +6412,8 @@ function findTableEnd(lines, start) {
|
|
|
6412
6412
|
}
|
|
6413
6413
|
|
|
6414
6414
|
// source/tokenize.ts
|
|
6415
|
+
var QUOTE_PREFIX = /^ {0,3}>(?: ?>)* ?/;
|
|
6416
|
+
var QUOTED_JSON_FENCE_LANGS = /* @__PURE__ */ new Set(["", "json", "jsonc", "json5"]);
|
|
6415
6417
|
var NOT_WHITESPACE = /\S/;
|
|
6416
6418
|
var DIRECTIVE_OPEN = /^(:{2,})([A-Za-z][\w-]*)/;
|
|
6417
6419
|
var MKDOCS_OPEN = /^(!!!|\?\?\?\+?)[ \t]+([A-Za-z][\w-]*)/;
|
|
@@ -6901,6 +6903,8 @@ var Tokenizer = class {
|
|
|
6901
6903
|
if (indent <= 3 && !listNested && t.startsWith(">")) {
|
|
6902
6904
|
const callout = this.callout(p, li, t);
|
|
6903
6905
|
if (callout) return callout;
|
|
6906
|
+
const lifted = this.quotedJsonFence(p, li, seg);
|
|
6907
|
+
if (lifted) return lifted;
|
|
6904
6908
|
}
|
|
6905
6909
|
if (atParaStart && indent <= 3 && t.startsWith("[^")) {
|
|
6906
6910
|
const footnote = this.footnoteDefinition(p, li, t);
|
|
@@ -7096,6 +7100,42 @@ var Tokenizer = class {
|
|
|
7096
7100
|
streaming: this.streaming
|
|
7097
7101
|
};
|
|
7098
7102
|
}
|
|
7103
|
+
/**
|
|
7104
|
+
* A JSON-family fence (unlabelled, json, jsonc, json5) opening on a quoted line. The renderer LIFTS it out
|
|
7105
|
+
* of the quote (matrx-frontend V1, never-raw law): the quote prefix is removed from every line of the
|
|
7106
|
+
* region, so the region is an ordinary top-level fence — drawn as code up to its own closer, which may sit on
|
|
7107
|
+
* a line that carries no `>` at all. The editor must lock at least what the renderer draws, so the island
|
|
7108
|
+
* runs from the quoted opener line to that closer (found on the lines with their quote prefix removed).
|
|
7109
|
+
*/
|
|
7110
|
+
quotedJsonFence(p, li, seg) {
|
|
7111
|
+
const m = QUOTE_PREFIX.exec(seg);
|
|
7112
|
+
if (!m) return null;
|
|
7113
|
+
const opener = fenceOpenerOf(seg.slice(m[0].length));
|
|
7114
|
+
if (!opener || opener.char !== "`" || !QUOTED_JSON_FENCE_LANGS.has(opener.lang.toLowerCase())) return null;
|
|
7115
|
+
const base2 = this.fenceLines;
|
|
7116
|
+
const lines = {
|
|
7117
|
+
...base2,
|
|
7118
|
+
line: (k) => {
|
|
7119
|
+
const text = base2.line(k);
|
|
7120
|
+
if (text === null) return null;
|
|
7121
|
+
const q = QUOTE_PREFIX.exec(text);
|
|
7122
|
+
return q ? text.slice(q[0].length) : text;
|
|
7123
|
+
}
|
|
7124
|
+
};
|
|
7125
|
+
let first = li;
|
|
7126
|
+
while (first > 0 && li - first < 400 && QUOTE_PREFIX.test(this.lineText(first - 1))) first--;
|
|
7127
|
+
for (let k = first; k < li; k++) {
|
|
7128
|
+
const o = fenceOpenerOf(lines.line(k) ?? "");
|
|
7129
|
+
if (!o || o.char !== "`" || QUOTED_JSON_FENCE_LANGS.has(o.lang.toLowerCase())) continue;
|
|
7130
|
+
const c = closeFence(lines, k, o);
|
|
7131
|
+
if (!c.closed || c.line >= li) return null;
|
|
7132
|
+
k = c.line;
|
|
7133
|
+
}
|
|
7134
|
+
const end = closeFence(lines, li, opener);
|
|
7135
|
+
const meta = { fence: "`", ticks: opener.ticks, lang: opener.lang };
|
|
7136
|
+
if (end.closed) return this.island("fence", p, this.contentEnds[end.line], true, meta);
|
|
7137
|
+
return this.island("fence", p, this.n, false, meta);
|
|
7138
|
+
}
|
|
7099
7139
|
/**
|
|
7100
7140
|
* Backtick fence — THE one closer (`closeFence`, source/code-ranges.ts): the
|
|
7101
7141
|
* nested-fence rule for markdown fences with the strict-CommonMark retry, the
|
|
@@ -7128,44 +7168,14 @@ var Tokenizer = class {
|
|
|
7128
7168
|
if (normalized && SPECIAL_CODE_LANGUAGES.has(normalized)) meta.special = normalized;
|
|
7129
7169
|
const close = closeFence(this.fenceLines, li, opener);
|
|
7130
7170
|
if (close.closed) {
|
|
7131
|
-
|
|
7132
|
-
const end = this.rendererOverflow(li + 1, close.line, tildeEnd);
|
|
7133
|
-
return this.island("fence", p, end, end === this.n ? this.overflowComplete : true, meta);
|
|
7171
|
+
return this.island("fence", p, this.contentEnds[close.line], true, meta);
|
|
7134
7172
|
}
|
|
7135
7173
|
return this.island("fence", p, this.n, false, meta);
|
|
7136
7174
|
}
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
* one as ordinary lines, so a ```` ``` ```` fence (or an XML section, a JSON
|
|
7142
|
-
* block…) that STARTS inside the tilde fence can run past its closer. The
|
|
7143
|
-
* editor must lock at least what the renderer draws (verify-RC-B3 residual
|
|
7144
|
-
* R5), so a tilde island extends over every block the renderer would detect
|
|
7145
|
-
* starting inside it. Returns the island's end.
|
|
7146
|
-
*/
|
|
7147
|
-
rendererOverflow(firstLine, closeLine, tildeEnd) {
|
|
7148
|
-
let end = tildeEnd;
|
|
7149
|
-
this.overflowComplete = true;
|
|
7150
|
-
for (let j = firstLine; j <= closeLine && j < this.lineCount; j++) {
|
|
7151
|
-
const start = this.lineStarts[j];
|
|
7152
|
-
if (this.lineIsBlank(j)) continue;
|
|
7153
|
-
if (fenceOpenerOf(this.lineText(j))?.char === "~") continue;
|
|
7154
|
-
const inner = this.detectBlockUncached(start, j, false);
|
|
7155
|
-
if (!inner) continue;
|
|
7156
|
-
if (this.streaming && inner.end >= tildeEnd && this.paragraphMayGrow(inner.end)) {
|
|
7157
|
-
this.overflowComplete = false;
|
|
7158
|
-
return this.n;
|
|
7159
|
-
}
|
|
7160
|
-
if (inner.end > end) {
|
|
7161
|
-
end = inner.end;
|
|
7162
|
-
this.overflowComplete = inner.complete;
|
|
7163
|
-
}
|
|
7164
|
-
const lastLine = this.lineOf(Math.max(start, inner.end - 1));
|
|
7165
|
-
if (lastLine > j) j = lastLine;
|
|
7166
|
-
}
|
|
7167
|
-
return end;
|
|
7168
|
-
}
|
|
7175
|
+
// A tilde island ends at its closer. The renderer's splitter treats `~~~` as a real fence since
|
|
7176
|
+
// matrx-frontend A4 (2026-09-30): the lines inside are code, so nothing that starts inside one runs
|
|
7177
|
+
// past the closer (the 0.14.2 "overflow" assumed the renderer did not know ~~~ and, kept, swallowed the
|
|
7178
|
+
// next fence's opener into the tilde island: a ````md block after a ~~~ block was left unlocked).
|
|
7169
7179
|
/**
|
|
7170
7180
|
* A line-leading `$$` that OPENS a math pair (source/math-pairs.ts — the
|
|
7171
7181
|
* core's rule). A closer, an unpaired `$$`, or a prose pair is never a block:
|
|
@@ -8081,6 +8091,424 @@ function resolveReferenceLinks(fragment, defs) {
|
|
|
8081
8091
|
return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
|
|
8082
8092
|
}
|
|
8083
8093
|
|
|
8084
|
-
|
|
8094
|
+
// source/code-range-edits.ts
|
|
8095
|
+
function unwrapCodeSpans(text) {
|
|
8096
|
+
if (!text.includes("`")) return text;
|
|
8097
|
+
return mapCodeRanges(text, (range, raw) => range.kind === "span" ? codeSpanText(raw) : raw);
|
|
8098
|
+
}
|
|
8099
|
+
function removeCodeSpans(text) {
|
|
8100
|
+
if (!text.includes("`")) return text;
|
|
8101
|
+
return mapCodeRanges(text, (range, raw) => range.kind === "span" ? "" : raw);
|
|
8102
|
+
}
|
|
8103
|
+
function replaceFences(text, fn) {
|
|
8104
|
+
if (!text.includes("```") && !text.includes("~~~")) return text;
|
|
8105
|
+
return mapCodeRanges(text, (range, raw) => {
|
|
8106
|
+
if (range.kind !== "fence") return raw;
|
|
8107
|
+
const parts = fenceParts(raw);
|
|
8108
|
+
return fn({ lang: parts?.opener.lang ?? "", body: parts?.body ?? raw, closed: parts?.closed ?? false, raw });
|
|
8109
|
+
});
|
|
8110
|
+
}
|
|
8111
|
+
function soleFence(text, options = {}) {
|
|
8112
|
+
const trimmed = text.trim();
|
|
8113
|
+
if (!trimmed.startsWith("`") && !trimmed.startsWith("~")) return null;
|
|
8114
|
+
const ranges = findCodeRanges(trimmed);
|
|
8115
|
+
const only = ranges.length === 1 ? ranges[0] : void 0;
|
|
8116
|
+
if (!only || only.kind !== "fence" || only.start !== 0 || only.end !== trimmed.length) return null;
|
|
8117
|
+
const parts = fenceParts(trimmed);
|
|
8118
|
+
if (!parts || !parts.closed && !options.allowUnclosed) return null;
|
|
8119
|
+
return { lang: parts.opener.lang, body: parts.body, closed: parts.closed };
|
|
8120
|
+
}
|
|
8121
|
+
|
|
8122
|
+
// source/plain-text.ts
|
|
8123
|
+
var INLINE_PATTERNS = [
|
|
8124
|
+
// [label](href) → label. Runs first so emphasis inside a label still unwraps.
|
|
8125
|
+
[/\[([^\]]+)\]\([^)]*\)/g, "$1"],
|
|
8126
|
+
[/\*\*\*(?=\S)([\s\S]*?\S)\*\*\*/g, "$1"],
|
|
8127
|
+
[/___(?=\S)([\s\S]*?\S)___/g, "$1"],
|
|
8128
|
+
[/\*\*(?=\S)([\s\S]*?\S)\*\*/g, "$1"],
|
|
8129
|
+
[/__(?=\S)([\s\S]*?\S)__/g, "$1"],
|
|
8130
|
+
[/~~(?=\S)([\s\S]*?\S)~~/g, "$1"],
|
|
8131
|
+
[/\*(?=\S)([^*\n]*?\S)\*/g, "$1"],
|
|
8132
|
+
// Underscore italics only between word boundaries: snake_case_names are not
|
|
8133
|
+
// emphasis, and mangling an identifier is a worse defect than a stray marker.
|
|
8134
|
+
[/(^|[\s(])_(?=\S)([^_\n]*?\S)_(?=[\s).,;:!?]|$)/g, "$1$2"]
|
|
8135
|
+
];
|
|
8136
|
+
var MATH_STRUCTURAL = [
|
|
8137
|
+
[/\\(?:d|t)?frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g, "$1/$2"],
|
|
8138
|
+
[/\\sqrt\s*\{([^{}]*)\}/g, "\u221A($1)"]
|
|
8139
|
+
];
|
|
8140
|
+
var MATH_PATTERNS = [
|
|
8141
|
+
// Environments (\begin{aligned} … \end{aligned}) carry no meaning in a
|
|
8142
|
+
// one-line preview; drop the wrapper, keep the contents. Without this the
|
|
8143
|
+
// catch-all below turned them into the word "aligned" twice.
|
|
8144
|
+
[/\\(?:begin|end)\s*\{[^{}]*\}/g, " "],
|
|
8145
|
+
// A TeX line break inside a preview is just a space.
|
|
8146
|
+
[/\\\\/g, " "],
|
|
8147
|
+
// TeX spacing commands (\, \; \: thin/medium space, \! negative space).
|
|
8148
|
+
[/\\[,;:]/g, " "],
|
|
8149
|
+
[/\\!/g, ""],
|
|
8150
|
+
// \left\{ … \right\} — the escaped-brace forms, which the character-class
|
|
8151
|
+
// rule below cannot reach because the brace is preceded by a backslash.
|
|
8152
|
+
[/\\(?:left|right)\s*\\?([([\]|){}])/g, "$1"],
|
|
8153
|
+
// NOTE: every command below ends with (?![a-zA-Z]) and NOT \b. `_` is a WORD
|
|
8154
|
+
// character, so \b fails after `\sum_` — which silently left every
|
|
8155
|
+
// summation, integral and limit card reading as "sum_" / "int_".
|
|
8156
|
+
[/\\times(?![a-zA-Z])/g, "\xD7"],
|
|
8157
|
+
[/\\div(?![a-zA-Z])/g, "\xF7"],
|
|
8158
|
+
[/\\pm(?![a-zA-Z])/g, "\xB1"],
|
|
8159
|
+
[/\\cdot(?![a-zA-Z])/g, "\xB7"],
|
|
8160
|
+
[/\\leq(?![a-zA-Z])/g, "\u2264"],
|
|
8161
|
+
[/\\geq(?![a-zA-Z])/g, "\u2265"],
|
|
8162
|
+
[/\\neq(?![a-zA-Z])/g, "\u2260"],
|
|
8163
|
+
[/\\approx(?![a-zA-Z])/g, "\u2248"],
|
|
8164
|
+
[/\\infty(?![a-zA-Z])/g, "\u221E"],
|
|
8165
|
+
[/\\pi(?![a-zA-Z])/g, "\u03C0"],
|
|
8166
|
+
[/\\theta(?![a-zA-Z])/g, "\u03B8"],
|
|
8167
|
+
[/\\alpha(?![a-zA-Z])/g, "\u03B1"],
|
|
8168
|
+
[/\\beta(?![a-zA-Z])/g, "\u03B2"],
|
|
8169
|
+
[/\\Delta(?![a-zA-Z])/g, "\u0394"],
|
|
8170
|
+
[/\\delta(?![a-zA-Z])/g, "\u03B4"],
|
|
8171
|
+
[/\\sum(?![a-zA-Z])/g, "\u03A3"],
|
|
8172
|
+
[/\\prod(?![a-zA-Z])/g, "\u220F"],
|
|
8173
|
+
[/\\int(?![a-zA-Z])/g, "\u222B"],
|
|
8174
|
+
[/\\lim(?![a-zA-Z])/g, "lim"],
|
|
8175
|
+
[/\\(?:rightarrow|to)(?![a-zA-Z])/g, "\u2192"],
|
|
8176
|
+
// Braces that only ever grouped a script or argument: ^{2} → ^2, _{i} → _i.
|
|
8177
|
+
[/([_^])\s*\{([^{}]*)\}/g, "$1$2"],
|
|
8178
|
+
// Any remaining single-argument command: \text{x} / \mathrm{x} → x.
|
|
8179
|
+
[/\\[a-zA-Z]+\s*\{([^{}]*)\}/g, "$1"],
|
|
8180
|
+
// Bare commands we did not translate: drop the backslash, keep the word.
|
|
8181
|
+
[/\\([a-zA-Z]+)/g, "$1"]
|
|
8182
|
+
];
|
|
8183
|
+
var MATH_REGIONS = [
|
|
8184
|
+
/\\\[([\s\S]*?)\\\]/g,
|
|
8185
|
+
/\\\(([\s\S]*?)\\\)/g,
|
|
8186
|
+
/\$\$([\s\S]*?)\$\$/g
|
|
8187
|
+
];
|
|
8188
|
+
function mathToReadable(expression) {
|
|
8189
|
+
let text = expression;
|
|
8190
|
+
for (let pass = 0; pass < 8; pass += 1) {
|
|
8191
|
+
const before = text;
|
|
8192
|
+
for (const [pattern, replacement] of MATH_STRUCTURAL) {
|
|
8193
|
+
text = text.replace(pattern, replacement);
|
|
8194
|
+
}
|
|
8195
|
+
if (text === before) break;
|
|
8196
|
+
}
|
|
8197
|
+
for (const [pattern, replacement] of MATH_PATTERNS) {
|
|
8198
|
+
text = text.replace(pattern, replacement);
|
|
8199
|
+
}
|
|
8200
|
+
return text.trim();
|
|
8201
|
+
}
|
|
8202
|
+
function markdownToPlainText(value) {
|
|
8203
|
+
if (!value) return "";
|
|
8204
|
+
const mathChunks = [];
|
|
8205
|
+
let text = value;
|
|
8206
|
+
for (const region of MATH_REGIONS) {
|
|
8207
|
+
text = text.replace(region, (_match, inner) => {
|
|
8208
|
+
mathChunks.push(mathToReadable(inner));
|
|
8209
|
+
return `\uE000MATH${mathChunks.length - 1}\uE001`;
|
|
8210
|
+
});
|
|
8211
|
+
}
|
|
8212
|
+
for (const [pattern, replacement] of INLINE_PATTERNS) {
|
|
8213
|
+
text = text.replace(pattern, replacement);
|
|
8214
|
+
}
|
|
8215
|
+
text = unwrapCodeSpans(text);
|
|
8216
|
+
text = text.replace(
|
|
8217
|
+
/\uE000MATH(\d+)\uE001/g,
|
|
8218
|
+
(_m, index) => mathChunks[Number(index)] ?? ""
|
|
8219
|
+
);
|
|
8220
|
+
return text.replace(/[ \t]{2,}/g, " ").trim();
|
|
8221
|
+
}
|
|
8222
|
+
function unwrapKindEnvelopes(value) {
|
|
8223
|
+
if (!value) return "";
|
|
8224
|
+
if (!value.includes("<artifact")) return value;
|
|
8225
|
+
return tokenizeSource(value).map((block) => {
|
|
8226
|
+
if (block.kind !== "island" || block.islandType !== "xml_attr" && block.islandType !== "xml_container") {
|
|
8227
|
+
return block.raw;
|
|
8228
|
+
}
|
|
8229
|
+
const match = /^\s*<artifact\b[^>]*>([\s\S]*?)<\/artifact>\s*$/.exec(block.raw);
|
|
8230
|
+
return match ? (match[1] ?? "").replace(/^\n/, "").replace(/\n$/, "") : block.raw;
|
|
8231
|
+
}).join("");
|
|
8232
|
+
}
|
|
8233
|
+
|
|
8234
|
+
// source/clean-markdown.ts
|
|
8235
|
+
var cleanMarkdown = (text) => {
|
|
8236
|
+
if (!text || typeof text !== "string") return "";
|
|
8237
|
+
let cleanedText = text;
|
|
8238
|
+
const lines = cleanedText.split("\n");
|
|
8239
|
+
const processedLines = [];
|
|
8240
|
+
for (let line of lines) {
|
|
8241
|
+
let processedLine = line;
|
|
8242
|
+
if (processedLine.trim() === "") {
|
|
8243
|
+
processedLines.push(processedLine);
|
|
8244
|
+
continue;
|
|
8245
|
+
}
|
|
8246
|
+
processedLine = processedLine.replace(/^#{1,6}\s+(.+)$/, "$1");
|
|
8247
|
+
processedLine = processedLine.replace(/(\*\*|__)(.*?)\1/, "$2");
|
|
8248
|
+
processedLine = processedLine.replace(/(\*|_)(.*?)\1/, "$2");
|
|
8249
|
+
processedLine = unwrapCodeSpans(processedLine);
|
|
8250
|
+
processedLine = processedLine.replace(/\[([^\]]+)\]\(([^)]+)\)/, "$1");
|
|
8251
|
+
processedLine = processedLine.replace(/!\[([^\]]*)\]\(([^)]+)\)/, "$1");
|
|
8252
|
+
processedLine = processedLine.replace(/^>\s*(.+)$/, "$1");
|
|
8253
|
+
processedLine = processedLine.replace(/^(\*{3,}|-{3,}|_{3,})$/, "");
|
|
8254
|
+
processedLine = processedLine.replace(/^(\s*[-+*]\s+|\s*\d+\.\s+)(.+)$/, "$2");
|
|
8255
|
+
processedLine = processedLine.replace(/<\/?[^>]+(>|$)/g, "");
|
|
8256
|
+
processedLines.push(processedLine);
|
|
8257
|
+
}
|
|
8258
|
+
cleanedText = processedLines.join("\n");
|
|
8259
|
+
cleanedText = replaceFences(cleanedText, ({ body }) => body);
|
|
8260
|
+
return cleanedText;
|
|
8261
|
+
};
|
|
8262
|
+
|
|
8263
|
+
// source/fence-meta.ts
|
|
8264
|
+
var FENCE_META_KEY = "fenceMeta";
|
|
8265
|
+
function splitFenceInfo(info) {
|
|
8266
|
+
const trimmed = info.trim();
|
|
8267
|
+
if (!trimmed) return {};
|
|
8268
|
+
const firstSpace = trimmed.search(/\s/);
|
|
8269
|
+
let token = firstSpace === -1 ? trimmed : trimmed.slice(0, firstSpace);
|
|
8270
|
+
let rest = firstSpace === -1 ? "" : trimmed.slice(firstSpace).trim();
|
|
8271
|
+
const braceAt = token.indexOf("{");
|
|
8272
|
+
if (braceAt > 0) {
|
|
8273
|
+
rest = `${token.slice(braceAt)} ${rest}`.trim();
|
|
8274
|
+
token = token.slice(0, braceAt);
|
|
8275
|
+
}
|
|
8276
|
+
const colonAt = token.indexOf(":");
|
|
8277
|
+
if (colonAt > 0 && colonAt < token.length - 1) {
|
|
8278
|
+
const filename = token.slice(colonAt + 1);
|
|
8279
|
+
rest = `title="${filename}" ${rest}`.trim();
|
|
8280
|
+
token = token.slice(0, colonAt);
|
|
8281
|
+
}
|
|
8282
|
+
if (token.startsWith("{")) {
|
|
8283
|
+
rest = `${token} ${rest}`.trim();
|
|
8284
|
+
token = "";
|
|
8285
|
+
}
|
|
8286
|
+
const out = {};
|
|
8287
|
+
if (token) out.language = token;
|
|
8288
|
+
if (rest) out.meta = rest;
|
|
8289
|
+
return out;
|
|
8290
|
+
}
|
|
8291
|
+
var TITLE_RE = /(?:^|\s)(?:title|filename|file)=(?:"([^"]*)"|'([^']*)'|(\S+))/i;
|
|
8292
|
+
var RANGES_RE = /(?:^|\s)\{([\d\s,-]+)\}/;
|
|
8293
|
+
var LINE_NUMBERS_RE = /(?:^|\s)showLineNumbers(?:\{(\d+)\})?(?=\s|$)/;
|
|
8294
|
+
var MAX_HIGHLIGHT_LINES = 1e4;
|
|
8295
|
+
function parseFenceMeta(meta) {
|
|
8296
|
+
const result = { highlightLines: [] };
|
|
8297
|
+
if (!meta) return result;
|
|
8298
|
+
const title = TITLE_RE.exec(meta);
|
|
8299
|
+
if (title) {
|
|
8300
|
+
const value = (title[1] ?? title[2] ?? title[3] ?? "").trim();
|
|
8301
|
+
if (value) result.title = value;
|
|
8302
|
+
}
|
|
8303
|
+
const ranges = RANGES_RE.exec(meta);
|
|
8304
|
+
if (ranges) result.highlightLines = parseLineRanges(ranges[1] ?? "");
|
|
8305
|
+
const lineNumbers = LINE_NUMBERS_RE.exec(meta);
|
|
8306
|
+
if (lineNumbers) {
|
|
8307
|
+
result.showLineNumbers = true;
|
|
8308
|
+
if (lineNumbers[1]) {
|
|
8309
|
+
const start = Number.parseInt(lineNumbers[1], 10);
|
|
8310
|
+
if (Number.isFinite(start) && start > 0) result.startLine = start;
|
|
8311
|
+
}
|
|
8312
|
+
}
|
|
8313
|
+
return result;
|
|
8314
|
+
}
|
|
8315
|
+
function parseLineRanges(spec) {
|
|
8316
|
+
const lines = /* @__PURE__ */ new Set();
|
|
8317
|
+
for (const part of spec.split(",")) {
|
|
8318
|
+
const piece = part.trim();
|
|
8319
|
+
if (!piece) continue;
|
|
8320
|
+
const range = /^(\d+)\s*-\s*(\d+)$/.exec(piece);
|
|
8321
|
+
if (range) {
|
|
8322
|
+
const from = Number.parseInt(range[1] ?? "", 10);
|
|
8323
|
+
const to = Number.parseInt(range[2] ?? "", 10);
|
|
8324
|
+
if (from < 1 || to < from) continue;
|
|
8325
|
+
for (let n = from; n <= to && lines.size < MAX_HIGHLIGHT_LINES; n += 1) {
|
|
8326
|
+
lines.add(n);
|
|
8327
|
+
}
|
|
8328
|
+
continue;
|
|
8329
|
+
}
|
|
8330
|
+
if (/^\d+$/.test(piece)) {
|
|
8331
|
+
const n = Number.parseInt(piece, 10);
|
|
8332
|
+
if (n >= 1) lines.add(n);
|
|
8333
|
+
}
|
|
8334
|
+
}
|
|
8335
|
+
return [...lines].sort((a, b) => a - b);
|
|
8336
|
+
}
|
|
8337
|
+
|
|
8338
|
+
// source/directive-container.ts
|
|
8339
|
+
var DIRECTIVE_CONTAINER_OPEN = /^[ \t]{0,3}(:{3,})[A-Za-z][\w-]*/;
|
|
8340
|
+
var CLOSE = /^[ \t]{0,3}(:{3,})[ \t]*$/;
|
|
8341
|
+
var DirectiveContainerTracker = class {
|
|
8342
|
+
stack;
|
|
8343
|
+
fence = null;
|
|
8344
|
+
constructor(openingLine) {
|
|
8345
|
+
const m = DIRECTIVE_CONTAINER_OPEN.exec(openingLine);
|
|
8346
|
+
this.stack = [m ? m[1].length : 3];
|
|
8347
|
+
}
|
|
8348
|
+
/** Feed the next line (after the opener). True once the outermost container has closed on this line. */
|
|
8349
|
+
consume(line) {
|
|
8350
|
+
if (this.fence) {
|
|
8351
|
+
if (this.fence.feed(line)) this.fence = null;
|
|
8352
|
+
return false;
|
|
8353
|
+
}
|
|
8354
|
+
const opener = fenceOpenerOf(line);
|
|
8355
|
+
if (opener) {
|
|
8356
|
+
this.fence = new FenceReader(opener);
|
|
8357
|
+
return false;
|
|
8358
|
+
}
|
|
8359
|
+
const open = DIRECTIVE_CONTAINER_OPEN.exec(line);
|
|
8360
|
+
if (open) {
|
|
8361
|
+
this.stack.push(open[1].length);
|
|
8362
|
+
return false;
|
|
8363
|
+
}
|
|
8364
|
+
const close = CLOSE.exec(line);
|
|
8365
|
+
if (close && close[1].length >= (this.stack[this.stack.length - 1] ?? 3)) {
|
|
8366
|
+
this.stack.pop();
|
|
8367
|
+
return this.stack.length === 0;
|
|
8368
|
+
}
|
|
8369
|
+
return false;
|
|
8370
|
+
}
|
|
8371
|
+
};
|
|
8372
|
+
|
|
8373
|
+
// source/image-figure.ts
|
|
8374
|
+
var TITLED_IMAGE_LINE = /^[ \t]{0,3}!\[[^\]\n]*\]\(\s*<?[^\s)>]+>?\s+(?:"[^"\n]+"|'[^'\n]+')\s*\)[ \t]*$/;
|
|
8375
|
+
|
|
8376
|
+
// source/inline-code-span.ts
|
|
8377
|
+
function isInsideInlineCode(line, at) {
|
|
8378
|
+
let i = 0;
|
|
8379
|
+
while (i <= at && i < line.length) {
|
|
8380
|
+
if (line[i] === "\\") {
|
|
8381
|
+
i += 2;
|
|
8382
|
+
continue;
|
|
8383
|
+
}
|
|
8384
|
+
if (line[i] !== "`") {
|
|
8385
|
+
i += 1;
|
|
8386
|
+
continue;
|
|
8387
|
+
}
|
|
8388
|
+
let run = 0;
|
|
8389
|
+
while (line[i + run] === "`") run += 1;
|
|
8390
|
+
let close = -1;
|
|
8391
|
+
for (let j = i + run; j < line.length; ) {
|
|
8392
|
+
if (line[j] !== "`") {
|
|
8393
|
+
j += 1;
|
|
8394
|
+
continue;
|
|
8395
|
+
}
|
|
8396
|
+
let r = 0;
|
|
8397
|
+
while (line[j + r] === "`") r += 1;
|
|
8398
|
+
if (r === run) {
|
|
8399
|
+
close = j;
|
|
8400
|
+
break;
|
|
8401
|
+
}
|
|
8402
|
+
j += r;
|
|
8403
|
+
}
|
|
8404
|
+
if (close === -1) {
|
|
8405
|
+
i += run;
|
|
8406
|
+
continue;
|
|
8407
|
+
}
|
|
8408
|
+
if (at > i && at < close + run) return true;
|
|
8409
|
+
i = close + run;
|
|
8410
|
+
}
|
|
8411
|
+
return false;
|
|
8412
|
+
}
|
|
8413
|
+
function indexOutsideInlineCode(line, needle, from = 0) {
|
|
8414
|
+
for (let idx = line.indexOf(needle, from); idx !== -1; idx = line.indexOf(needle, idx + 1)) {
|
|
8415
|
+
if (!isInsideInlineCode(line, idx)) return idx;
|
|
8416
|
+
}
|
|
8417
|
+
return -1;
|
|
8418
|
+
}
|
|
8419
|
+
function hasUnclosedBacktickRun(text) {
|
|
8420
|
+
let i = 0;
|
|
8421
|
+
while (i < text.length) {
|
|
8422
|
+
if (text[i] === "\\") {
|
|
8423
|
+
i += 2;
|
|
8424
|
+
continue;
|
|
8425
|
+
}
|
|
8426
|
+
if (text[i] !== "`") {
|
|
8427
|
+
i += 1;
|
|
8428
|
+
continue;
|
|
8429
|
+
}
|
|
8430
|
+
let run = 0;
|
|
8431
|
+
while (text[i + run] === "`") run += 1;
|
|
8432
|
+
let close = -1;
|
|
8433
|
+
for (let j = i + run; j < text.length; ) {
|
|
8434
|
+
if (text[j] !== "`") {
|
|
8435
|
+
j += 1;
|
|
8436
|
+
continue;
|
|
8437
|
+
}
|
|
8438
|
+
let r = 0;
|
|
8439
|
+
while (text[j + r] === "`") r += 1;
|
|
8440
|
+
if (r === run) {
|
|
8441
|
+
close = j;
|
|
8442
|
+
break;
|
|
8443
|
+
}
|
|
8444
|
+
j += r;
|
|
8445
|
+
}
|
|
8446
|
+
if (close === -1) return true;
|
|
8447
|
+
i = close + run;
|
|
8448
|
+
}
|
|
8449
|
+
return false;
|
|
8450
|
+
}
|
|
8451
|
+
|
|
8452
|
+
// source/xml-tag-balance.ts
|
|
8453
|
+
function initialXmlBalance() {
|
|
8454
|
+
return { depth: 1, fence: null };
|
|
8455
|
+
}
|
|
8456
|
+
function escapeRegExp(value) {
|
|
8457
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8458
|
+
}
|
|
8459
|
+
function findBalancedXmlClose(line, tagName, state, { trackFences = true, nest = true } = {}) {
|
|
8460
|
+
if (state.fence) {
|
|
8461
|
+
if (state.fence.feed(line)) state.fence = null;
|
|
8462
|
+
return -1;
|
|
8463
|
+
}
|
|
8464
|
+
const opener = trackFences ? fenceOpenerOf(line) : null;
|
|
8465
|
+
if (opener) {
|
|
8466
|
+
state.fence = new FenceReader(opener);
|
|
8467
|
+
return -1;
|
|
8468
|
+
}
|
|
8469
|
+
const tag = new RegExp(
|
|
8470
|
+
`<(\\/?)${escapeRegExp(tagName)}(?=[\\s>/])[^<>]*?(\\/?)>`,
|
|
8471
|
+
"g"
|
|
8472
|
+
);
|
|
8473
|
+
for (const match of line.matchAll(tag)) {
|
|
8474
|
+
const closing = match[1] === "/";
|
|
8475
|
+
const selfClosing = match[2] === "/";
|
|
8476
|
+
if (closing) {
|
|
8477
|
+
state.depth -= 1;
|
|
8478
|
+
if (state.depth === 0) return match.index ?? -1;
|
|
8479
|
+
} else if (nest && !selfClosing && line.slice(0, match.index).trim() === "") {
|
|
8480
|
+
state.depth += 1;
|
|
8481
|
+
}
|
|
8482
|
+
}
|
|
8483
|
+
return -1;
|
|
8484
|
+
}
|
|
8485
|
+
|
|
8486
|
+
// source/gfm-table-lines.ts
|
|
8487
|
+
function findWholeTableStart(lines, from = 0) {
|
|
8488
|
+
for (let i = Math.max(0, from); i + 1 < lines.length; i += 1) if (tableStartsAt(lines, i)) return i;
|
|
8489
|
+
return -1;
|
|
8490
|
+
}
|
|
8491
|
+
function startsLikeTableRow(line) {
|
|
8492
|
+
return /^\s*\|/.test(line);
|
|
8493
|
+
}
|
|
8494
|
+
function isGrowingDelimiterRow(line) {
|
|
8495
|
+
return /^[\s|:-]*-[\s|:-]*$/.test(line);
|
|
8496
|
+
}
|
|
8497
|
+
function trailingTableStart(lines, end = lines.length) {
|
|
8498
|
+
const isTableLine = (line) => startsLikeTableRow(line) || continuesTable(line.trimStart());
|
|
8499
|
+
let start = end;
|
|
8500
|
+
while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
|
|
8501
|
+
if (start === end && end > 1 && isGrowingDelimiterRow(lines[end - 1] ?? "") && continuesTable((lines[end - 2] ?? "").trimStart())) {
|
|
8502
|
+
start = end - 1;
|
|
8503
|
+
while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
|
|
8504
|
+
}
|
|
8505
|
+
for (let head = start; head < end; head += 1) {
|
|
8506
|
+
if (startsLikeTableRow(lines[head] ?? "")) return head;
|
|
8507
|
+
if (end - head > 1 && isGrowingDelimiterRow(lines[head + 1] ?? "")) return head;
|
|
8508
|
+
}
|
|
8509
|
+
return end;
|
|
8510
|
+
}
|
|
8511
|
+
|
|
8512
|
+
export { ACTION_BY_CLASS, AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, CAPABILITY_BY_CLASS, CLASSES, CONTROL_KEYS, CONTROL_KEY_FIELDS, DIRECTIVE_CONTAINER_OPEN, DIRECTIVE_VERSION, DirectiveContainerTracker, DirectiveDecodeError, FENCE_META_KEY, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, IN_CONTENT_CLASSES, IR_ENVELOPE_CACHE_VERSION, IR_ENVELOPE_KEY, IR_PARTIAL_KEY, IR_VERSION, IrTree, JSON_DISCRIMINATOR, JsonStreamTokenizer, KIND_KEY, KindStorageError, KindStreamParser, NESTING_FENCE_LANGUAGES, NODE_OUTCOME_KIND, ParseSession, RECORD_DISPOSITION, RESERVED_PREFIX, ROOT_STORAGE_NAME, RUN_RESULT_KIND, SIDE_EFFECT_CLASSES, SLUG_PREFIX, SourceSpliceError, TITLED_IMAGE_LINE, XmlContainerTracker, advancePartialKind, asKindInstance, blockAt, blockEdit, blockRangeEdit, buildAgentSchemaWithRenderBlockSupport, buildCodePointIndex, buildCompliantKindSnapshot, buildDirectiveSlug, buildKindDirective, capabilityOf, classifyInboundEnvelopeMetadata, classifyInnerFenceLine, cleanMarkdown, closeFence, codeSpanText, collectLinkDefinitions, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, continuesTable, controlKeysApplyTo, convertAiSchemaToBlockFields, createFingerprinter, createKindStreamParser, createKindValidator, decodeDirective, describeDualGateFailure, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, disposeParseSession, emitPayloadFence, emitPayloadJson, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, executesAtOutputRoot, fenceDiscriminator, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, fieldsToDbPayload, findBalancedXmlClose, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, findWholeTableStart, fingerprintText, formatBlockLabel, getParseSession, hasUnclosedBacktickRun, indexOutsideInlineCode, initialXmlBalance, injectKindIntoObjectSchema, irPathIsUnderOrEqual, irPathKey, irPathLabel, irPathsEqual, isCanonicalBlockIR, isDirectiveClass, isDuplicateBlockSlug, isEmptyResidue, isEscapedBracketMath, isGfmDelimiterRow, isGrowingDelimiterRow, isHtmlBlockTagName, isInsideInlineCode, isIrEnvelopeCache, isJsonAnyField, isKindDirective, isLegacyShell, isMathPlaceholder, isPipeLedRow, isProvisionalKind, isReservedDirectiveSlug, isScalarArrayType, isSingleDollarMath, isTerminalKindEvent, islandEdit, itemFacts, itemSubtitle, itemTitle, joinSource, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, kindSchemaToStorage, kindVerdictOf, legacyShellUses, lineIndent, listIslands, looksLikeDirectiveHead, looksLikeDisplayMath, looksLikeOpenInlineMath, makePartialKindStalenessGate, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, markdownToPlainText, mathToReadable, mergeResidueIntoValue, normalizeAiSchemaInput, normalizeJsonRegion, normalizeLinkLabel, nounFamily, nounLabel, nounTitleColumn, openParseSession, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseDirectiveSlug, parseFenceMeta, parseFenceOpener, parseLineRanges, pendingCodeSpanStart, pendingDisplayMathOpener, readEnvelope, readNodeOutcomeValue, readObjectKind, readOutputRef, readPartialKindEvent, readRunResultValue, readXmlTag, reconstructRegionValue, rehydrateNodeOutcome, rehydrateRunResult, removeCodeSpans, replaceFences, resetLegacyShellUses, resolveReferenceLinks, resolvesInContent, reuseEnvelopeIfCurrent, rowCells, runKindDualGate, runSchemaConversion, sanitizeInboundEnvelopeMetadata, sanitizeInboundPartialKindMetadata, scalarArrayItemType, schemaLayoutMode, schemaStructureDepth, setJsonRootKeyLookup, singleDollarAfter, singleDollarMathEnd, soleFence, spliceSave, splitFenceInfo, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsLikeTableRow, startsPipelessTable, storageToKindSchema, stripControlKeys, stripKindDeep, tableContainerIndent, tableStartsAt, titleCaseToken, toCodePointOffset, toUtf16Offset, tokenizeSource, trailingTableStart, trimFenceLine, tryDecodeDirective, tryDecodeDirectiveContent, unescapeCellPipes, unwrapCodeSpans, unwrapKindEnvelopes, validateBlockSchemaSavePlan, validateStructuralLeg, withControlKeyFields, withControlKeys, withRootKind, xmlDiscriminator };
|
|
8085
8513
|
//# sourceMappingURL=index.js.map
|
|
8086
8514
|
//# sourceMappingURL=index.js.map
|