@tinacms/mdx 2.1.6 → 2.1.7
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/index.browser.js +31 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +31 -2
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -49213,7 +49213,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
49213
49213
|
const image2 = (content4) => {
|
|
49214
49214
|
return {
|
|
49215
49215
|
type: "img",
|
|
49216
|
-
url: imageCallback(content4.url),
|
|
49216
|
+
url: imageCallback(sanitizeUrl(content4.url)),
|
|
49217
49217
|
alt: content4.alt || void 0,
|
|
49218
49218
|
// alt cannot be `null`
|
|
49219
49219
|
caption: content4.title,
|
|
@@ -49365,6 +49365,32 @@ var mdxToAst = (value) => {
|
|
|
49365
49365
|
return remark().use(remarkMdx).use(remarkGfm).parse(value);
|
|
49366
49366
|
};
|
|
49367
49367
|
var MDX_PARSE_ERROR_MSG = "TinaCMS supports a stricter version of markdown and a subset of MDX. https://tina.io/docs/r/what-is-markdown";
|
|
49368
|
+
var isSlateNode = (value) => !!value && typeof value === "object" && !Array.isArray(value) && typeof value.type === "string";
|
|
49369
|
+
var isSlateContent = (value) => isSlateNode(value) || Array.isArray(value) && value.length > 0 && value.every(isSlateNode);
|
|
49370
|
+
var sanitizeSlateTree = (node2) => {
|
|
49371
|
+
if (Array.isArray(node2)) {
|
|
49372
|
+
return node2.map((child) => sanitizeSlateTree(child));
|
|
49373
|
+
}
|
|
49374
|
+
if (!node2 || typeof node2 !== "object") {
|
|
49375
|
+
return node2;
|
|
49376
|
+
}
|
|
49377
|
+
const next = {
|
|
49378
|
+
...node2
|
|
49379
|
+
};
|
|
49380
|
+
if ((next.type === "a" || next.type === "img") && typeof next.url === "string") {
|
|
49381
|
+
next.url = sanitizeUrl(next.url);
|
|
49382
|
+
}
|
|
49383
|
+
if (Array.isArray(next.children)) {
|
|
49384
|
+
next.children = next.children.map((child) => sanitizeSlateTree(child));
|
|
49385
|
+
}
|
|
49386
|
+
if (next.props && typeof next.props === "object" && !Array.isArray(next.props)) {
|
|
49387
|
+
const props = next.props;
|
|
49388
|
+
if (isSlateContent(props.children)) {
|
|
49389
|
+
next.props = { ...props, children: sanitizeSlateTree(props.children) };
|
|
49390
|
+
}
|
|
49391
|
+
}
|
|
49392
|
+
return next;
|
|
49393
|
+
};
|
|
49368
49394
|
var parseMDX = (value, field, imageCallback) => {
|
|
49369
49395
|
if (!value) {
|
|
49370
49396
|
return { type: "root", children: [] };
|
|
@@ -49375,7 +49401,9 @@ var parseMDX = (value, field, imageCallback) => {
|
|
|
49375
49401
|
case "markdown":
|
|
49376
49402
|
return parseMDX2(value, field, imageCallback);
|
|
49377
49403
|
case "slatejson":
|
|
49378
|
-
return
|
|
49404
|
+
return sanitizeSlateTree(
|
|
49405
|
+
value
|
|
49406
|
+
);
|
|
49379
49407
|
}
|
|
49380
49408
|
let preprocessedString = value;
|
|
49381
49409
|
const templatesWithMatchers = field.templates?.filter(
|
|
@@ -49428,6 +49456,7 @@ var replaceAll = (string3, target, value) => {
|
|
|
49428
49456
|
};
|
|
49429
49457
|
export {
|
|
49430
49458
|
parseMDX,
|
|
49459
|
+
sanitizeUrl,
|
|
49431
49460
|
serializeMDX
|
|
49432
49461
|
};
|
|
49433
49462
|
/*! Bundled license information:
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -51079,7 +51079,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
51079
51079
|
const image2 = (content4) => {
|
|
51080
51080
|
return {
|
|
51081
51081
|
type: "img",
|
|
51082
|
-
url: imageCallback(content4.url),
|
|
51082
|
+
url: imageCallback(sanitizeUrl(content4.url)),
|
|
51083
51083
|
alt: content4.alt || void 0,
|
|
51084
51084
|
// alt cannot be `null`
|
|
51085
51085
|
caption: content4.title,
|
|
@@ -51231,6 +51231,32 @@ var mdxToAst = (value) => {
|
|
|
51231
51231
|
return remark().use(remarkMdx).use(remarkGfm).parse(value);
|
|
51232
51232
|
};
|
|
51233
51233
|
var MDX_PARSE_ERROR_MSG = "TinaCMS supports a stricter version of markdown and a subset of MDX. https://tina.io/docs/r/what-is-markdown";
|
|
51234
|
+
var isSlateNode = (value) => !!value && typeof value === "object" && !Array.isArray(value) && typeof value.type === "string";
|
|
51235
|
+
var isSlateContent = (value) => isSlateNode(value) || Array.isArray(value) && value.length > 0 && value.every(isSlateNode);
|
|
51236
|
+
var sanitizeSlateTree = (node2) => {
|
|
51237
|
+
if (Array.isArray(node2)) {
|
|
51238
|
+
return node2.map((child) => sanitizeSlateTree(child));
|
|
51239
|
+
}
|
|
51240
|
+
if (!node2 || typeof node2 !== "object") {
|
|
51241
|
+
return node2;
|
|
51242
|
+
}
|
|
51243
|
+
const next = {
|
|
51244
|
+
...node2
|
|
51245
|
+
};
|
|
51246
|
+
if ((next.type === "a" || next.type === "img") && typeof next.url === "string") {
|
|
51247
|
+
next.url = sanitizeUrl(next.url);
|
|
51248
|
+
}
|
|
51249
|
+
if (Array.isArray(next.children)) {
|
|
51250
|
+
next.children = next.children.map((child) => sanitizeSlateTree(child));
|
|
51251
|
+
}
|
|
51252
|
+
if (next.props && typeof next.props === "object" && !Array.isArray(next.props)) {
|
|
51253
|
+
const props = next.props;
|
|
51254
|
+
if (isSlateContent(props.children)) {
|
|
51255
|
+
next.props = { ...props, children: sanitizeSlateTree(props.children) };
|
|
51256
|
+
}
|
|
51257
|
+
}
|
|
51258
|
+
return next;
|
|
51259
|
+
};
|
|
51234
51260
|
var parseMDX = (value, field, imageCallback) => {
|
|
51235
51261
|
if (!value) {
|
|
51236
51262
|
return { type: "root", children: [] };
|
|
@@ -51241,7 +51267,9 @@ var parseMDX = (value, field, imageCallback) => {
|
|
|
51241
51267
|
case "markdown":
|
|
51242
51268
|
return parseMDX2(value, field, imageCallback);
|
|
51243
51269
|
case "slatejson":
|
|
51244
|
-
return
|
|
51270
|
+
return sanitizeSlateTree(
|
|
51271
|
+
value
|
|
51272
|
+
);
|
|
51245
51273
|
}
|
|
51246
51274
|
let preprocessedString = value;
|
|
51247
51275
|
const templatesWithMatchers = field.templates?.filter(
|
|
@@ -51294,6 +51322,7 @@ var replaceAll = (string3, target, value) => {
|
|
|
51294
51322
|
};
|
|
51295
51323
|
export {
|
|
51296
51324
|
parseMDX,
|
|
51325
|
+
sanitizeUrl,
|
|
51297
51326
|
serializeMDX
|
|
51298
51327
|
};
|
|
51299
51328
|
/*! Bundled license information:
|