@tinacms/mdx 2.2.1 → 2.2.2
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/dist/break-neighbours.test.d.ts +1 -0
- package/dist/break-representability/index.test.d.ts +1 -0
- package/dist/break-serialization.d.ts +12 -0
- package/dist/break-serialization.test.d.ts +1 -0
- package/dist/index.browser.js +115 -6
- package/dist/index.js +115 -6
- package/dist/link-children.test.d.ts +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as Md from 'mdast';
|
|
2
|
+
/**
|
|
3
|
+
* Reshape the tree so every hard break left in it is one markdown can express.
|
|
4
|
+
* Acts in place.
|
|
5
|
+
*
|
|
6
|
+
* Two ordered passes, not one. Splitting a heading that still holds a trailing
|
|
7
|
+
* break yields a second heading containing only what followed it — for
|
|
8
|
+
* `### [one⏎](/x)` that is an empty link, written out as `### [](/x)`. Trimming
|
|
9
|
+
* the whole tree first means the split only ever sees breaks with content on
|
|
10
|
+
* both sides.
|
|
11
|
+
*/
|
|
12
|
+
export declare const serializeBreaks: <T extends Md.Root>(tree: T) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.browser.js
CHANGED
|
@@ -1225,7 +1225,7 @@ var init_acorn = __esm({
|
|
|
1225
1225
|
}
|
|
1226
1226
|
};
|
|
1227
1227
|
pp$8.parseBreakContinueStatement = function(node2, keyword) {
|
|
1228
|
-
var
|
|
1228
|
+
var isBreak2 = keyword === "break";
|
|
1229
1229
|
this.next();
|
|
1230
1230
|
if (this.eat(types$1.semi) || this.insertSemicolon()) {
|
|
1231
1231
|
node2.label = null;
|
|
@@ -1239,10 +1239,10 @@ var init_acorn = __esm({
|
|
|
1239
1239
|
for (; i2 < this.labels.length; ++i2) {
|
|
1240
1240
|
var lab = this.labels[i2];
|
|
1241
1241
|
if (node2.label == null || lab.name === node2.label.name) {
|
|
1242
|
-
if (lab.kind != null && (
|
|
1242
|
+
if (lab.kind != null && (isBreak2 || lab.kind === "loop")) {
|
|
1243
1243
|
break;
|
|
1244
1244
|
}
|
|
1245
|
-
if (node2.label &&
|
|
1245
|
+
if (node2.label && isBreak2) {
|
|
1246
1246
|
break;
|
|
1247
1247
|
}
|
|
1248
1248
|
}
|
|
@@ -1250,7 +1250,7 @@ var init_acorn = __esm({
|
|
|
1250
1250
|
if (i2 === this.labels.length) {
|
|
1251
1251
|
this.raise(node2.start, "Unsyntactic " + keyword);
|
|
1252
1252
|
}
|
|
1253
|
-
return this.finishNode(node2,
|
|
1253
|
+
return this.finishNode(node2, isBreak2 ? "BreakStatement" : "ContinueStatement");
|
|
1254
1254
|
};
|
|
1255
1255
|
pp$8.parseDebuggerStatement = function(node2) {
|
|
1256
1256
|
this.next();
|
|
@@ -34302,6 +34302,112 @@ function assertShape(value, callback, errorMessage) {
|
|
|
34302
34302
|
}
|
|
34303
34303
|
}
|
|
34304
34304
|
|
|
34305
|
+
// src/break-serialization.ts
|
|
34306
|
+
var serializeBreaks = (tree) => {
|
|
34307
|
+
trimTree(tree);
|
|
34308
|
+
splitTree(tree);
|
|
34309
|
+
return tree;
|
|
34310
|
+
};
|
|
34311
|
+
var isParent = (node2) => Array.isArray(node2?.children);
|
|
34312
|
+
var PHRASING_BLOCKS = /* @__PURE__ */ new Set(["paragraph", "heading", "tableCell"]);
|
|
34313
|
+
var trimTree = (node2) => {
|
|
34314
|
+
dropBreaksBeforeLineStartSensitive(node2.children);
|
|
34315
|
+
if (PHRASING_BLOCKS.has(node2.type ?? "")) {
|
|
34316
|
+
trimTrailingBreaks(node2);
|
|
34317
|
+
}
|
|
34318
|
+
for (const child of node2.children) {
|
|
34319
|
+
if (isParent(child)) {
|
|
34320
|
+
trimTree(child);
|
|
34321
|
+
}
|
|
34322
|
+
}
|
|
34323
|
+
};
|
|
34324
|
+
var splitTree = (node2) => {
|
|
34325
|
+
node2.children = node2.children.flatMap(
|
|
34326
|
+
(child) => isHeading(child) && child.depth > DEEPEST_SETEXT ? splitOnBreaks(child) : [child]
|
|
34327
|
+
);
|
|
34328
|
+
for (const child of node2.children) {
|
|
34329
|
+
if (isParent(child)) {
|
|
34330
|
+
splitTree(child);
|
|
34331
|
+
}
|
|
34332
|
+
}
|
|
34333
|
+
};
|
|
34334
|
+
var trimTrailingBreaks = ({ children }) => {
|
|
34335
|
+
let index2 = children.length;
|
|
34336
|
+
const trailing = [];
|
|
34337
|
+
while (index2 > 0) {
|
|
34338
|
+
const child = children[index2 - 1];
|
|
34339
|
+
if (isBreak(child)) {
|
|
34340
|
+
trailing.push(index2 - 1);
|
|
34341
|
+
} else if (!writesNothing(child)) {
|
|
34342
|
+
break;
|
|
34343
|
+
}
|
|
34344
|
+
index2--;
|
|
34345
|
+
}
|
|
34346
|
+
for (const at3 of trailing) {
|
|
34347
|
+
children.splice(at3, 1);
|
|
34348
|
+
}
|
|
34349
|
+
const last = children[index2 - 1];
|
|
34350
|
+
if (isParent(last)) {
|
|
34351
|
+
trimTrailingBreaks(last);
|
|
34352
|
+
}
|
|
34353
|
+
};
|
|
34354
|
+
var isBreak = (node2) => node2?.type === "break";
|
|
34355
|
+
var writesNothing = (node2) => node2?.type === "text" && node2.value === "";
|
|
34356
|
+
var dropBreaksBeforeLineStartSensitive = (children) => {
|
|
34357
|
+
for (let index2 = children.length - 1; index2 >= 0; index2--) {
|
|
34358
|
+
if (!isBreak(children[index2])) {
|
|
34359
|
+
continue;
|
|
34360
|
+
}
|
|
34361
|
+
const next = children.slice(index2 + 1).find((sibling2) => !writesNothing(sibling2));
|
|
34362
|
+
const type = next?.type;
|
|
34363
|
+
if (type === "html") {
|
|
34364
|
+
const before = children[index2 - 1];
|
|
34365
|
+
const spaced = before?.type === "text" && /[ \t]$/.test(before.value);
|
|
34366
|
+
children.splice(
|
|
34367
|
+
index2,
|
|
34368
|
+
1,
|
|
34369
|
+
...spaced ? [] : [{ type: "text", value: " " }]
|
|
34370
|
+
);
|
|
34371
|
+
} else if (type === "mdxJsxTextElement") {
|
|
34372
|
+
children.splice(index2, 1);
|
|
34373
|
+
}
|
|
34374
|
+
}
|
|
34375
|
+
};
|
|
34376
|
+
var isHeading = (node2) => isParent(node2) && node2.type === "heading";
|
|
34377
|
+
var DEEPEST_SETEXT = 2;
|
|
34378
|
+
var splitOnBreaks = (heading2) => splitInlines(heading2.children).map((children) => children.filter((child) => !writesNothingDeep(child))).filter((children) => children.length).map((children) => ({ ...heading2, children }));
|
|
34379
|
+
var writesNothingDeep = (node2) => {
|
|
34380
|
+
if (isBreak(node2)) {
|
|
34381
|
+
return false;
|
|
34382
|
+
}
|
|
34383
|
+
if (isParent(node2)) {
|
|
34384
|
+
return node2.children.length > 0 && node2.children.every(writesNothingDeep);
|
|
34385
|
+
}
|
|
34386
|
+
return writesNothing(node2);
|
|
34387
|
+
};
|
|
34388
|
+
var splitInlines = (nodes) => {
|
|
34389
|
+
const segments = [[]];
|
|
34390
|
+
const push2 = (node2) => segments[segments.length - 1]?.push(node2);
|
|
34391
|
+
for (const node2 of nodes) {
|
|
34392
|
+
if (isBreak(node2)) {
|
|
34393
|
+
segments.push([]);
|
|
34394
|
+
continue;
|
|
34395
|
+
}
|
|
34396
|
+
if (!isParent(node2)) {
|
|
34397
|
+
push2(node2);
|
|
34398
|
+
continue;
|
|
34399
|
+
}
|
|
34400
|
+
const inner = splitInlines(node2.children);
|
|
34401
|
+
inner.forEach((children, index2) => {
|
|
34402
|
+
if (index2 > 0) {
|
|
34403
|
+
segments.push([]);
|
|
34404
|
+
}
|
|
34405
|
+
push2({ ...node2, children });
|
|
34406
|
+
});
|
|
34407
|
+
}
|
|
34408
|
+
return segments;
|
|
34409
|
+
};
|
|
34410
|
+
|
|
34305
34411
|
// src/extensions/tina-shortcodes/to-markdown.ts
|
|
34306
34412
|
var own6 = {}.hasOwnProperty;
|
|
34307
34413
|
var directiveToMarkdown = (patterns) => ({
|
|
@@ -35059,7 +35165,7 @@ var toTinaMarkdown = (tree, field) => {
|
|
|
35059
35165
|
}
|
|
35060
35166
|
return text4(node2, parent, context, safeOptions);
|
|
35061
35167
|
};
|
|
35062
|
-
return toMarkdown(tree, {
|
|
35168
|
+
return toMarkdown(serializeBreaks(tree), {
|
|
35063
35169
|
extensions: [
|
|
35064
35170
|
directiveToMarkdown(patterns),
|
|
35065
35171
|
mdxJsxToMarkdown(),
|
|
@@ -36288,7 +36394,7 @@ var toTinaMarkdown2 = (tree, field) => {
|
|
|
36288
36394
|
}
|
|
36289
36395
|
return text4(node2, parent, context, safeOptions);
|
|
36290
36396
|
};
|
|
36291
|
-
return toMarkdown(tree, {
|
|
36397
|
+
return toMarkdown(serializeBreaks(tree), {
|
|
36292
36398
|
extensions: [mdxJsxToMarkdown2({ patterns }), gfmToMarkdown()],
|
|
36293
36399
|
listItemIndent: "one",
|
|
36294
36400
|
handlers
|
|
@@ -37807,10 +37913,13 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
37807
37913
|
) ?? mdxJsxElement2(content4, field, imageCallback);
|
|
37808
37914
|
case "text":
|
|
37809
37915
|
return text7(content4);
|
|
37916
|
+
case "break":
|
|
37917
|
+
return breakContent();
|
|
37810
37918
|
case "inlineCode":
|
|
37811
37919
|
case "emphasis":
|
|
37812
37920
|
case "image":
|
|
37813
37921
|
case "strong":
|
|
37922
|
+
case "delete":
|
|
37814
37923
|
return phrashingMark(content4);
|
|
37815
37924
|
case "html":
|
|
37816
37925
|
return html_inline(content4);
|
package/dist/index.js
CHANGED
|
@@ -1225,7 +1225,7 @@ var init_acorn = __esm({
|
|
|
1225
1225
|
}
|
|
1226
1226
|
};
|
|
1227
1227
|
pp$8.parseBreakContinueStatement = function(node2, keyword) {
|
|
1228
|
-
var
|
|
1228
|
+
var isBreak2 = keyword === "break";
|
|
1229
1229
|
this.next();
|
|
1230
1230
|
if (this.eat(types$1.semi) || this.insertSemicolon()) {
|
|
1231
1231
|
node2.label = null;
|
|
@@ -1239,10 +1239,10 @@ var init_acorn = __esm({
|
|
|
1239
1239
|
for (; i2 < this.labels.length; ++i2) {
|
|
1240
1240
|
var lab = this.labels[i2];
|
|
1241
1241
|
if (node2.label == null || lab.name === node2.label.name) {
|
|
1242
|
-
if (lab.kind != null && (
|
|
1242
|
+
if (lab.kind != null && (isBreak2 || lab.kind === "loop")) {
|
|
1243
1243
|
break;
|
|
1244
1244
|
}
|
|
1245
|
-
if (node2.label &&
|
|
1245
|
+
if (node2.label && isBreak2) {
|
|
1246
1246
|
break;
|
|
1247
1247
|
}
|
|
1248
1248
|
}
|
|
@@ -1250,7 +1250,7 @@ var init_acorn = __esm({
|
|
|
1250
1250
|
if (i2 === this.labels.length) {
|
|
1251
1251
|
this.raise(node2.start, "Unsyntactic " + keyword);
|
|
1252
1252
|
}
|
|
1253
|
-
return this.finishNode(node2,
|
|
1253
|
+
return this.finishNode(node2, isBreak2 ? "BreakStatement" : "ContinueStatement");
|
|
1254
1254
|
};
|
|
1255
1255
|
pp$8.parseDebuggerStatement = function(node2) {
|
|
1256
1256
|
this.next();
|
|
@@ -36168,6 +36168,112 @@ function assertShape(value, callback, errorMessage) {
|
|
|
36168
36168
|
}
|
|
36169
36169
|
}
|
|
36170
36170
|
|
|
36171
|
+
// src/break-serialization.ts
|
|
36172
|
+
var serializeBreaks = (tree) => {
|
|
36173
|
+
trimTree(tree);
|
|
36174
|
+
splitTree(tree);
|
|
36175
|
+
return tree;
|
|
36176
|
+
};
|
|
36177
|
+
var isParent = (node2) => Array.isArray(node2?.children);
|
|
36178
|
+
var PHRASING_BLOCKS = /* @__PURE__ */ new Set(["paragraph", "heading", "tableCell"]);
|
|
36179
|
+
var trimTree = (node2) => {
|
|
36180
|
+
dropBreaksBeforeLineStartSensitive(node2.children);
|
|
36181
|
+
if (PHRASING_BLOCKS.has(node2.type ?? "")) {
|
|
36182
|
+
trimTrailingBreaks(node2);
|
|
36183
|
+
}
|
|
36184
|
+
for (const child of node2.children) {
|
|
36185
|
+
if (isParent(child)) {
|
|
36186
|
+
trimTree(child);
|
|
36187
|
+
}
|
|
36188
|
+
}
|
|
36189
|
+
};
|
|
36190
|
+
var splitTree = (node2) => {
|
|
36191
|
+
node2.children = node2.children.flatMap(
|
|
36192
|
+
(child) => isHeading(child) && child.depth > DEEPEST_SETEXT ? splitOnBreaks(child) : [child]
|
|
36193
|
+
);
|
|
36194
|
+
for (const child of node2.children) {
|
|
36195
|
+
if (isParent(child)) {
|
|
36196
|
+
splitTree(child);
|
|
36197
|
+
}
|
|
36198
|
+
}
|
|
36199
|
+
};
|
|
36200
|
+
var trimTrailingBreaks = ({ children }) => {
|
|
36201
|
+
let index2 = children.length;
|
|
36202
|
+
const trailing = [];
|
|
36203
|
+
while (index2 > 0) {
|
|
36204
|
+
const child = children[index2 - 1];
|
|
36205
|
+
if (isBreak(child)) {
|
|
36206
|
+
trailing.push(index2 - 1);
|
|
36207
|
+
} else if (!writesNothing(child)) {
|
|
36208
|
+
break;
|
|
36209
|
+
}
|
|
36210
|
+
index2--;
|
|
36211
|
+
}
|
|
36212
|
+
for (const at3 of trailing) {
|
|
36213
|
+
children.splice(at3, 1);
|
|
36214
|
+
}
|
|
36215
|
+
const last = children[index2 - 1];
|
|
36216
|
+
if (isParent(last)) {
|
|
36217
|
+
trimTrailingBreaks(last);
|
|
36218
|
+
}
|
|
36219
|
+
};
|
|
36220
|
+
var isBreak = (node2) => node2?.type === "break";
|
|
36221
|
+
var writesNothing = (node2) => node2?.type === "text" && node2.value === "";
|
|
36222
|
+
var dropBreaksBeforeLineStartSensitive = (children) => {
|
|
36223
|
+
for (let index2 = children.length - 1; index2 >= 0; index2--) {
|
|
36224
|
+
if (!isBreak(children[index2])) {
|
|
36225
|
+
continue;
|
|
36226
|
+
}
|
|
36227
|
+
const next = children.slice(index2 + 1).find((sibling2) => !writesNothing(sibling2));
|
|
36228
|
+
const type = next?.type;
|
|
36229
|
+
if (type === "html") {
|
|
36230
|
+
const before = children[index2 - 1];
|
|
36231
|
+
const spaced = before?.type === "text" && /[ \t]$/.test(before.value);
|
|
36232
|
+
children.splice(
|
|
36233
|
+
index2,
|
|
36234
|
+
1,
|
|
36235
|
+
...spaced ? [] : [{ type: "text", value: " " }]
|
|
36236
|
+
);
|
|
36237
|
+
} else if (type === "mdxJsxTextElement") {
|
|
36238
|
+
children.splice(index2, 1);
|
|
36239
|
+
}
|
|
36240
|
+
}
|
|
36241
|
+
};
|
|
36242
|
+
var isHeading = (node2) => isParent(node2) && node2.type === "heading";
|
|
36243
|
+
var DEEPEST_SETEXT = 2;
|
|
36244
|
+
var splitOnBreaks = (heading2) => splitInlines(heading2.children).map((children) => children.filter((child) => !writesNothingDeep(child))).filter((children) => children.length).map((children) => ({ ...heading2, children }));
|
|
36245
|
+
var writesNothingDeep = (node2) => {
|
|
36246
|
+
if (isBreak(node2)) {
|
|
36247
|
+
return false;
|
|
36248
|
+
}
|
|
36249
|
+
if (isParent(node2)) {
|
|
36250
|
+
return node2.children.length > 0 && node2.children.every(writesNothingDeep);
|
|
36251
|
+
}
|
|
36252
|
+
return writesNothing(node2);
|
|
36253
|
+
};
|
|
36254
|
+
var splitInlines = (nodes) => {
|
|
36255
|
+
const segments = [[]];
|
|
36256
|
+
const push2 = (node2) => segments[segments.length - 1]?.push(node2);
|
|
36257
|
+
for (const node2 of nodes) {
|
|
36258
|
+
if (isBreak(node2)) {
|
|
36259
|
+
segments.push([]);
|
|
36260
|
+
continue;
|
|
36261
|
+
}
|
|
36262
|
+
if (!isParent(node2)) {
|
|
36263
|
+
push2(node2);
|
|
36264
|
+
continue;
|
|
36265
|
+
}
|
|
36266
|
+
const inner = splitInlines(node2.children);
|
|
36267
|
+
inner.forEach((children, index2) => {
|
|
36268
|
+
if (index2 > 0) {
|
|
36269
|
+
segments.push([]);
|
|
36270
|
+
}
|
|
36271
|
+
push2({ ...node2, children });
|
|
36272
|
+
});
|
|
36273
|
+
}
|
|
36274
|
+
return segments;
|
|
36275
|
+
};
|
|
36276
|
+
|
|
36171
36277
|
// src/extensions/tina-shortcodes/to-markdown.ts
|
|
36172
36278
|
var own7 = {}.hasOwnProperty;
|
|
36173
36279
|
var directiveToMarkdown = (patterns) => ({
|
|
@@ -36925,7 +37031,7 @@ var toTinaMarkdown = (tree, field) => {
|
|
|
36925
37031
|
}
|
|
36926
37032
|
return text4(node2, parent, context, safeOptions);
|
|
36927
37033
|
};
|
|
36928
|
-
return toMarkdown(tree, {
|
|
37034
|
+
return toMarkdown(serializeBreaks(tree), {
|
|
36929
37035
|
extensions: [
|
|
36930
37036
|
directiveToMarkdown(patterns),
|
|
36931
37037
|
mdxJsxToMarkdown(),
|
|
@@ -38154,7 +38260,7 @@ var toTinaMarkdown2 = (tree, field) => {
|
|
|
38154
38260
|
}
|
|
38155
38261
|
return text4(node2, parent, context, safeOptions);
|
|
38156
38262
|
};
|
|
38157
|
-
return toMarkdown(tree, {
|
|
38263
|
+
return toMarkdown(serializeBreaks(tree), {
|
|
38158
38264
|
extensions: [mdxJsxToMarkdown2({ patterns }), gfmToMarkdown()],
|
|
38159
38265
|
listItemIndent: "one",
|
|
38160
38266
|
handlers
|
|
@@ -39673,10 +39779,13 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
39673
39779
|
) ?? mdxJsxElement2(content4, field, imageCallback);
|
|
39674
39780
|
case "text":
|
|
39675
39781
|
return text7(content4);
|
|
39782
|
+
case "break":
|
|
39783
|
+
return breakContent();
|
|
39676
39784
|
case "inlineCode":
|
|
39677
39785
|
case "emphasis":
|
|
39678
39786
|
case "image":
|
|
39679
39787
|
case "strong":
|
|
39788
|
+
case "delete":
|
|
39680
39789
|
return phrashingMark(content4);
|
|
39681
39790
|
case "html":
|
|
39682
39791
|
return html_inline(content4);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/mdx",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"unist-util-stringify-position": "3.0.3",
|
|
59
59
|
"unist-util-visit": "4.1.2",
|
|
60
60
|
"vfile-message": "3.1.4",
|
|
61
|
-
"@tinacms/schema-tools": "^2.
|
|
61
|
+
"@tinacms/schema-tools": "^2.10.0"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"registry": "https://registry.npmjs.org"
|
|
65
65
|
},
|
|
66
66
|
"repository": {
|
|
67
67
|
"url": "https://github.com/tinacms/tinacms.git",
|
|
68
|
-
"directory": "packages/
|
|
68
|
+
"directory": "packages/@tinacms/mdx"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/estree": "1.0.0",
|