@mintlify/cli 4.0.1474 → 4.0.1475
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/bin/tsconfig.build.tsbuildinfo +1 -1
- package/bin/vendor/converter.js +962 -20
- package/package.json +3 -3
package/bin/vendor/converter.js
CHANGED
|
@@ -1340,13 +1340,22 @@ function convertHtmlCommentsToJsx(mdx) {
|
|
|
1340
1340
|
const parts = mdx.split(/(```[\s\S]*?```|~~~[\s\S]*?~~~)/);
|
|
1341
1341
|
return parts.map((part, i) => i % 2 === 0 ? part.replace(/<!--([\s\S]*?)-->/g, (_m, c) => `{/* ${c} */}`) : part).join("");
|
|
1342
1342
|
}
|
|
1343
|
-
function
|
|
1344
|
-
omitHtmlComments: true
|
|
1345
|
-
}) {
|
|
1343
|
+
function preprocessMdxSource(mdx, options = {}) {
|
|
1346
1344
|
var _a;
|
|
1347
1345
|
const sanitized = ((_a = options.omitHtmlComments) !== null && _a !== void 0 ? _a : true) ? convertHtmlCommentsToJsx(mdx) : mdx;
|
|
1346
|
+
return {
|
|
1347
|
+
sanitized,
|
|
1348
|
+
preprocessed: preprocessCustomHeadingIds(sanitized, { preserveOriginal: true })
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
function parsePreprocessedMdx(preprocessed, options = {}) {
|
|
1348
1352
|
const parser = options.singleDollarTextMath === false ? noSingleDollarTextMathRemark : coreRemark;
|
|
1349
|
-
return parser().parse(
|
|
1353
|
+
return parser().parse(preprocessed);
|
|
1354
|
+
}
|
|
1355
|
+
function mdxToMdast(mdx, options = {
|
|
1356
|
+
omitHtmlComments: true
|
|
1357
|
+
}) {
|
|
1358
|
+
return parsePreprocessedMdx(preprocessMdxSource(mdx, options).preprocessed, options);
|
|
1350
1359
|
}
|
|
1351
1360
|
|
|
1352
1361
|
// ../editor/dist/converter/parse/handlers/prompt.js
|
|
@@ -10370,8 +10379,12 @@ var SerializerState = class {
|
|
|
10370
10379
|
}
|
|
10371
10380
|
/** Escapes special Markdown characters in the input string. */
|
|
10372
10381
|
esc(str2, options = {}) {
|
|
10382
|
+
return this.escRange(str2, 0, str2.length, options);
|
|
10383
|
+
}
|
|
10384
|
+
/** Escapes `str[from, to)` using the whole string as context. */
|
|
10385
|
+
escRange(str2, from, to, options = {}) {
|
|
10373
10386
|
let out = "";
|
|
10374
|
-
for (let i =
|
|
10387
|
+
for (let i = from; i < to; i++) {
|
|
10375
10388
|
const ch = str2[i];
|
|
10376
10389
|
if (this.needsEscape(str2, i, options))
|
|
10377
10390
|
out += "\\";
|
|
@@ -11653,6 +11666,12 @@ function hasReferenceDefinitions(doc) {
|
|
|
11653
11666
|
function pmToMdx(doc, options = {}) {
|
|
11654
11667
|
return serializeDoc(doc, options, null).mdx;
|
|
11655
11668
|
}
|
|
11669
|
+
function serializeNodeWithDelim(node, options, delim) {
|
|
11670
|
+
const state = new SerializerState(options);
|
|
11671
|
+
state.delim = delim;
|
|
11672
|
+
renderNode(state, node, node, 0);
|
|
11673
|
+
return state.out.replace(/(\n[ \t]*)+$/, "");
|
|
11674
|
+
}
|
|
11656
11675
|
function serializeDoc(doc, options, sourceMap) {
|
|
11657
11676
|
var _a;
|
|
11658
11677
|
const { frontmatter } = options, serializerOptions = __rest2(options, ["frontmatter"]);
|
|
@@ -11880,21 +11899,9 @@ function renderNode(state, node, _parent, _index) {
|
|
|
11880
11899
|
}
|
|
11881
11900
|
}
|
|
11882
11901
|
|
|
11883
|
-
// ../editor/dist/converter/serialize/pm-to-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
}
|
|
11887
|
-
|
|
11888
|
-
// ../editor/dist/converter/serialize/mdast-to-mdx.js
|
|
11889
|
-
import remarkGfm3 from "remark-gfm";
|
|
11890
|
-
import remarkMath2 from "remark-math";
|
|
11891
|
-
import remarkMdx3 from "remark-mdx";
|
|
11892
|
-
import remarkStringify2 from "remark-stringify";
|
|
11893
|
-
import { unified as unified2 } from "unified";
|
|
11894
|
-
function mdastToMdx(mdast) {
|
|
11895
|
-
const result = unified2().use(remarkMdx3).use(remarkGfm3).use(remarkMath2).use(remarkStringify2).stringify(mdast);
|
|
11896
|
-
return typeof result === "string" ? result : String(result);
|
|
11897
|
-
}
|
|
11902
|
+
// ../editor/dist/converter/serialize/pm-to-mdx-preserving.js
|
|
11903
|
+
import { Fragment } from "prosemirror-model";
|
|
11904
|
+
import { parse as parseYaml2 } from "yaml";
|
|
11898
11905
|
|
|
11899
11906
|
// ../editor/dist/converter/diff/node-utils.js
|
|
11900
11907
|
var deepEqual = (a, b) => {
|
|
@@ -12063,6 +12070,940 @@ var isCode = (nodeType, schema2) => {
|
|
|
12063
12070
|
return (_a = spec === null || spec === void 0 ? void 0 : spec.spec.code) !== null && _a !== void 0 ? _a : false;
|
|
12064
12071
|
};
|
|
12065
12072
|
|
|
12073
|
+
// ../editor/dist/converter/serialize/pm-to-mdx-preserving.js
|
|
12074
|
+
var __rest3 = function(s, e) {
|
|
12075
|
+
var t = {};
|
|
12076
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
12077
|
+
t[p] = s[p];
|
|
12078
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
12079
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
12080
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
12081
|
+
t[p[i]] = s[p[i]];
|
|
12082
|
+
}
|
|
12083
|
+
return t;
|
|
12084
|
+
};
|
|
12085
|
+
var JSX_HEADING_OPEN = /^\s*<h[1-6] id="/;
|
|
12086
|
+
var JSX_HEADING_CLOSE = /^\s*<\/h[1-6]>$/;
|
|
12087
|
+
var MAX_ALIGNMENT_CELLS = 25e6;
|
|
12088
|
+
var LIST_MARKER = /^([-*+]|(\d+)([.)]))[ \t]+/;
|
|
12089
|
+
var TITLED_TYPES = /* @__PURE__ */ new Set([BLOCK_TYPES.card, BLOCK_TYPES.accordion, BLOCK_TYPES.step]);
|
|
12090
|
+
var LIST_TYPES = /* @__PURE__ */ new Set(["bulletList", "orderedList"]);
|
|
12091
|
+
var JSX_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
12092
|
+
BLOCK_TYPES.callout,
|
|
12093
|
+
BLOCK_TYPES.card,
|
|
12094
|
+
BLOCK_TYPES.accordion,
|
|
12095
|
+
BLOCK_TYPES.accordionGroup,
|
|
12096
|
+
BLOCK_TYPES.step,
|
|
12097
|
+
BLOCK_TYPES.steps,
|
|
12098
|
+
BLOCK_TYPES.tab,
|
|
12099
|
+
BLOCK_TYPES.tabs,
|
|
12100
|
+
BLOCK_TYPES.column,
|
|
12101
|
+
BLOCK_TYPES.columns,
|
|
12102
|
+
BLOCK_TYPES.update,
|
|
12103
|
+
BLOCK_TYPES.frame,
|
|
12104
|
+
BLOCK_TYPES.expandable,
|
|
12105
|
+
BLOCK_TYPES.paramField,
|
|
12106
|
+
BLOCK_TYPES.responseField,
|
|
12107
|
+
BLOCK_TYPES.visibility,
|
|
12108
|
+
BLOCK_TYPES.customComponent,
|
|
12109
|
+
BLOCK_TYPES.codeGroup,
|
|
12110
|
+
BLOCK_TYPES.requestExample,
|
|
12111
|
+
BLOCK_TYPES.responseExample
|
|
12112
|
+
]);
|
|
12113
|
+
function pmToMdxPreservingSource(doc, options) {
|
|
12114
|
+
const { source, parseOptions, onFallback, frontmatter } = options, serializerOptions = __rest3(options, ["source", "parseOptions", "onFallback", "frontmatter"]);
|
|
12115
|
+
const canonicalOptions = Object.assign(Object.assign({}, serializerOptions), { frontmatter });
|
|
12116
|
+
const fallback = (reason, candidate, error) => {
|
|
12117
|
+
onFallback === null || onFallback === void 0 ? void 0 : onFallback(reason, candidate, error);
|
|
12118
|
+
return pmToMdx(doc, canonicalOptions);
|
|
12119
|
+
};
|
|
12120
|
+
try {
|
|
12121
|
+
const preserver = Preserver.create(doc, source, parseOptions !== null && parseOptions !== void 0 ? parseOptions : {}, serializerOptions);
|
|
12122
|
+
if (!preserver)
|
|
12123
|
+
return fallback("unmappable");
|
|
12124
|
+
const out = preserver.run(frontmatter);
|
|
12125
|
+
if (out === null)
|
|
12126
|
+
return fallback("alignment");
|
|
12127
|
+
if (!preserver.roundTrips(out))
|
|
12128
|
+
return fallback("roundtrip", out);
|
|
12129
|
+
return out;
|
|
12130
|
+
} catch (error) {
|
|
12131
|
+
return fallback("error", void 0, error);
|
|
12132
|
+
}
|
|
12133
|
+
}
|
|
12134
|
+
var SourceCoords = class _SourceCoords {
|
|
12135
|
+
constructor(source, preprocessed, lineMap) {
|
|
12136
|
+
this.source = source;
|
|
12137
|
+
this.lineMap = lineMap;
|
|
12138
|
+
this.lineStarts = computeLineStarts(source);
|
|
12139
|
+
this.origLines = source.split("\n");
|
|
12140
|
+
this.preLines = preprocessed.split("\n");
|
|
12141
|
+
}
|
|
12142
|
+
static create(source, sanitized, preprocessed) {
|
|
12143
|
+
const lineMap = buildLineMap(sanitized, preprocessed);
|
|
12144
|
+
return lineMap ? new _SourceCoords(source, preprocessed, lineMap) : null;
|
|
12145
|
+
}
|
|
12146
|
+
lineStart(offset) {
|
|
12147
|
+
return this.source.lastIndexOf("\n", offset - 1) + 1;
|
|
12148
|
+
}
|
|
12149
|
+
lineEnd(line) {
|
|
12150
|
+
return line + 1 < this.lineStarts.length ? this.lineStarts[line + 1] - 1 : this.source.length;
|
|
12151
|
+
}
|
|
12152
|
+
exact(preLine, origLine) {
|
|
12153
|
+
return this.preLines[preLine] === this.origLines[origLine];
|
|
12154
|
+
}
|
|
12155
|
+
span(node) {
|
|
12156
|
+
const position = node.position;
|
|
12157
|
+
if (!position)
|
|
12158
|
+
return null;
|
|
12159
|
+
const startLine = this.lineMap[position.start.line - 1];
|
|
12160
|
+
const endLine = this.lineMap[position.end.line - 1];
|
|
12161
|
+
if (startLine === void 0 || endLine === void 0)
|
|
12162
|
+
return null;
|
|
12163
|
+
const start = this.exact(position.start.line - 1, startLine) ? this.lineStarts[startLine] + position.start.column - 1 : this.lineStarts[startLine];
|
|
12164
|
+
const end = this.exact(position.end.line - 1, endLine) ? this.lineStarts[endLine] + position.end.column - 1 : this.lineEnd(endLine);
|
|
12165
|
+
if (start > end || end > this.source.length)
|
|
12166
|
+
return null;
|
|
12167
|
+
return { start, end };
|
|
12168
|
+
}
|
|
12169
|
+
};
|
|
12170
|
+
var LevelWriter = class {
|
|
12171
|
+
constructor(source, src, frame) {
|
|
12172
|
+
this.source = source;
|
|
12173
|
+
this.src = src;
|
|
12174
|
+
this.frame = frame;
|
|
12175
|
+
this.out = "";
|
|
12176
|
+
this.first = true;
|
|
12177
|
+
this.prevSrc = null;
|
|
12178
|
+
this.prevType = null;
|
|
12179
|
+
}
|
|
12180
|
+
sep(nextSrc, nextType, multilineCanonical) {
|
|
12181
|
+
const { frame } = this;
|
|
12182
|
+
if (this.first) {
|
|
12183
|
+
this.out += frame.open;
|
|
12184
|
+
if (multilineCanonical && frame.kind === "jsx" && !/\n[ \t]*$/.test(frame.open)) {
|
|
12185
|
+
this.out += `
|
|
12186
|
+
${frame.indent}`;
|
|
12187
|
+
}
|
|
12188
|
+
this.first = false;
|
|
12189
|
+
return;
|
|
12190
|
+
}
|
|
12191
|
+
if (nextSrc !== null && this.prevSrc !== null && nextSrc === this.prevSrc + 1) {
|
|
12192
|
+
this.out += this.source.slice(this.src[this.prevSrc].end, this.src[nextSrc].start);
|
|
12193
|
+
return;
|
|
12194
|
+
}
|
|
12195
|
+
const lazy = frame.kind === "item" && frame.sepBody === "\n" && this.prevType === "paragraph" && nextType === "paragraph";
|
|
12196
|
+
this.out += (lazy ? "\n\n" : frame.sepBody) + this.indentFor(nextSrc);
|
|
12197
|
+
}
|
|
12198
|
+
indentFor(srcIndex) {
|
|
12199
|
+
if (srcIndex === null)
|
|
12200
|
+
return this.frame.indent;
|
|
12201
|
+
const start = this.src[srcIndex].start;
|
|
12202
|
+
const prefix = this.source.slice(this.source.lastIndexOf("\n", start - 1) + 1, start);
|
|
12203
|
+
return /^[ \t]*$/.test(prefix) ? prefix : this.frame.indent;
|
|
12204
|
+
}
|
|
12205
|
+
verbatim(index) {
|
|
12206
|
+
var _a, _b, _c, _d;
|
|
12207
|
+
const child = this.src[index];
|
|
12208
|
+
this.sep(index, (_b = (_a = child.node) === null || _a === void 0 ? void 0 : _a.type.name) !== null && _b !== void 0 ? _b : null, false);
|
|
12209
|
+
this.out += this.source.slice(child.start, child.end);
|
|
12210
|
+
this.prevSrc = index;
|
|
12211
|
+
this.prevType = (_d = (_c = child.node) === null || _c === void 0 ? void 0 : _c.type.name) !== null && _d !== void 0 ? _d : null;
|
|
12212
|
+
}
|
|
12213
|
+
recursed(index, text, type2) {
|
|
12214
|
+
this.sep(index, type2, false);
|
|
12215
|
+
this.out += text;
|
|
12216
|
+
this.prevSrc = index;
|
|
12217
|
+
this.prevType = type2;
|
|
12218
|
+
}
|
|
12219
|
+
canonical(text, type2) {
|
|
12220
|
+
this.sep(null, type2, text.includes("\n"));
|
|
12221
|
+
this.out += text;
|
|
12222
|
+
this.prevSrc = null;
|
|
12223
|
+
this.prevType = type2;
|
|
12224
|
+
}
|
|
12225
|
+
raw(text) {
|
|
12226
|
+
this.out += text;
|
|
12227
|
+
this.first = false;
|
|
12228
|
+
this.prevSrc = null;
|
|
12229
|
+
this.prevType = null;
|
|
12230
|
+
}
|
|
12231
|
+
finish() {
|
|
12232
|
+
const { frame } = this;
|
|
12233
|
+
if (this.first) {
|
|
12234
|
+
return frame.kind === "top" ? "" : frame.open.replace(/[ \t]+$/, "") + frame.close;
|
|
12235
|
+
}
|
|
12236
|
+
if (this.src.length > 0 && this.prevSrc === this.src.length - 1) {
|
|
12237
|
+
return this.out + frame.close;
|
|
12238
|
+
}
|
|
12239
|
+
if (frame.kind === "top") {
|
|
12240
|
+
return this.source.endsWith("\n") && !this.out.endsWith("\n") ? `${this.out}
|
|
12241
|
+
` : this.out;
|
|
12242
|
+
}
|
|
12243
|
+
if (!frame.close)
|
|
12244
|
+
return this.out;
|
|
12245
|
+
if (frame.close.startsWith("\n") || !this.out.slice(frame.open.length).includes("\n")) {
|
|
12246
|
+
return this.out + frame.close;
|
|
12247
|
+
}
|
|
12248
|
+
return `${this.out}
|
|
12249
|
+
${frame.containerIndent}${frame.close}`;
|
|
12250
|
+
}
|
|
12251
|
+
};
|
|
12252
|
+
var Preserver = class _Preserver {
|
|
12253
|
+
constructor(doc, coords, root, parseOptions, ser) {
|
|
12254
|
+
this.doc = doc;
|
|
12255
|
+
this.coords = coords;
|
|
12256
|
+
this.root = root;
|
|
12257
|
+
this.parseOptions = parseOptions;
|
|
12258
|
+
this.ser = ser;
|
|
12259
|
+
this.keyIds = /* @__PURE__ */ new Map();
|
|
12260
|
+
this.source = coords.source;
|
|
12261
|
+
this.schema = doc.type.schema;
|
|
12262
|
+
this.emptyParagraph = this.schema.nodes.paragraph.create();
|
|
12263
|
+
}
|
|
12264
|
+
static create(doc, source, parseOptions, serializerOptions) {
|
|
12265
|
+
const { sanitized, preprocessed } = preprocessMdxSource(source, parseOptions);
|
|
12266
|
+
const coords = SourceCoords.create(source, sanitized, preprocessed);
|
|
12267
|
+
if (!coords)
|
|
12268
|
+
return null;
|
|
12269
|
+
const root = parsePreprocessedMdx(preprocessed, parseOptions);
|
|
12270
|
+
const ser = Object.assign(Object.assign({}, serializerOptions), { removeTrailingNewline: true, hasReferenceDefinitions: hasReferenceDefinitions(doc) });
|
|
12271
|
+
return new _Preserver(doc, coords, root, parseOptions, ser);
|
|
12272
|
+
}
|
|
12273
|
+
roundTrips(out) {
|
|
12274
|
+
const reparse = (mdx) => pmToMdx(mdxToPm(mdx, Object.assign(Object.assign({}, this.parseOptions), { schema: this.schema })).doc, this.ser);
|
|
12275
|
+
const canonical = pmToMdx(this.doc, this.ser);
|
|
12276
|
+
const candidate = reparse(out);
|
|
12277
|
+
return candidate === canonical || candidate === reparse(canonical);
|
|
12278
|
+
}
|
|
12279
|
+
run(frontmatter) {
|
|
12280
|
+
const src = this.buildSrcChildren(this.root.children);
|
|
12281
|
+
if (!src)
|
|
12282
|
+
return null;
|
|
12283
|
+
const live = docChildren(this.doc);
|
|
12284
|
+
const canonicalFrontmatter = this.frontmatterText(frontmatter);
|
|
12285
|
+
const omitted = frontmatter === void 0 || canonicalFrontmatter === "";
|
|
12286
|
+
const delta = omitted ? { kind: "rewrite" } : frontmatterDelta(extractFrontmatter(this.root), frontmatter);
|
|
12287
|
+
const top = {
|
|
12288
|
+
omitted,
|
|
12289
|
+
unchanged: delta.kind === "same",
|
|
12290
|
+
appended: delta.kind === "append" ? delta.lines : null,
|
|
12291
|
+
record: frontmatter,
|
|
12292
|
+
canonical: canonicalFrontmatter,
|
|
12293
|
+
hasYaml: src.some((child) => child.mdast.type === "yaml")
|
|
12294
|
+
};
|
|
12295
|
+
if (src.length === 0 && live.length === 0 && top.omitted)
|
|
12296
|
+
return this.source;
|
|
12297
|
+
const frame = {
|
|
12298
|
+
kind: "top",
|
|
12299
|
+
open: src.length > 0 && !(top.omitted && top.hasYaml) ? this.source.slice(0, src[0].start) : "",
|
|
12300
|
+
close: src.length > 0 ? this.source.slice(src[src.length - 1].end) : "",
|
|
12301
|
+
indent: "",
|
|
12302
|
+
containerIndent: "",
|
|
12303
|
+
sepBody: "\n\n",
|
|
12304
|
+
list: null
|
|
12305
|
+
};
|
|
12306
|
+
return this.emitLevel({ outerOpen: "", innerOpen: "", close: "", chain: [] }, live, src, frame, top);
|
|
12307
|
+
}
|
|
12308
|
+
frontmatterText(frontmatter) {
|
|
12309
|
+
const emptyDoc = this.schema.topNodeType.createAndFill();
|
|
12310
|
+
if (!emptyDoc)
|
|
12311
|
+
return "";
|
|
12312
|
+
return pmToMdx(emptyDoc, Object.assign(Object.assign({}, this.ser), { frontmatter }));
|
|
12313
|
+
}
|
|
12314
|
+
keyOf(node) {
|
|
12315
|
+
const key = blockKey(node, this.ser);
|
|
12316
|
+
let id = this.keyIds.get(key);
|
|
12317
|
+
if (id === void 0) {
|
|
12318
|
+
id = this.keyIds.size;
|
|
12319
|
+
this.keyIds.set(key, id);
|
|
12320
|
+
}
|
|
12321
|
+
return id;
|
|
12322
|
+
}
|
|
12323
|
+
buildSrcChildren(nodes2) {
|
|
12324
|
+
const children = [];
|
|
12325
|
+
for (const mdast of nodes2) {
|
|
12326
|
+
for (const part of promotedElements(mdast)) {
|
|
12327
|
+
const span = this.coords.span(part);
|
|
12328
|
+
if (!span)
|
|
12329
|
+
return null;
|
|
12330
|
+
children.push({
|
|
12331
|
+
mdast: part,
|
|
12332
|
+
start: span.start,
|
|
12333
|
+
end: span.end,
|
|
12334
|
+
keys: null,
|
|
12335
|
+
node: null,
|
|
12336
|
+
nodes: null
|
|
12337
|
+
});
|
|
12338
|
+
}
|
|
12339
|
+
}
|
|
12340
|
+
return children;
|
|
12341
|
+
}
|
|
12342
|
+
linePrefix(offset) {
|
|
12343
|
+
return this.source.slice(this.coords.lineStart(offset), offset);
|
|
12344
|
+
}
|
|
12345
|
+
wrapperOpen(level, start, first) {
|
|
12346
|
+
const prefix = this.linePrefix(start);
|
|
12347
|
+
const combined = level.outerOpen + level.innerOpen;
|
|
12348
|
+
if (!/^[ \t]*$/.test(prefix))
|
|
12349
|
+
return combined;
|
|
12350
|
+
if (/^[ \t]*$/.test(combined))
|
|
12351
|
+
return prefix;
|
|
12352
|
+
if (first)
|
|
12353
|
+
return combined;
|
|
12354
|
+
const newline = combined.lastIndexOf("\n");
|
|
12355
|
+
const tail = combined.slice(newline + 1);
|
|
12356
|
+
return /^[ \t]*$/.test(tail) ? combined.slice(0, newline + 1) + prefix : `${combined.trimEnd()}
|
|
12357
|
+
${prefix}`;
|
|
12358
|
+
}
|
|
12359
|
+
parseInContext(level, start, end, first) {
|
|
12360
|
+
return this.parseText(level, this.source.slice(start, end), start, first);
|
|
12361
|
+
}
|
|
12362
|
+
parseText(level, text, start, first) {
|
|
12363
|
+
let parsed;
|
|
12364
|
+
try {
|
|
12365
|
+
const wrapped = this.wrapperOpen(level, start, first) + text + level.close;
|
|
12366
|
+
parsed = mdxToPm(wrapped, Object.assign(Object.assign({}, this.parseOptions), { schema: this.schema })).doc;
|
|
12367
|
+
} catch (_a) {
|
|
12368
|
+
return null;
|
|
12369
|
+
}
|
|
12370
|
+
let current = parsed;
|
|
12371
|
+
for (const type2 of level.chain) {
|
|
12372
|
+
const kids = contentChildren(current);
|
|
12373
|
+
if (kids.length !== 1 || kids[0].type.name !== type2)
|
|
12374
|
+
return null;
|
|
12375
|
+
current = kids[0];
|
|
12376
|
+
}
|
|
12377
|
+
return contentChildren(current);
|
|
12378
|
+
}
|
|
12379
|
+
fillKeys(level, child, first) {
|
|
12380
|
+
if (child.mdast.type === "yaml")
|
|
12381
|
+
return;
|
|
12382
|
+
const nodes2 = this.parseInContext(level, child.start, child.end, first);
|
|
12383
|
+
child.keys = nodes2 ? nodes2.map((node) => this.keyOf(node)) : null;
|
|
12384
|
+
child.node = nodes2 && nodes2.length === 1 ? nodes2[0] : null;
|
|
12385
|
+
child.nodes = nodes2;
|
|
12386
|
+
}
|
|
12387
|
+
coalesce(level, src, matches) {
|
|
12388
|
+
var _a, _b;
|
|
12389
|
+
let merged = false;
|
|
12390
|
+
for (let i = src.length - 2; i >= 0; i--) {
|
|
12391
|
+
const a = src[i];
|
|
12392
|
+
const b = src[i + 1];
|
|
12393
|
+
if (!((_a = a.keys) === null || _a === void 0 ? void 0 : _a.length) || !((_b = b.keys) === null || _b === void 0 ? void 0 : _b.length))
|
|
12394
|
+
continue;
|
|
12395
|
+
if (matches[i] !== null || matches[i + 1] !== null)
|
|
12396
|
+
continue;
|
|
12397
|
+
const nodes2 = this.parseInContext(level, a.start, b.end, i === 0);
|
|
12398
|
+
if (!nodes2)
|
|
12399
|
+
continue;
|
|
12400
|
+
const keys = nodes2.map((node) => this.keyOf(node));
|
|
12401
|
+
if (sameKeys(keys, [...a.keys, ...b.keys]))
|
|
12402
|
+
continue;
|
|
12403
|
+
src.splice(i, 2, {
|
|
12404
|
+
mdast: a.mdast,
|
|
12405
|
+
start: a.start,
|
|
12406
|
+
end: b.end,
|
|
12407
|
+
keys,
|
|
12408
|
+
node: nodes2.length === 1 ? nodes2[0] : null,
|
|
12409
|
+
nodes: nodes2
|
|
12410
|
+
});
|
|
12411
|
+
merged = true;
|
|
12412
|
+
}
|
|
12413
|
+
return merged;
|
|
12414
|
+
}
|
|
12415
|
+
emitLevel(level, live, src, frame, top) {
|
|
12416
|
+
const liveKeys = live.map((node) => this.keyOf(node));
|
|
12417
|
+
src.forEach((child, index) => this.fillKeys(level, child, index === 0));
|
|
12418
|
+
let matches = alignChildren(src, liveKeys);
|
|
12419
|
+
if (!matches)
|
|
12420
|
+
return null;
|
|
12421
|
+
if (this.coalesce(level, src, matches)) {
|
|
12422
|
+
matches = alignChildren(src, liveKeys);
|
|
12423
|
+
if (!matches)
|
|
12424
|
+
return null;
|
|
12425
|
+
}
|
|
12426
|
+
rejectUnequalMatches(src, live, matches);
|
|
12427
|
+
const writer = new LevelWriter(this.source, src, frame);
|
|
12428
|
+
const pending = [];
|
|
12429
|
+
let liveIndex = 0;
|
|
12430
|
+
const flushZeroKeys = (upTo) => {
|
|
12431
|
+
var _a;
|
|
12432
|
+
for (let p = 0; p < upTo; p++) {
|
|
12433
|
+
const index = pending[p];
|
|
12434
|
+
if (((_a = src[index].keys) === null || _a === void 0 ? void 0 : _a.length) === 0)
|
|
12435
|
+
writer.verbatim(index);
|
|
12436
|
+
}
|
|
12437
|
+
};
|
|
12438
|
+
const emitLive = (node) => {
|
|
12439
|
+
var _a;
|
|
12440
|
+
const type2 = node.type.name;
|
|
12441
|
+
const pairAt = pending.findIndex((index2) => {
|
|
12442
|
+
var _a2;
|
|
12443
|
+
const child = src[index2];
|
|
12444
|
+
return child.keys !== null && child.keys.length > 0 && ((_a2 = child.node) === null || _a2 === void 0 ? void 0 : _a2.type.name) === type2;
|
|
12445
|
+
});
|
|
12446
|
+
if (pairAt === -1) {
|
|
12447
|
+
writer.canonical(this.renderCanonical(node, liveIndex, frame), type2);
|
|
12448
|
+
return;
|
|
12449
|
+
}
|
|
12450
|
+
flushZeroKeys(pairAt);
|
|
12451
|
+
const index = pending[pairAt];
|
|
12452
|
+
pending.splice(0, pairAt + 1);
|
|
12453
|
+
const localized = (_a = this.tryRecurse(level, node, src[index], frame)) !== null && _a !== void 0 ? _a : this.tryPatchParagraph(level, node, src[index], index === 0);
|
|
12454
|
+
if (localized !== null)
|
|
12455
|
+
writer.recursed(index, localized, type2);
|
|
12456
|
+
else
|
|
12457
|
+
writer.canonical(this.renderCanonical(node, liveIndex, frame), type2);
|
|
12458
|
+
};
|
|
12459
|
+
const flushLive = (to) => {
|
|
12460
|
+
while (liveIndex < to) {
|
|
12461
|
+
emitLive(live[liveIndex]);
|
|
12462
|
+
liveIndex++;
|
|
12463
|
+
}
|
|
12464
|
+
};
|
|
12465
|
+
const flushPending = () => {
|
|
12466
|
+
flushZeroKeys(pending.length);
|
|
12467
|
+
pending.length = 0;
|
|
12468
|
+
};
|
|
12469
|
+
if (top && !top.omitted && !top.hasYaml)
|
|
12470
|
+
writer.raw(top.canonical);
|
|
12471
|
+
for (let i = 0; i < src.length; i++) {
|
|
12472
|
+
const child = src[i];
|
|
12473
|
+
if (child.mdast.type === "yaml") {
|
|
12474
|
+
if (!top)
|
|
12475
|
+
return null;
|
|
12476
|
+
const appended = top.appended === null ? null : verifiedYamlAppend(this.source.slice(child.start, child.end), top.appended, top.record);
|
|
12477
|
+
if (top.unchanged)
|
|
12478
|
+
writer.verbatim(i);
|
|
12479
|
+
else if (appended !== null)
|
|
12480
|
+
writer.recursed(i, appended, "yaml");
|
|
12481
|
+
else if (!top.omitted)
|
|
12482
|
+
writer.raw(top.canonical);
|
|
12483
|
+
continue;
|
|
12484
|
+
}
|
|
12485
|
+
const match = matches[i];
|
|
12486
|
+
if (match !== null && match !== void 0) {
|
|
12487
|
+
flushLive(match);
|
|
12488
|
+
flushPending();
|
|
12489
|
+
liveIndex = match + child.keys.length;
|
|
12490
|
+
writer.verbatim(i);
|
|
12491
|
+
continue;
|
|
12492
|
+
}
|
|
12493
|
+
pending.push(i);
|
|
12494
|
+
}
|
|
12495
|
+
flushLive(live.length);
|
|
12496
|
+
flushPending();
|
|
12497
|
+
return writer.finish();
|
|
12498
|
+
}
|
|
12499
|
+
tryRecurse(level, live, child, frame) {
|
|
12500
|
+
var _a;
|
|
12501
|
+
const base = child.node;
|
|
12502
|
+
if (!base || base.type.name !== live.type.name)
|
|
12503
|
+
return null;
|
|
12504
|
+
const type2 = live.type.name;
|
|
12505
|
+
if (type2 === "table")
|
|
12506
|
+
return this.emitTable(live, child);
|
|
12507
|
+
if (!JSX_CONTAINER_TYPES.has(type2) && !LIST_TYPES.has(type2) && type2 !== "listItem")
|
|
12508
|
+
return null;
|
|
12509
|
+
if (type2 === BLOCK_TYPES.customComponent && live.attrs.name === "CodeBlock")
|
|
12510
|
+
return null;
|
|
12511
|
+
const kind = LIST_TYPES.has(type2) ? "list" : type2 === "listItem" ? "item" : "jsx";
|
|
12512
|
+
const element = kind === "jsx" ? this.resolveElement(child) : child;
|
|
12513
|
+
if (!element)
|
|
12514
|
+
return null;
|
|
12515
|
+
const mdastKids = element.mdast.children;
|
|
12516
|
+
if (!mdastKids || mdastKids.length === 0)
|
|
12517
|
+
return null;
|
|
12518
|
+
const srcKids = this.buildSrcChildren(mdastKids);
|
|
12519
|
+
if (!srcKids)
|
|
12520
|
+
return null;
|
|
12521
|
+
const first = srcKids[0];
|
|
12522
|
+
const last = srcKids[srcKids.length - 1];
|
|
12523
|
+
if (first.start < element.start || last.end > element.end)
|
|
12524
|
+
return null;
|
|
12525
|
+
let open = this.source.slice(element.start, first.start);
|
|
12526
|
+
const close = this.source.slice(last.end, element.end);
|
|
12527
|
+
if (this.shellKey(base) === this.shellKey(live)) {
|
|
12528
|
+
if (!sameNode(this.hollow(base), this.hollow(live)))
|
|
12529
|
+
return null;
|
|
12530
|
+
} else {
|
|
12531
|
+
if (kind !== "jsx")
|
|
12532
|
+
return null;
|
|
12533
|
+
const tagLine = blockKey(this.hollow(live), this.ser).split("\n")[0];
|
|
12534
|
+
const firstLine = open.split("\n")[0];
|
|
12535
|
+
if (!tagLine.endsWith(">") || !/>[ \t]*$/.test(firstLine) || firstLine.slice(1).includes("<")) {
|
|
12536
|
+
return null;
|
|
12537
|
+
}
|
|
12538
|
+
open = tagLine + open.slice(firstLine.trimEnd().length);
|
|
12539
|
+
}
|
|
12540
|
+
const prefix = this.linePrefix(first.start);
|
|
12541
|
+
const containerLine = this.linePrefix(element.start);
|
|
12542
|
+
const list = kind === "list" ? this.listMarker(live, srcKids) : null;
|
|
12543
|
+
if (kind === "list" && !list)
|
|
12544
|
+
return null;
|
|
12545
|
+
const containerIndent = /^[ \t]*$/.test(containerLine) ? containerLine : frame.indent;
|
|
12546
|
+
const continuation = kind === "item" ? this.continuationIndent([element]) : null;
|
|
12547
|
+
const childFrame = {
|
|
12548
|
+
kind,
|
|
12549
|
+
open,
|
|
12550
|
+
close,
|
|
12551
|
+
indent: continuation !== null && continuation !== void 0 ? continuation : kind === "jsx" && !/^[ \t]*$/.test(prefix) ? containerIndent + " ".repeat((_a = this.ser.indentSize) !== null && _a !== void 0 ? _a : 2) : prefix.replace(/\S/g, " "),
|
|
12552
|
+
containerIndent,
|
|
12553
|
+
sepBody: this.separatorBody(srcKids, kind),
|
|
12554
|
+
list
|
|
12555
|
+
};
|
|
12556
|
+
const childLevel = {
|
|
12557
|
+
outerOpen: level.outerOpen + level.innerOpen,
|
|
12558
|
+
innerOpen: open,
|
|
12559
|
+
close: close + level.close,
|
|
12560
|
+
chain: [...level.chain, type2]
|
|
12561
|
+
};
|
|
12562
|
+
return this.emitLevel(childLevel, contentChildren(live), srcKids, childFrame, null);
|
|
12563
|
+
}
|
|
12564
|
+
tryPatchParagraph(level, live, child, first) {
|
|
12565
|
+
const base = child.node;
|
|
12566
|
+
if (!base || live.type.name !== "paragraph" || base.type.name !== "paragraph")
|
|
12567
|
+
return null;
|
|
12568
|
+
if (child.mdast.type !== "paragraph" || base.childCount !== live.childCount)
|
|
12569
|
+
return null;
|
|
12570
|
+
let changed = -1;
|
|
12571
|
+
for (let i = 0; i < live.childCount; i++) {
|
|
12572
|
+
const before2 = base.child(i);
|
|
12573
|
+
const after2 = live.child(i);
|
|
12574
|
+
if (before2.eq(after2))
|
|
12575
|
+
continue;
|
|
12576
|
+
if (changed !== -1 || !before2.isText || !after2.isText || !before2.sameMarkup(after2)) {
|
|
12577
|
+
return null;
|
|
12578
|
+
}
|
|
12579
|
+
changed = i;
|
|
12580
|
+
}
|
|
12581
|
+
if (changed === -1)
|
|
12582
|
+
return null;
|
|
12583
|
+
const liveText = live.child(changed);
|
|
12584
|
+
if (liveText.marks.some((mark) => mark.type.name === "code" || mark.type.name === "link")) {
|
|
12585
|
+
return null;
|
|
12586
|
+
}
|
|
12587
|
+
const leaves = inlineLeaves(child.mdast.children);
|
|
12588
|
+
const leaf = leaves[changed];
|
|
12589
|
+
if (leaves.length !== base.childCount || (leaf === null || leaf === void 0 ? void 0 : leaf.type) !== "text")
|
|
12590
|
+
return null;
|
|
12591
|
+
const span = this.coords.span(leaf);
|
|
12592
|
+
if (!span || span.start < child.start || span.end > child.end)
|
|
12593
|
+
return null;
|
|
12594
|
+
const before = base.child(changed).text;
|
|
12595
|
+
const after = liveText.text;
|
|
12596
|
+
const offsets = mapTextToSource(this.source, span.start, span.end, before);
|
|
12597
|
+
if (!offsets)
|
|
12598
|
+
return null;
|
|
12599
|
+
let prefix = 0;
|
|
12600
|
+
while (prefix < before.length && prefix < after.length && before[prefix] === after[prefix]) {
|
|
12601
|
+
prefix++;
|
|
12602
|
+
}
|
|
12603
|
+
let suffix = 0;
|
|
12604
|
+
while (suffix < before.length - prefix && suffix < after.length - prefix && before[before.length - 1 - suffix] === after[after.length - 1 - suffix]) {
|
|
12605
|
+
suffix++;
|
|
12606
|
+
}
|
|
12607
|
+
const segment = new SerializerState(this.ser).escRange(after, prefix, after.length - suffix);
|
|
12608
|
+
const patched = this.source.slice(child.start, offsets[prefix]) + segment + this.source.slice(offsets[before.length - suffix], child.end);
|
|
12609
|
+
const nodes2 = this.parseText(level, patched, child.start, first);
|
|
12610
|
+
if (!nodes2 || nodes2.length !== 1 || !sameNode(nodes2[0], live))
|
|
12611
|
+
return null;
|
|
12612
|
+
return patched;
|
|
12613
|
+
}
|
|
12614
|
+
resolveElement(child) {
|
|
12615
|
+
if (child.mdast.type === "mdxJsxFlowElement" || child.mdast.type === "mdxJsxTextElement") {
|
|
12616
|
+
return child;
|
|
12617
|
+
}
|
|
12618
|
+
if (child.mdast.type !== "paragraph")
|
|
12619
|
+
return null;
|
|
12620
|
+
const inline = child.mdast.children.filter((node) => !(node.type === "text" && node.value.trim() === ""));
|
|
12621
|
+
const element = inline[0];
|
|
12622
|
+
if (inline.length !== 1 || (element === null || element === void 0 ? void 0 : element.type) !== "mdxJsxTextElement")
|
|
12623
|
+
return null;
|
|
12624
|
+
const span = this.coords.span(element);
|
|
12625
|
+
if (!span)
|
|
12626
|
+
return null;
|
|
12627
|
+
return Object.assign(Object.assign({ mdast: element }, span), { keys: child.keys, node: child.node, nodes: child.nodes });
|
|
12628
|
+
}
|
|
12629
|
+
separatorBody(srcKids, kind) {
|
|
12630
|
+
var _a, _b;
|
|
12631
|
+
if (srcKids.length >= 2) {
|
|
12632
|
+
const between = this.source.slice(srcKids[0].end, srcKids[1].start);
|
|
12633
|
+
const newlines = (_b = (_a = between.match(/\n/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
12634
|
+
if (newlines >= 1)
|
|
12635
|
+
return newlines >= 2 ? "\n\n" : "\n";
|
|
12636
|
+
}
|
|
12637
|
+
return kind === "list" || kind === "item" ? "\n" : "\n\n";
|
|
12638
|
+
}
|
|
12639
|
+
listMarker(live, items) {
|
|
12640
|
+
const ordered = live.type.name === "orderedList";
|
|
12641
|
+
const numbers = [];
|
|
12642
|
+
let delimiter = ordered ? "." : "-";
|
|
12643
|
+
for (const item of items) {
|
|
12644
|
+
const match = LIST_MARKER.exec(this.source.slice(item.start, item.start + 12));
|
|
12645
|
+
if (!match)
|
|
12646
|
+
continue;
|
|
12647
|
+
if (ordered !== (match[2] !== void 0))
|
|
12648
|
+
return null;
|
|
12649
|
+
delimiter = ordered ? match[3] : match[1];
|
|
12650
|
+
if (ordered)
|
|
12651
|
+
numbers.push(Number(match[2]));
|
|
12652
|
+
}
|
|
12653
|
+
const fixedNumber = ordered && numbers.length >= 2 && numbers.every((n) => n === numbers[0]) ? numbers[0] : null;
|
|
12654
|
+
return {
|
|
12655
|
+
ordered,
|
|
12656
|
+
start: live.attrs.start || 1,
|
|
12657
|
+
delimiter,
|
|
12658
|
+
fixedNumber,
|
|
12659
|
+
contentIndent: this.continuationIndent(items)
|
|
12660
|
+
};
|
|
12661
|
+
}
|
|
12662
|
+
continuationIndent(items) {
|
|
12663
|
+
for (const item of items) {
|
|
12664
|
+
const kids = item.mdast.children;
|
|
12665
|
+
if (!kids || kids.length < 2)
|
|
12666
|
+
continue;
|
|
12667
|
+
const span = this.coords.span(kids[1]);
|
|
12668
|
+
if (!span || this.coords.lineStart(span.start) <= item.start)
|
|
12669
|
+
continue;
|
|
12670
|
+
const prefix = this.linePrefix(span.start);
|
|
12671
|
+
if (/^[ \t]*$/.test(prefix))
|
|
12672
|
+
return prefix;
|
|
12673
|
+
}
|
|
12674
|
+
return null;
|
|
12675
|
+
}
|
|
12676
|
+
renderCanonical(node, liveIndex, frame) {
|
|
12677
|
+
var _a;
|
|
12678
|
+
if (!frame.list)
|
|
12679
|
+
return serializeNodeWithDelim(node, this.ser, frame.indent);
|
|
12680
|
+
const { list } = frame;
|
|
12681
|
+
const number = (_a = list.fixedNumber) !== null && _a !== void 0 ? _a : list.start + liveIndex;
|
|
12682
|
+
const checked = node.attrs.checked;
|
|
12683
|
+
const task = checked == null ? "" : checked ? "[x] " : "[ ] ";
|
|
12684
|
+
const prefix = (list.ordered ? `${number}${list.delimiter} ` : `${list.delimiter} `) + task;
|
|
12685
|
+
const fallbackIndent = frame.indent + " ".repeat(prefix.length);
|
|
12686
|
+
const delim = list.contentIndent && list.contentIndent.length >= fallbackIndent.length ? list.contentIndent : fallbackIndent;
|
|
12687
|
+
const body = serializeNodeWithDelim(node, this.ser, delim);
|
|
12688
|
+
return prefix + body;
|
|
12689
|
+
}
|
|
12690
|
+
emitTable(live, child) {
|
|
12691
|
+
var _a;
|
|
12692
|
+
const base = child.node;
|
|
12693
|
+
const rows = child.mdast.children;
|
|
12694
|
+
if (!rows || rows.length === 0 || rows.length !== base.childCount || live.childCount === 0) {
|
|
12695
|
+
return null;
|
|
12696
|
+
}
|
|
12697
|
+
const srcRows = this.buildSrcChildren(rows);
|
|
12698
|
+
if (!srcRows)
|
|
12699
|
+
return null;
|
|
12700
|
+
const columns = base.child(0).childCount;
|
|
12701
|
+
for (let i = 0; i < live.childCount; i++) {
|
|
12702
|
+
if (live.child(i).childCount !== columns)
|
|
12703
|
+
return null;
|
|
12704
|
+
}
|
|
12705
|
+
const rowKey = (row) => this.keyOf(live.type.create(null, [row]));
|
|
12706
|
+
srcRows.forEach((row, i) => {
|
|
12707
|
+
row.keys = [rowKey(base.child(i))];
|
|
12708
|
+
});
|
|
12709
|
+
const liveRows = docChildren(live);
|
|
12710
|
+
const liveKeys = liveRows.map(rowKey);
|
|
12711
|
+
const matches = alignChildren(srcRows, liveKeys);
|
|
12712
|
+
if (!matches || matches[0] !== 0 && matches[0] !== null)
|
|
12713
|
+
return null;
|
|
12714
|
+
matches.forEach((liveAt, srcAt) => {
|
|
12715
|
+
if (liveAt !== null && !sameNode(base.child(srcAt), liveRows[liveAt]))
|
|
12716
|
+
matches[srcAt] = null;
|
|
12717
|
+
});
|
|
12718
|
+
const liveToSrc = /* @__PURE__ */ new Map();
|
|
12719
|
+
matches.forEach((liveAt, srcAt) => {
|
|
12720
|
+
if (liveAt !== null)
|
|
12721
|
+
liveToSrc.set(liveAt, srcAt);
|
|
12722
|
+
});
|
|
12723
|
+
if (matches[0] === null && liveToSrc.has(0))
|
|
12724
|
+
return null;
|
|
12725
|
+
const header = srcRows[0];
|
|
12726
|
+
const indent = this.linePrefix(header.start).replace(/\S/g, " ");
|
|
12727
|
+
const afterHeader = this.source.slice(header.end, srcRows.length >= 2 ? srcRows[1].start : child.end);
|
|
12728
|
+
const delimiter = (_a = /^\n[^\n]*/.exec(afterHeader)) === null || _a === void 0 ? void 0 : _a[0];
|
|
12729
|
+
if (!delimiter)
|
|
12730
|
+
return null;
|
|
12731
|
+
const afterDelimiter = header.end + delimiter.length;
|
|
12732
|
+
let out = this.source.slice(child.start, header.start);
|
|
12733
|
+
if (matches[0] === 0) {
|
|
12734
|
+
out += this.source.slice(header.start, header.end) + delimiter;
|
|
12735
|
+
} else {
|
|
12736
|
+
const canonicalHeader = blockKey(live.type.create(null, [liveRows[0]]), this.ser);
|
|
12737
|
+
out += canonicalHeader.split("\n").slice(0, 2).join(`
|
|
12738
|
+
${indent}`);
|
|
12739
|
+
}
|
|
12740
|
+
let prevSrc = null;
|
|
12741
|
+
for (let k = 1; k < liveRows.length; k++) {
|
|
12742
|
+
const srcAt = liveToSrc.get(k);
|
|
12743
|
+
if (srcAt !== void 0 && k === 1 && srcAt === 1) {
|
|
12744
|
+
out += this.source.slice(afterDelimiter, srcRows[1].start);
|
|
12745
|
+
} else if (srcAt !== void 0 && prevSrc !== null && srcAt === prevSrc + 1) {
|
|
12746
|
+
out += this.source.slice(srcRows[prevSrc].end, srcRows[srcAt].start);
|
|
12747
|
+
} else {
|
|
12748
|
+
out += `
|
|
12749
|
+
${indent}`;
|
|
12750
|
+
}
|
|
12751
|
+
if (srcAt !== void 0) {
|
|
12752
|
+
out += this.source.slice(srcRows[srcAt].start, srcRows[srcAt].end);
|
|
12753
|
+
prevSrc = srcAt;
|
|
12754
|
+
} else {
|
|
12755
|
+
out += blockKey(live.type.create(null, [liveRows[k]]), this.ser).split("\n")[0];
|
|
12756
|
+
prevSrc = null;
|
|
12757
|
+
}
|
|
12758
|
+
}
|
|
12759
|
+
if (srcRows.length >= 2 && prevSrc === srcRows.length - 1) {
|
|
12760
|
+
out += this.source.slice(srcRows[prevSrc].end, child.end);
|
|
12761
|
+
}
|
|
12762
|
+
return out;
|
|
12763
|
+
}
|
|
12764
|
+
shellKey(node) {
|
|
12765
|
+
const type2 = node.type.name;
|
|
12766
|
+
const attrs2 = LIST_TYPES.has(type2) || type2 === "listItem" ? JSON.stringify(node.attrs) : "";
|
|
12767
|
+
return `${type2}|${attrs2}|${blockKey(this.hollow(node), this.ser)}`;
|
|
12768
|
+
}
|
|
12769
|
+
hollow(node) {
|
|
12770
|
+
const type2 = node.type.name;
|
|
12771
|
+
if (TITLED_TYPES.has(type2) && node.childCount >= 2) {
|
|
12772
|
+
return node.copy(Fragment.from([node.child(0), node.child(1).copy(Fragment.from(this.emptyParagraph))]));
|
|
12773
|
+
}
|
|
12774
|
+
if (LIST_TYPES.has(type2)) {
|
|
12775
|
+
const item = this.schema.nodes.listItem.create(null, this.emptyParagraph);
|
|
12776
|
+
return node.copy(Fragment.from(item));
|
|
12777
|
+
}
|
|
12778
|
+
return node.copy(Fragment.from(this.emptyParagraph));
|
|
12779
|
+
}
|
|
12780
|
+
};
|
|
12781
|
+
function docChildren(node) {
|
|
12782
|
+
const children = [];
|
|
12783
|
+
node.forEach((child) => children.push(child));
|
|
12784
|
+
return children;
|
|
12785
|
+
}
|
|
12786
|
+
function contentChildren(node) {
|
|
12787
|
+
if (TITLED_TYPES.has(node.type.name)) {
|
|
12788
|
+
return node.childCount >= 2 ? docChildren(node.child(1)) : [];
|
|
12789
|
+
}
|
|
12790
|
+
return docChildren(node);
|
|
12791
|
+
}
|
|
12792
|
+
function sameKeys(a, b) {
|
|
12793
|
+
return a.length === b.length && a.every((key, i) => key === b[i]);
|
|
12794
|
+
}
|
|
12795
|
+
function frontmatterLines(record) {
|
|
12796
|
+
return new Map(Object.entries(filterFrontmatterRecord(record)).map(([key, value]) => [
|
|
12797
|
+
key,
|
|
12798
|
+
formatFrontmatterValue(key, value)
|
|
12799
|
+
]));
|
|
12800
|
+
}
|
|
12801
|
+
function frontmatterDelta(original, next) {
|
|
12802
|
+
const before = frontmatterLines(original);
|
|
12803
|
+
const after = frontmatterLines(next);
|
|
12804
|
+
for (const [key, line] of before) {
|
|
12805
|
+
if (after.get(key) !== line)
|
|
12806
|
+
return { kind: "rewrite" };
|
|
12807
|
+
}
|
|
12808
|
+
const added = [...after].filter(([key]) => !before.has(key)).map(([, line]) => line);
|
|
12809
|
+
return added.length === 0 ? { kind: "same" } : { kind: "append", lines: added.join("\n") };
|
|
12810
|
+
}
|
|
12811
|
+
function appendYamlLines(yaml2, lines) {
|
|
12812
|
+
const fence = /(\r?\n)---[ \t]*$/.exec(yaml2);
|
|
12813
|
+
if (!fence)
|
|
12814
|
+
return null;
|
|
12815
|
+
const newline = fence[1];
|
|
12816
|
+
return `${yaml2.slice(0, fence.index)}${newline}${lines.replace(/\n/g, newline)}${yaml2.slice(fence.index)}`;
|
|
12817
|
+
}
|
|
12818
|
+
function verifiedYamlAppend(yaml2, lines, record) {
|
|
12819
|
+
var _a;
|
|
12820
|
+
const appended = appendYamlLines(yaml2, lines);
|
|
12821
|
+
if (appended === null || record === void 0)
|
|
12822
|
+
return null;
|
|
12823
|
+
const body = (_a = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*$/.exec(appended)) === null || _a === void 0 ? void 0 : _a[1];
|
|
12824
|
+
if (body === void 0)
|
|
12825
|
+
return null;
|
|
12826
|
+
let parsed;
|
|
12827
|
+
try {
|
|
12828
|
+
parsed = parseYaml2(body);
|
|
12829
|
+
} catch (_b) {
|
|
12830
|
+
return null;
|
|
12831
|
+
}
|
|
12832
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
12833
|
+
return null;
|
|
12834
|
+
const before = frontmatterLines(parsed);
|
|
12835
|
+
const after = frontmatterLines(record);
|
|
12836
|
+
if (before.size !== after.size)
|
|
12837
|
+
return null;
|
|
12838
|
+
for (const [key, line] of after) {
|
|
12839
|
+
if (before.get(key) !== line)
|
|
12840
|
+
return null;
|
|
12841
|
+
}
|
|
12842
|
+
return appended;
|
|
12843
|
+
}
|
|
12844
|
+
function rejectUnequalMatches(src, live, matches) {
|
|
12845
|
+
matches.forEach((at, i) => {
|
|
12846
|
+
if (at === null)
|
|
12847
|
+
return;
|
|
12848
|
+
const nodes2 = src[i].nodes;
|
|
12849
|
+
if (!nodes2 || nodes2.some((node, k) => !sameNode(node, live[at + k])))
|
|
12850
|
+
matches[i] = null;
|
|
12851
|
+
});
|
|
12852
|
+
}
|
|
12853
|
+
function sameNode(a, b) {
|
|
12854
|
+
return a.eq(b) || deepEqual(a.toJSON(), b.toJSON());
|
|
12855
|
+
}
|
|
12856
|
+
function promotedElements(mdast) {
|
|
12857
|
+
if (mdast.type !== "paragraph")
|
|
12858
|
+
return [mdast];
|
|
12859
|
+
const elements = mdast.children.filter((node) => !(node.type === "text" && node.value.trim() === ""));
|
|
12860
|
+
const promotable = elements.length > 0 && elements.every((node) => node.type === "mdxJsxTextElement" && isBlockName(node.name));
|
|
12861
|
+
return promotable ? elements : [mdast];
|
|
12862
|
+
}
|
|
12863
|
+
var MARK_CONTAINERS = /* @__PURE__ */ new Set(["emphasis", "strong", "delete", "link"]);
|
|
12864
|
+
var MARK_ELEMENTS = /* @__PURE__ */ new Set(["u", "sub", "sup"]);
|
|
12865
|
+
function inlineLeaves(nodes2) {
|
|
12866
|
+
const leaves = [];
|
|
12867
|
+
for (const node of nodes2) {
|
|
12868
|
+
if (MARK_CONTAINERS.has(node.type) && "children" in node) {
|
|
12869
|
+
leaves.push(...inlineLeaves(node.children));
|
|
12870
|
+
} else if (node.type === "mdxJsxTextElement" && node.name !== null && MARK_ELEMENTS.has(node.name)) {
|
|
12871
|
+
leaves.push(...inlineLeaves(node.children));
|
|
12872
|
+
} else {
|
|
12873
|
+
leaves.push(node);
|
|
12874
|
+
}
|
|
12875
|
+
}
|
|
12876
|
+
return leaves;
|
|
12877
|
+
}
|
|
12878
|
+
var ASCII_PUNCTUATION = /[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/;
|
|
12879
|
+
function mapTextToSource(source, start, end, text) {
|
|
12880
|
+
const offsets = [];
|
|
12881
|
+
let i = start;
|
|
12882
|
+
for (let j = 0; j < text.length; j++) {
|
|
12883
|
+
offsets.push(i);
|
|
12884
|
+
if (i >= end)
|
|
12885
|
+
return null;
|
|
12886
|
+
const run = /^[ \t]*\n[ \t\n]*/.exec(source.slice(i, end));
|
|
12887
|
+
if (run) {
|
|
12888
|
+
if (text[j] !== " ")
|
|
12889
|
+
return null;
|
|
12890
|
+
i += run[0].length;
|
|
12891
|
+
continue;
|
|
12892
|
+
}
|
|
12893
|
+
if (source[i] === "\\" && i + 1 < end && ASCII_PUNCTUATION.test(source[i + 1]))
|
|
12894
|
+
i++;
|
|
12895
|
+
if (source[i] !== text[j])
|
|
12896
|
+
return null;
|
|
12897
|
+
i++;
|
|
12898
|
+
}
|
|
12899
|
+
offsets.push(i);
|
|
12900
|
+
return /^[ \t]*$/.test(source.slice(i, end)) ? offsets : null;
|
|
12901
|
+
}
|
|
12902
|
+
function blockKey(node, serializerOptions) {
|
|
12903
|
+
try {
|
|
12904
|
+
const wrapped = node.type.schema.topNodeType.create(null, [node]);
|
|
12905
|
+
return pmToMdx(wrapped, Object.assign(Object.assign({}, serializerOptions), { removeTrailingNewline: true }));
|
|
12906
|
+
} catch (_a) {
|
|
12907
|
+
return JSON.stringify(node.toJSON());
|
|
12908
|
+
}
|
|
12909
|
+
}
|
|
12910
|
+
function computeLineStarts(source) {
|
|
12911
|
+
const starts = [0];
|
|
12912
|
+
for (let i = 0; i < source.length; i++) {
|
|
12913
|
+
if (source[i] === "\n")
|
|
12914
|
+
starts.push(i + 1);
|
|
12915
|
+
}
|
|
12916
|
+
return starts;
|
|
12917
|
+
}
|
|
12918
|
+
function buildLineMap(sanitized, preprocessed) {
|
|
12919
|
+
var _a, _b;
|
|
12920
|
+
const from = sanitized.split("\n");
|
|
12921
|
+
const to = preprocessed.split("\n");
|
|
12922
|
+
const map2 = [];
|
|
12923
|
+
let i = 0;
|
|
12924
|
+
for (let j = 0; j < to.length; ) {
|
|
12925
|
+
if (to[j] === from[i]) {
|
|
12926
|
+
map2.push(i);
|
|
12927
|
+
i++;
|
|
12928
|
+
j++;
|
|
12929
|
+
continue;
|
|
12930
|
+
}
|
|
12931
|
+
if (JSX_HEADING_OPEN.test((_a = to[j]) !== null && _a !== void 0 ? _a : "") && JSX_HEADING_CLOSE.test((_b = to[j + 2]) !== null && _b !== void 0 ? _b : "")) {
|
|
12932
|
+
map2.push(i, i, i);
|
|
12933
|
+
i++;
|
|
12934
|
+
j += 3;
|
|
12935
|
+
continue;
|
|
12936
|
+
}
|
|
12937
|
+
return null;
|
|
12938
|
+
}
|
|
12939
|
+
return i === from.length ? map2 : null;
|
|
12940
|
+
}
|
|
12941
|
+
function alignChildren(children, liveKeys) {
|
|
12942
|
+
const candidates = [];
|
|
12943
|
+
children.forEach((child, index) => {
|
|
12944
|
+
if (child.keys && child.keys.length > 0)
|
|
12945
|
+
candidates.push(index);
|
|
12946
|
+
});
|
|
12947
|
+
const n = candidates.length;
|
|
12948
|
+
const m = liveKeys.length;
|
|
12949
|
+
if ((n + 1) * (m + 1) > MAX_ALIGNMENT_CELLS)
|
|
12950
|
+
return null;
|
|
12951
|
+
const matchesAt = (keys, at) => {
|
|
12952
|
+
if (at + keys.length > m)
|
|
12953
|
+
return false;
|
|
12954
|
+
for (let k = 0; k < keys.length; k++) {
|
|
12955
|
+
if (liveKeys[at + k] !== keys[k])
|
|
12956
|
+
return false;
|
|
12957
|
+
}
|
|
12958
|
+
return true;
|
|
12959
|
+
};
|
|
12960
|
+
const dp = Array.from({ length: n + 1 }, () => new Int32Array(m + 1));
|
|
12961
|
+
for (let b2 = n - 1; b2 >= 0; b2--) {
|
|
12962
|
+
const keys = children[candidates[b2]].keys;
|
|
12963
|
+
const row = dp[b2];
|
|
12964
|
+
const next = dp[b2 + 1];
|
|
12965
|
+
for (let j2 = m - 1; j2 >= 0; j2--) {
|
|
12966
|
+
let best = Math.max(next[j2], row[j2 + 1]);
|
|
12967
|
+
if (matchesAt(keys, j2)) {
|
|
12968
|
+
best = Math.max(best, keys.length + next[j2 + keys.length]);
|
|
12969
|
+
}
|
|
12970
|
+
row[j2] = best;
|
|
12971
|
+
}
|
|
12972
|
+
}
|
|
12973
|
+
const result = children.map(() => null);
|
|
12974
|
+
let b = 0;
|
|
12975
|
+
let j = 0;
|
|
12976
|
+
while (b < n && j < m) {
|
|
12977
|
+
const keys = children[candidates[b]].keys;
|
|
12978
|
+
if (matchesAt(keys, j) && dp[b][j] === keys.length + dp[b + 1][j + keys.length]) {
|
|
12979
|
+
result[candidates[b]] = j;
|
|
12980
|
+
b++;
|
|
12981
|
+
j += keys.length;
|
|
12982
|
+
} else if (dp[b][j] === dp[b + 1][j]) {
|
|
12983
|
+
b++;
|
|
12984
|
+
} else {
|
|
12985
|
+
j++;
|
|
12986
|
+
}
|
|
12987
|
+
}
|
|
12988
|
+
return result;
|
|
12989
|
+
}
|
|
12990
|
+
|
|
12991
|
+
// ../editor/dist/converter/serialize/pm-to-mdast.js
|
|
12992
|
+
function pmJsonToMdast(_doc, _frontmatter) {
|
|
12993
|
+
throw new Error("pmJsonToMdast is not yet implemented \u2014 use pmToMdx instead for direct MDX output");
|
|
12994
|
+
}
|
|
12995
|
+
|
|
12996
|
+
// ../editor/dist/converter/serialize/mdast-to-mdx.js
|
|
12997
|
+
import remarkGfm3 from "remark-gfm";
|
|
12998
|
+
import remarkMath2 from "remark-math";
|
|
12999
|
+
import remarkMdx3 from "remark-mdx";
|
|
13000
|
+
import remarkStringify2 from "remark-stringify";
|
|
13001
|
+
import { unified as unified2 } from "unified";
|
|
13002
|
+
function mdastToMdx(mdast) {
|
|
13003
|
+
const result = unified2().use(remarkMdx3).use(remarkGfm3).use(remarkMath2).use(remarkStringify2).stringify(mdast);
|
|
13004
|
+
return typeof result === "string" ? result : String(result);
|
|
13005
|
+
}
|
|
13006
|
+
|
|
12066
13007
|
// ../editor/dist/converter/diff/diff-docs.js
|
|
12067
13008
|
var diffDocs = (oldDoc, newDoc, schema2) => {
|
|
12068
13009
|
var _a, _b;
|
|
@@ -12596,6 +13537,7 @@ export {
|
|
|
12596
13537
|
parseMetaString,
|
|
12597
13538
|
pmJsonToMdast,
|
|
12598
13539
|
pmToMdx,
|
|
13540
|
+
pmToMdxPreservingSource,
|
|
12599
13541
|
safeJsonParse,
|
|
12600
13542
|
sanitizeDomAttrs,
|
|
12601
13543
|
serializePropValue,
|