@ai-matrx/content-ir 0.20.0 → 0.21.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 +31 -0
- package/dist/convert.cjs.map +1 -1
- package/dist/convert.js.map +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js.map +1 -1
- package/dist/directives.cjs +14 -3
- package/dist/directives.cjs.map +1 -1
- package/dist/directives.js +14 -3
- package/dist/directives.js.map +1 -1
- package/dist/index.cjs +456 -3
- 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 +433 -4
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +442 -0
- 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 +419 -1
- package/dist/source.js.map +1 -1
- package/dist/text-case.cjs +14 -3
- package/dist/text-case.cjs.map +1 -1
- package/dist/text-case.d.cts +13 -7
- package/dist/text-case.d.ts +13 -7
- package/dist/text-case.js +14 -3
- package/dist/text-case.js.map +1 -1
- package/package.json +1 -1
package/dist/source.cjs
CHANGED
|
@@ -2877,20 +2877,443 @@ function resolveReferenceLinks(fragment, defs) {
|
|
|
2877
2877
|
return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
|
|
2878
2878
|
}
|
|
2879
2879
|
|
|
2880
|
+
// source/code-range-edits.ts
|
|
2881
|
+
function unwrapCodeSpans(text) {
|
|
2882
|
+
if (!text.includes("`")) return text;
|
|
2883
|
+
return mapCodeRanges(text, (range, raw) => range.kind === "span" ? codeSpanText(raw) : raw);
|
|
2884
|
+
}
|
|
2885
|
+
function removeCodeSpans(text) {
|
|
2886
|
+
if (!text.includes("`")) return text;
|
|
2887
|
+
return mapCodeRanges(text, (range, raw) => range.kind === "span" ? "" : raw);
|
|
2888
|
+
}
|
|
2889
|
+
function replaceFences(text, fn) {
|
|
2890
|
+
if (!text.includes("```") && !text.includes("~~~")) return text;
|
|
2891
|
+
return mapCodeRanges(text, (range, raw) => {
|
|
2892
|
+
if (range.kind !== "fence") return raw;
|
|
2893
|
+
const parts = fenceParts(raw);
|
|
2894
|
+
return fn({ lang: parts?.opener.lang ?? "", body: parts?.body ?? raw, closed: parts?.closed ?? false, raw });
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2897
|
+
function soleFence(text, options = {}) {
|
|
2898
|
+
const trimmed = text.trim();
|
|
2899
|
+
if (!trimmed.startsWith("`") && !trimmed.startsWith("~")) return null;
|
|
2900
|
+
const ranges = findCodeRanges(trimmed);
|
|
2901
|
+
const only = ranges.length === 1 ? ranges[0] : void 0;
|
|
2902
|
+
if (!only || only.kind !== "fence" || only.start !== 0 || only.end !== trimmed.length) return null;
|
|
2903
|
+
const parts = fenceParts(trimmed);
|
|
2904
|
+
if (!parts || !parts.closed && !options.allowUnclosed) return null;
|
|
2905
|
+
return { lang: parts.opener.lang, body: parts.body, closed: parts.closed };
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
// source/plain-text.ts
|
|
2909
|
+
var INLINE_PATTERNS = [
|
|
2910
|
+
// [label](href) → label. Runs first so emphasis inside a label still unwraps.
|
|
2911
|
+
[/\[([^\]]+)\]\([^)]*\)/g, "$1"],
|
|
2912
|
+
[/\*\*\*(?=\S)([\s\S]*?\S)\*\*\*/g, "$1"],
|
|
2913
|
+
[/___(?=\S)([\s\S]*?\S)___/g, "$1"],
|
|
2914
|
+
[/\*\*(?=\S)([\s\S]*?\S)\*\*/g, "$1"],
|
|
2915
|
+
[/__(?=\S)([\s\S]*?\S)__/g, "$1"],
|
|
2916
|
+
[/~~(?=\S)([\s\S]*?\S)~~/g, "$1"],
|
|
2917
|
+
[/\*(?=\S)([^*\n]*?\S)\*/g, "$1"],
|
|
2918
|
+
// Underscore italics only between word boundaries: snake_case_names are not
|
|
2919
|
+
// emphasis, and mangling an identifier is a worse defect than a stray marker.
|
|
2920
|
+
[/(^|[\s(])_(?=\S)([^_\n]*?\S)_(?=[\s).,;:!?]|$)/g, "$1$2"]
|
|
2921
|
+
];
|
|
2922
|
+
var MATH_STRUCTURAL = [
|
|
2923
|
+
[/\\(?:d|t)?frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g, "$1/$2"],
|
|
2924
|
+
[/\\sqrt\s*\{([^{}]*)\}/g, "\u221A($1)"]
|
|
2925
|
+
];
|
|
2926
|
+
var MATH_PATTERNS = [
|
|
2927
|
+
// Environments (\begin{aligned} … \end{aligned}) carry no meaning in a
|
|
2928
|
+
// one-line preview; drop the wrapper, keep the contents. Without this the
|
|
2929
|
+
// catch-all below turned them into the word "aligned" twice.
|
|
2930
|
+
[/\\(?:begin|end)\s*\{[^{}]*\}/g, " "],
|
|
2931
|
+
// A TeX line break inside a preview is just a space.
|
|
2932
|
+
[/\\\\/g, " "],
|
|
2933
|
+
// TeX spacing commands (\, \; \: thin/medium space, \! negative space).
|
|
2934
|
+
[/\\[,;:]/g, " "],
|
|
2935
|
+
[/\\!/g, ""],
|
|
2936
|
+
// \left\{ … \right\} — the escaped-brace forms, which the character-class
|
|
2937
|
+
// rule below cannot reach because the brace is preceded by a backslash.
|
|
2938
|
+
[/\\(?:left|right)\s*\\?([([\]|){}])/g, "$1"],
|
|
2939
|
+
// NOTE: every command below ends with (?![a-zA-Z]) and NOT \b. `_` is a WORD
|
|
2940
|
+
// character, so \b fails after `\sum_` — which silently left every
|
|
2941
|
+
// summation, integral and limit card reading as "sum_" / "int_".
|
|
2942
|
+
[/\\times(?![a-zA-Z])/g, "\xD7"],
|
|
2943
|
+
[/\\div(?![a-zA-Z])/g, "\xF7"],
|
|
2944
|
+
[/\\pm(?![a-zA-Z])/g, "\xB1"],
|
|
2945
|
+
[/\\cdot(?![a-zA-Z])/g, "\xB7"],
|
|
2946
|
+
[/\\leq(?![a-zA-Z])/g, "\u2264"],
|
|
2947
|
+
[/\\geq(?![a-zA-Z])/g, "\u2265"],
|
|
2948
|
+
[/\\neq(?![a-zA-Z])/g, "\u2260"],
|
|
2949
|
+
[/\\approx(?![a-zA-Z])/g, "\u2248"],
|
|
2950
|
+
[/\\infty(?![a-zA-Z])/g, "\u221E"],
|
|
2951
|
+
[/\\pi(?![a-zA-Z])/g, "\u03C0"],
|
|
2952
|
+
[/\\theta(?![a-zA-Z])/g, "\u03B8"],
|
|
2953
|
+
[/\\alpha(?![a-zA-Z])/g, "\u03B1"],
|
|
2954
|
+
[/\\beta(?![a-zA-Z])/g, "\u03B2"],
|
|
2955
|
+
[/\\Delta(?![a-zA-Z])/g, "\u0394"],
|
|
2956
|
+
[/\\delta(?![a-zA-Z])/g, "\u03B4"],
|
|
2957
|
+
[/\\sum(?![a-zA-Z])/g, "\u03A3"],
|
|
2958
|
+
[/\\prod(?![a-zA-Z])/g, "\u220F"],
|
|
2959
|
+
[/\\int(?![a-zA-Z])/g, "\u222B"],
|
|
2960
|
+
[/\\lim(?![a-zA-Z])/g, "lim"],
|
|
2961
|
+
[/\\(?:rightarrow|to)(?![a-zA-Z])/g, "\u2192"],
|
|
2962
|
+
// Braces that only ever grouped a script or argument: ^{2} → ^2, _{i} → _i.
|
|
2963
|
+
[/([_^])\s*\{([^{}]*)\}/g, "$1$2"],
|
|
2964
|
+
// Any remaining single-argument command: \text{x} / \mathrm{x} → x.
|
|
2965
|
+
[/\\[a-zA-Z]+\s*\{([^{}]*)\}/g, "$1"],
|
|
2966
|
+
// Bare commands we did not translate: drop the backslash, keep the word.
|
|
2967
|
+
[/\\([a-zA-Z]+)/g, "$1"]
|
|
2968
|
+
];
|
|
2969
|
+
var MATH_REGIONS = [
|
|
2970
|
+
/\\\[([\s\S]*?)\\\]/g,
|
|
2971
|
+
/\\\(([\s\S]*?)\\\)/g,
|
|
2972
|
+
/\$\$([\s\S]*?)\$\$/g
|
|
2973
|
+
];
|
|
2974
|
+
function mathToReadable(expression) {
|
|
2975
|
+
let text = expression;
|
|
2976
|
+
for (let pass = 0; pass < 8; pass += 1) {
|
|
2977
|
+
const before = text;
|
|
2978
|
+
for (const [pattern, replacement] of MATH_STRUCTURAL) {
|
|
2979
|
+
text = text.replace(pattern, replacement);
|
|
2980
|
+
}
|
|
2981
|
+
if (text === before) break;
|
|
2982
|
+
}
|
|
2983
|
+
for (const [pattern, replacement] of MATH_PATTERNS) {
|
|
2984
|
+
text = text.replace(pattern, replacement);
|
|
2985
|
+
}
|
|
2986
|
+
return text.trim();
|
|
2987
|
+
}
|
|
2988
|
+
function markdownToPlainText(value) {
|
|
2989
|
+
if (!value) return "";
|
|
2990
|
+
const mathChunks = [];
|
|
2991
|
+
let text = value;
|
|
2992
|
+
for (const region of MATH_REGIONS) {
|
|
2993
|
+
text = text.replace(region, (_match, inner) => {
|
|
2994
|
+
mathChunks.push(mathToReadable(inner));
|
|
2995
|
+
return `\uE000MATH${mathChunks.length - 1}\uE001`;
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
for (const [pattern, replacement] of INLINE_PATTERNS) {
|
|
2999
|
+
text = text.replace(pattern, replacement);
|
|
3000
|
+
}
|
|
3001
|
+
text = unwrapCodeSpans(text);
|
|
3002
|
+
text = text.replace(
|
|
3003
|
+
/\uE000MATH(\d+)\uE001/g,
|
|
3004
|
+
(_m, index) => mathChunks[Number(index)] ?? ""
|
|
3005
|
+
);
|
|
3006
|
+
return text.replace(/[ \t]{2,}/g, " ").trim();
|
|
3007
|
+
}
|
|
3008
|
+
function unwrapKindEnvelopes(value) {
|
|
3009
|
+
if (!value) return "";
|
|
3010
|
+
if (!value.includes("<artifact")) return value;
|
|
3011
|
+
return tokenizeSource(value).map((block) => {
|
|
3012
|
+
if (block.kind !== "island" || block.islandType !== "xml_attr" && block.islandType !== "xml_container") {
|
|
3013
|
+
return block.raw;
|
|
3014
|
+
}
|
|
3015
|
+
const match = /^\s*<artifact\b[^>]*>([\s\S]*?)<\/artifact>\s*$/.exec(block.raw);
|
|
3016
|
+
return match ? (match[1] ?? "").replace(/^\n/, "").replace(/\n$/, "") : block.raw;
|
|
3017
|
+
}).join("");
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
// source/clean-markdown.ts
|
|
3021
|
+
var cleanMarkdown = (text) => {
|
|
3022
|
+
if (!text || typeof text !== "string") return "";
|
|
3023
|
+
let cleanedText = text;
|
|
3024
|
+
const lines = cleanedText.split("\n");
|
|
3025
|
+
const processedLines = [];
|
|
3026
|
+
for (let line of lines) {
|
|
3027
|
+
let processedLine = line;
|
|
3028
|
+
if (processedLine.trim() === "") {
|
|
3029
|
+
processedLines.push(processedLine);
|
|
3030
|
+
continue;
|
|
3031
|
+
}
|
|
3032
|
+
processedLine = processedLine.replace(/^#{1,6}\s+(.+)$/, "$1");
|
|
3033
|
+
processedLine = processedLine.replace(/(\*\*|__)(.*?)\1/, "$2");
|
|
3034
|
+
processedLine = processedLine.replace(/(\*|_)(.*?)\1/, "$2");
|
|
3035
|
+
processedLine = unwrapCodeSpans(processedLine);
|
|
3036
|
+
processedLine = processedLine.replace(/\[([^\]]+)\]\(([^)]+)\)/, "$1");
|
|
3037
|
+
processedLine = processedLine.replace(/!\[([^\]]*)\]\(([^)]+)\)/, "$1");
|
|
3038
|
+
processedLine = processedLine.replace(/^>\s*(.+)$/, "$1");
|
|
3039
|
+
processedLine = processedLine.replace(/^(\*{3,}|-{3,}|_{3,})$/, "");
|
|
3040
|
+
processedLine = processedLine.replace(/^(\s*[-+*]\s+|\s*\d+\.\s+)(.+)$/, "$2");
|
|
3041
|
+
processedLine = processedLine.replace(/<\/?[^>]+(>|$)/g, "");
|
|
3042
|
+
processedLines.push(processedLine);
|
|
3043
|
+
}
|
|
3044
|
+
cleanedText = processedLines.join("\n");
|
|
3045
|
+
cleanedText = replaceFences(cleanedText, ({ body }) => body);
|
|
3046
|
+
return cleanedText;
|
|
3047
|
+
};
|
|
3048
|
+
|
|
3049
|
+
// source/fence-meta.ts
|
|
3050
|
+
var FENCE_META_KEY = "fenceMeta";
|
|
3051
|
+
function splitFenceInfo(info) {
|
|
3052
|
+
const trimmed = info.trim();
|
|
3053
|
+
if (!trimmed) return {};
|
|
3054
|
+
const firstSpace = trimmed.search(/\s/);
|
|
3055
|
+
let token = firstSpace === -1 ? trimmed : trimmed.slice(0, firstSpace);
|
|
3056
|
+
let rest = firstSpace === -1 ? "" : trimmed.slice(firstSpace).trim();
|
|
3057
|
+
const braceAt = token.indexOf("{");
|
|
3058
|
+
if (braceAt > 0) {
|
|
3059
|
+
rest = `${token.slice(braceAt)} ${rest}`.trim();
|
|
3060
|
+
token = token.slice(0, braceAt);
|
|
3061
|
+
}
|
|
3062
|
+
const colonAt = token.indexOf(":");
|
|
3063
|
+
if (colonAt > 0 && colonAt < token.length - 1) {
|
|
3064
|
+
const filename = token.slice(colonAt + 1);
|
|
3065
|
+
rest = `title="${filename}" ${rest}`.trim();
|
|
3066
|
+
token = token.slice(0, colonAt);
|
|
3067
|
+
}
|
|
3068
|
+
if (token.startsWith("{")) {
|
|
3069
|
+
rest = `${token} ${rest}`.trim();
|
|
3070
|
+
token = "";
|
|
3071
|
+
}
|
|
3072
|
+
const out = {};
|
|
3073
|
+
if (token) out.language = token;
|
|
3074
|
+
if (rest) out.meta = rest;
|
|
3075
|
+
return out;
|
|
3076
|
+
}
|
|
3077
|
+
var TITLE_RE = /(?:^|\s)(?:title|filename|file)=(?:"([^"]*)"|'([^']*)'|(\S+))/i;
|
|
3078
|
+
var RANGES_RE = /(?:^|\s)\{([\d\s,-]+)\}/;
|
|
3079
|
+
var LINE_NUMBERS_RE = /(?:^|\s)showLineNumbers(?:\{(\d+)\})?(?=\s|$)/;
|
|
3080
|
+
var MAX_HIGHLIGHT_LINES = 1e4;
|
|
3081
|
+
function parseFenceMeta(meta) {
|
|
3082
|
+
const result = { highlightLines: [] };
|
|
3083
|
+
if (!meta) return result;
|
|
3084
|
+
const title = TITLE_RE.exec(meta);
|
|
3085
|
+
if (title) {
|
|
3086
|
+
const value = (title[1] ?? title[2] ?? title[3] ?? "").trim();
|
|
3087
|
+
if (value) result.title = value;
|
|
3088
|
+
}
|
|
3089
|
+
const ranges = RANGES_RE.exec(meta);
|
|
3090
|
+
if (ranges) result.highlightLines = parseLineRanges(ranges[1] ?? "");
|
|
3091
|
+
const lineNumbers = LINE_NUMBERS_RE.exec(meta);
|
|
3092
|
+
if (lineNumbers) {
|
|
3093
|
+
result.showLineNumbers = true;
|
|
3094
|
+
if (lineNumbers[1]) {
|
|
3095
|
+
const start = Number.parseInt(lineNumbers[1], 10);
|
|
3096
|
+
if (Number.isFinite(start) && start > 0) result.startLine = start;
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
return result;
|
|
3100
|
+
}
|
|
3101
|
+
function parseLineRanges(spec) {
|
|
3102
|
+
const lines = /* @__PURE__ */ new Set();
|
|
3103
|
+
for (const part of spec.split(",")) {
|
|
3104
|
+
const piece = part.trim();
|
|
3105
|
+
if (!piece) continue;
|
|
3106
|
+
const range = /^(\d+)\s*-\s*(\d+)$/.exec(piece);
|
|
3107
|
+
if (range) {
|
|
3108
|
+
const from = Number.parseInt(range[1] ?? "", 10);
|
|
3109
|
+
const to = Number.parseInt(range[2] ?? "", 10);
|
|
3110
|
+
if (from < 1 || to < from) continue;
|
|
3111
|
+
for (let n = from; n <= to && lines.size < MAX_HIGHLIGHT_LINES; n += 1) {
|
|
3112
|
+
lines.add(n);
|
|
3113
|
+
}
|
|
3114
|
+
continue;
|
|
3115
|
+
}
|
|
3116
|
+
if (/^\d+$/.test(piece)) {
|
|
3117
|
+
const n = Number.parseInt(piece, 10);
|
|
3118
|
+
if (n >= 1) lines.add(n);
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
return [...lines].sort((a, b) => a - b);
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
// source/directive-container.ts
|
|
3125
|
+
var DIRECTIVE_CONTAINER_OPEN = /^[ \t]{0,3}(:{3,})[A-Za-z][\w-]*/;
|
|
3126
|
+
var CLOSE = /^[ \t]{0,3}(:{3,})[ \t]*$/;
|
|
3127
|
+
var DirectiveContainerTracker = class {
|
|
3128
|
+
stack;
|
|
3129
|
+
fence = null;
|
|
3130
|
+
constructor(openingLine) {
|
|
3131
|
+
const m = DIRECTIVE_CONTAINER_OPEN.exec(openingLine);
|
|
3132
|
+
this.stack = [m ? m[1].length : 3];
|
|
3133
|
+
}
|
|
3134
|
+
/** Feed the next line (after the opener). True once the outermost container has closed on this line. */
|
|
3135
|
+
consume(line) {
|
|
3136
|
+
if (this.fence) {
|
|
3137
|
+
if (this.fence.feed(line)) this.fence = null;
|
|
3138
|
+
return false;
|
|
3139
|
+
}
|
|
3140
|
+
const opener = fenceOpenerOf(line);
|
|
3141
|
+
if (opener) {
|
|
3142
|
+
this.fence = new FenceReader(opener);
|
|
3143
|
+
return false;
|
|
3144
|
+
}
|
|
3145
|
+
const open = DIRECTIVE_CONTAINER_OPEN.exec(line);
|
|
3146
|
+
if (open) {
|
|
3147
|
+
this.stack.push(open[1].length);
|
|
3148
|
+
return false;
|
|
3149
|
+
}
|
|
3150
|
+
const close = CLOSE.exec(line);
|
|
3151
|
+
if (close && close[1].length >= (this.stack[this.stack.length - 1] ?? 3)) {
|
|
3152
|
+
this.stack.pop();
|
|
3153
|
+
return this.stack.length === 0;
|
|
3154
|
+
}
|
|
3155
|
+
return false;
|
|
3156
|
+
}
|
|
3157
|
+
};
|
|
3158
|
+
|
|
3159
|
+
// source/image-figure.ts
|
|
3160
|
+
var TITLED_IMAGE_LINE = /^[ \t]{0,3}!\[[^\]\n]*\]\(\s*<?[^\s)>]+>?\s+(?:"[^"\n]+"|'[^'\n]+')\s*\)[ \t]*$/;
|
|
3161
|
+
|
|
3162
|
+
// source/inline-code-span.ts
|
|
3163
|
+
function isInsideInlineCode(line, at) {
|
|
3164
|
+
let i = 0;
|
|
3165
|
+
while (i <= at && i < line.length) {
|
|
3166
|
+
if (line[i] === "\\") {
|
|
3167
|
+
i += 2;
|
|
3168
|
+
continue;
|
|
3169
|
+
}
|
|
3170
|
+
if (line[i] !== "`") {
|
|
3171
|
+
i += 1;
|
|
3172
|
+
continue;
|
|
3173
|
+
}
|
|
3174
|
+
let run = 0;
|
|
3175
|
+
while (line[i + run] === "`") run += 1;
|
|
3176
|
+
let close = -1;
|
|
3177
|
+
for (let j = i + run; j < line.length; ) {
|
|
3178
|
+
if (line[j] !== "`") {
|
|
3179
|
+
j += 1;
|
|
3180
|
+
continue;
|
|
3181
|
+
}
|
|
3182
|
+
let r = 0;
|
|
3183
|
+
while (line[j + r] === "`") r += 1;
|
|
3184
|
+
if (r === run) {
|
|
3185
|
+
close = j;
|
|
3186
|
+
break;
|
|
3187
|
+
}
|
|
3188
|
+
j += r;
|
|
3189
|
+
}
|
|
3190
|
+
if (close === -1) {
|
|
3191
|
+
i += run;
|
|
3192
|
+
continue;
|
|
3193
|
+
}
|
|
3194
|
+
if (at > i && at < close + run) return true;
|
|
3195
|
+
i = close + run;
|
|
3196
|
+
}
|
|
3197
|
+
return false;
|
|
3198
|
+
}
|
|
3199
|
+
function indexOutsideInlineCode(line, needle, from = 0) {
|
|
3200
|
+
for (let idx = line.indexOf(needle, from); idx !== -1; idx = line.indexOf(needle, idx + 1)) {
|
|
3201
|
+
if (!isInsideInlineCode(line, idx)) return idx;
|
|
3202
|
+
}
|
|
3203
|
+
return -1;
|
|
3204
|
+
}
|
|
3205
|
+
function hasUnclosedBacktickRun(text) {
|
|
3206
|
+
let i = 0;
|
|
3207
|
+
while (i < text.length) {
|
|
3208
|
+
if (text[i] === "\\") {
|
|
3209
|
+
i += 2;
|
|
3210
|
+
continue;
|
|
3211
|
+
}
|
|
3212
|
+
if (text[i] !== "`") {
|
|
3213
|
+
i += 1;
|
|
3214
|
+
continue;
|
|
3215
|
+
}
|
|
3216
|
+
let run = 0;
|
|
3217
|
+
while (text[i + run] === "`") run += 1;
|
|
3218
|
+
let close = -1;
|
|
3219
|
+
for (let j = i + run; j < text.length; ) {
|
|
3220
|
+
if (text[j] !== "`") {
|
|
3221
|
+
j += 1;
|
|
3222
|
+
continue;
|
|
3223
|
+
}
|
|
3224
|
+
let r = 0;
|
|
3225
|
+
while (text[j + r] === "`") r += 1;
|
|
3226
|
+
if (r === run) {
|
|
3227
|
+
close = j;
|
|
3228
|
+
break;
|
|
3229
|
+
}
|
|
3230
|
+
j += r;
|
|
3231
|
+
}
|
|
3232
|
+
if (close === -1) return true;
|
|
3233
|
+
i = close + run;
|
|
3234
|
+
}
|
|
3235
|
+
return false;
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
// source/xml-tag-balance.ts
|
|
3239
|
+
function initialXmlBalance() {
|
|
3240
|
+
return { depth: 1, fence: null };
|
|
3241
|
+
}
|
|
3242
|
+
function escapeRegExp(value) {
|
|
3243
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3244
|
+
}
|
|
3245
|
+
function findBalancedXmlClose(line, tagName, state, { trackFences = true, nest = true } = {}) {
|
|
3246
|
+
if (state.fence) {
|
|
3247
|
+
if (state.fence.feed(line)) state.fence = null;
|
|
3248
|
+
return -1;
|
|
3249
|
+
}
|
|
3250
|
+
const opener = trackFences ? fenceOpenerOf(line) : null;
|
|
3251
|
+
if (opener) {
|
|
3252
|
+
state.fence = new FenceReader(opener);
|
|
3253
|
+
return -1;
|
|
3254
|
+
}
|
|
3255
|
+
const tag = new RegExp(
|
|
3256
|
+
`<(\\/?)${escapeRegExp(tagName)}(?=[\\s>/])[^<>]*?(\\/?)>`,
|
|
3257
|
+
"g"
|
|
3258
|
+
);
|
|
3259
|
+
for (const match of line.matchAll(tag)) {
|
|
3260
|
+
const closing = match[1] === "/";
|
|
3261
|
+
const selfClosing = match[2] === "/";
|
|
3262
|
+
if (closing) {
|
|
3263
|
+
state.depth -= 1;
|
|
3264
|
+
if (state.depth === 0) return match.index ?? -1;
|
|
3265
|
+
} else if (nest && !selfClosing && line.slice(0, match.index).trim() === "") {
|
|
3266
|
+
state.depth += 1;
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
return -1;
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
// source/gfm-table-lines.ts
|
|
3273
|
+
function findWholeTableStart(lines, from = 0) {
|
|
3274
|
+
for (let i = Math.max(0, from); i + 1 < lines.length; i += 1) if (tableStartsAt(lines, i)) return i;
|
|
3275
|
+
return -1;
|
|
3276
|
+
}
|
|
3277
|
+
function startsLikeTableRow(line) {
|
|
3278
|
+
return /^\s*\|/.test(line);
|
|
3279
|
+
}
|
|
3280
|
+
function isGrowingDelimiterRow(line) {
|
|
3281
|
+
return /^[\s|:-]*-[\s|:-]*$/.test(line);
|
|
3282
|
+
}
|
|
3283
|
+
function trailingTableStart(lines, end = lines.length) {
|
|
3284
|
+
const isTableLine = (line) => startsLikeTableRow(line) || continuesTable(line.trimStart());
|
|
3285
|
+
let start = end;
|
|
3286
|
+
while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
|
|
3287
|
+
if (start === end && end > 1 && isGrowingDelimiterRow(lines[end - 1] ?? "") && continuesTable((lines[end - 2] ?? "").trimStart())) {
|
|
3288
|
+
start = end - 1;
|
|
3289
|
+
while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
|
|
3290
|
+
}
|
|
3291
|
+
for (let head = start; head < end; head += 1) {
|
|
3292
|
+
if (startsLikeTableRow(lines[head] ?? "")) return head;
|
|
3293
|
+
if (end - head > 1 && isGrowingDelimiterRow(lines[head + 1] ?? "")) return head;
|
|
3294
|
+
}
|
|
3295
|
+
return end;
|
|
3296
|
+
}
|
|
3297
|
+
|
|
2880
3298
|
exports.AFTER_WINDOW = AFTER_WINDOW;
|
|
2881
3299
|
exports.BacktickRuns = BacktickRuns;
|
|
2882
3300
|
exports.CALLOUT_NAMES = CALLOUT_NAMES;
|
|
3301
|
+
exports.DIRECTIVE_CONTAINER_OPEN = DIRECTIVE_CONTAINER_OPEN;
|
|
3302
|
+
exports.DirectiveContainerTracker = DirectiveContainerTracker;
|
|
3303
|
+
exports.FENCE_META_KEY = FENCE_META_KEY;
|
|
2883
3304
|
exports.FENCE_OPENER_WHITESPACE = FENCE_OPENER_WHITESPACE;
|
|
2884
3305
|
exports.FENCE_WHITESPACE = FENCE_WHITESPACE;
|
|
2885
3306
|
exports.FenceReader = FenceReader;
|
|
2886
3307
|
exports.NESTING_FENCE_LANGUAGES = NESTING_FENCE_LANGUAGES;
|
|
2887
3308
|
exports.SourceSpliceError = SourceSpliceError;
|
|
3309
|
+
exports.TITLED_IMAGE_LINE = TITLED_IMAGE_LINE;
|
|
2888
3310
|
exports.XmlContainerTracker = XmlContainerTracker;
|
|
2889
3311
|
exports.blockAt = blockAt;
|
|
2890
3312
|
exports.blockEdit = blockEdit;
|
|
2891
3313
|
exports.blockRangeEdit = blockRangeEdit;
|
|
2892
3314
|
exports.buildCodePointIndex = buildCodePointIndex;
|
|
2893
3315
|
exports.classifyInnerFenceLine = classifyInnerFenceLine;
|
|
3316
|
+
exports.cleanMarkdown = cleanMarkdown;
|
|
2894
3317
|
exports.closeFence = closeFence;
|
|
2895
3318
|
exports.codeSpanText = codeSpanText;
|
|
2896
3319
|
exports.collectLinkDefinitions = collectLinkDefinitions;
|
|
@@ -2899,14 +3322,21 @@ exports.fenceLineKinds = fenceLineKinds;
|
|
|
2899
3322
|
exports.fenceNestsInnerFences = fenceNestsInnerFences;
|
|
2900
3323
|
exports.fenceOpenerOf = fenceOpenerOf;
|
|
2901
3324
|
exports.fenceParts = fenceParts;
|
|
3325
|
+
exports.findBalancedXmlClose = findBalancedXmlClose;
|
|
2902
3326
|
exports.findCodeRanges = findCodeRanges;
|
|
2903
3327
|
exports.findInlineCodeSpans = findInlineCodeSpans;
|
|
2904
3328
|
exports.findLinkDefinitionLines = findLinkDefinitionLines;
|
|
2905
3329
|
exports.findTableEnd = findTableEnd;
|
|
2906
3330
|
exports.findTableStart = findTableStart;
|
|
3331
|
+
exports.findWholeTableStart = findWholeTableStart;
|
|
3332
|
+
exports.hasUnclosedBacktickRun = hasUnclosedBacktickRun;
|
|
3333
|
+
exports.indexOutsideInlineCode = indexOutsideInlineCode;
|
|
3334
|
+
exports.initialXmlBalance = initialXmlBalance;
|
|
2907
3335
|
exports.isEscapedBracketMath = isEscapedBracketMath;
|
|
2908
3336
|
exports.isGfmDelimiterRow = isGfmDelimiterRow;
|
|
3337
|
+
exports.isGrowingDelimiterRow = isGrowingDelimiterRow;
|
|
2909
3338
|
exports.isHtmlBlockTagName = isHtmlBlockTagName;
|
|
3339
|
+
exports.isInsideInlineCode = isInsideInlineCode;
|
|
2910
3340
|
exports.isMathPlaceholder = isMathPlaceholder;
|
|
2911
3341
|
exports.isPipeLedRow = isPipeLedRow;
|
|
2912
3342
|
exports.isSingleDollarMath = isSingleDollarMath;
|
|
@@ -2920,29 +3350,41 @@ exports.mapCodeRanges = mapCodeRanges;
|
|
|
2920
3350
|
exports.mapInlineCodeSpans = mapInlineCodeSpans;
|
|
2921
3351
|
exports.mapPosition = mapPosition;
|
|
2922
3352
|
exports.mapRange = mapRange;
|
|
3353
|
+
exports.markdownToPlainText = markdownToPlainText;
|
|
3354
|
+
exports.mathToReadable = mathToReadable;
|
|
2923
3355
|
exports.normalizeLinkLabel = normalizeLinkLabel;
|
|
2924
3356
|
exports.opensStrippedHtmlBlock = opensStrippedHtmlBlock;
|
|
2925
3357
|
exports.opensTable = opensTable;
|
|
2926
3358
|
exports.pairDisplayMath = pairDisplayMath;
|
|
3359
|
+
exports.parseFenceMeta = parseFenceMeta;
|
|
2927
3360
|
exports.parseFenceOpener = parseFenceOpener;
|
|
3361
|
+
exports.parseLineRanges = parseLineRanges;
|
|
2928
3362
|
exports.pendingCodeSpanStart = pendingCodeSpanStart;
|
|
2929
3363
|
exports.pendingDisplayMathOpener = pendingDisplayMathOpener;
|
|
2930
3364
|
exports.readXmlTag = readXmlTag;
|
|
3365
|
+
exports.removeCodeSpans = removeCodeSpans;
|
|
3366
|
+
exports.replaceFences = replaceFences;
|
|
2931
3367
|
exports.resolveReferenceLinks = resolveReferenceLinks;
|
|
2932
3368
|
exports.rowCells = rowCells;
|
|
2933
3369
|
exports.singleDollarAfter = singleDollarAfter;
|
|
2934
3370
|
exports.singleDollarMathEnd = singleDollarMathEnd;
|
|
3371
|
+
exports.soleFence = soleFence;
|
|
2935
3372
|
exports.spliceSave = spliceSave;
|
|
3373
|
+
exports.splitFenceInfo = splitFenceInfo;
|
|
2936
3374
|
exports.splitRowSegments = splitRowSegments;
|
|
2937
3375
|
exports.splitsSurrogatePair = splitsSurrogatePair;
|
|
2938
3376
|
exports.startsHtmlBlock = startsHtmlBlock;
|
|
3377
|
+
exports.startsLikeTableRow = startsLikeTableRow;
|
|
2939
3378
|
exports.startsPipelessTable = startsPipelessTable;
|
|
2940
3379
|
exports.tableContainerIndent = tableContainerIndent;
|
|
2941
3380
|
exports.tableStartsAt = tableStartsAt;
|
|
2942
3381
|
exports.toCodePointOffset = toCodePointOffset;
|
|
2943
3382
|
exports.toUtf16Offset = toUtf16Offset;
|
|
2944
3383
|
exports.tokenizeSource = tokenizeSource;
|
|
3384
|
+
exports.trailingTableStart = trailingTableStart;
|
|
2945
3385
|
exports.trimFenceLine = trimFenceLine;
|
|
2946
3386
|
exports.unescapeCellPipes = unescapeCellPipes;
|
|
3387
|
+
exports.unwrapCodeSpans = unwrapCodeSpans;
|
|
3388
|
+
exports.unwrapKindEnvelopes = unwrapKindEnvelopes;
|
|
2947
3389
|
//# sourceMappingURL=source.cjs.map
|
|
2948
3390
|
//# sourceMappingURL=source.cjs.map
|