@tinacms/mdx 0.0.0-877699d-20250102032632 → 0.0.0-899eda4-20250227042836
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.mjs +126 -58
- package/dist/index.js +129 -61
- package/dist/index.mjs +126 -58
- package/dist/next/stringify/pre-processing.d.ts +0 -2
- package/dist/next/tests/markdown-basic-marks-strikethrough/field.d.ts +2 -0
- package/dist/next/tests/markdown-basic-marks-strikethrough/index.test.d.ts +1 -0
- package/dist/next/tests/mdx-local-variables/field.d.ts +2 -0
- package/dist/next/tests/mdx-local-variables/index.test.d.ts +1 -0
- package/dist/next/tests/util.d.ts +6 -0
- package/dist/parse/acorn.d.ts +1 -1
- package/dist/parse/index.d.ts +3 -1
- package/dist/parse/mdx.d.ts +2 -2
- package/dist/parse/plate.d.ts +2 -0
- package/dist/parse/remarkToPlate.d.ts +1 -1
- package/dist/stringify/acorn.d.ts +3 -3
- package/dist/stringify/index.d.ts +4 -4
- package/package.json +11 -6
package/dist/index.mjs
CHANGED
|
@@ -40024,10 +40024,22 @@ var Xh = Q({ "src/language-js/parse/acorn-and-espree.js"(a, u) {
|
|
|
40024
40024
|
var mc = Xh();
|
|
40025
40025
|
|
|
40026
40026
|
// src/stringify/acorn.ts
|
|
40027
|
-
|
|
40028
|
-
|
|
40027
|
+
function generateRandom6LetterString() {
|
|
40028
|
+
const characters = "abcdefghijklmnopqrstuvwxyz";
|
|
40029
|
+
let result = "";
|
|
40030
|
+
for (let i = 0; i < 6; i++) {
|
|
40031
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
40032
|
+
result += characters[randomIndex];
|
|
40033
|
+
}
|
|
40034
|
+
return result;
|
|
40035
|
+
}
|
|
40036
|
+
function isMultiline(input) {
|
|
40037
|
+
return input.includes("\n") || input.includes("\r");
|
|
40038
|
+
}
|
|
40039
|
+
var stringifyPropsInline = (element, field, imageCallback, context) => {
|
|
40040
|
+
return stringifyProps(element, field, true, imageCallback, context || {});
|
|
40029
40041
|
};
|
|
40030
|
-
function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
40042
|
+
function stringifyProps(element, parentField, flatten2, imageCallback, context) {
|
|
40031
40043
|
const attributes2 = [];
|
|
40032
40044
|
const children = [];
|
|
40033
40045
|
let template;
|
|
@@ -40051,6 +40063,16 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
40051
40063
|
if (template.fields.find((f) => f.name === "children")) {
|
|
40052
40064
|
directiveType = "block";
|
|
40053
40065
|
}
|
|
40066
|
+
const embedCodes = {};
|
|
40067
|
+
for (const [embedKey, value] of Object.entries(element.props)) {
|
|
40068
|
+
if (embedKey.startsWith("_tinaEmbeds")) {
|
|
40069
|
+
const key = embedKey.replace("_tinaEmbeds.", "");
|
|
40070
|
+
embedCodes[key] = value;
|
|
40071
|
+
}
|
|
40072
|
+
}
|
|
40073
|
+
for (const key of Object.keys(embedCodes)) {
|
|
40074
|
+
delete element.props[`_tinaEmbeds.${key}`];
|
|
40075
|
+
}
|
|
40054
40076
|
useDirective = !!template.match;
|
|
40055
40077
|
Object.entries(element.props).forEach(([name2, value]) => {
|
|
40056
40078
|
if (typeof template === "string") {
|
|
@@ -40101,11 +40123,22 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
40101
40123
|
}
|
|
40102
40124
|
} else {
|
|
40103
40125
|
if (typeof value === "string") {
|
|
40104
|
-
|
|
40105
|
-
|
|
40106
|
-
|
|
40107
|
-
value
|
|
40108
|
-
|
|
40126
|
+
if (isMultiline(value)) {
|
|
40127
|
+
const code3 = embedCodes[name2] || generateRandom6LetterString();
|
|
40128
|
+
context._tinaEmbeds = context._tinaEmbeds || {};
|
|
40129
|
+
context._tinaEmbeds[code3] = value;
|
|
40130
|
+
attributes2.push({
|
|
40131
|
+
type: "mdxJsxAttribute",
|
|
40132
|
+
name: name2,
|
|
40133
|
+
value: `_tinaEmbeds.${code3}`
|
|
40134
|
+
});
|
|
40135
|
+
} else {
|
|
40136
|
+
attributes2.push({
|
|
40137
|
+
type: "mdxJsxAttribute",
|
|
40138
|
+
name: name2,
|
|
40139
|
+
value
|
|
40140
|
+
});
|
|
40141
|
+
}
|
|
40109
40142
|
} else {
|
|
40110
40143
|
throw new Error(
|
|
40111
40144
|
`Expected string for attribute on field ${field.name}`
|
|
@@ -40191,39 +40224,23 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
40191
40224
|
(value2) => value2.type === "root" && Array.isArray(value2.children),
|
|
40192
40225
|
`Nested rich-text element is not a valid shape for field ${field.name}`
|
|
40193
40226
|
);
|
|
40227
|
+
const code3 = value.embedCode || generateRandom6LetterString();
|
|
40194
40228
|
if (field.name === "children") {
|
|
40195
|
-
const root2 = rootElement(value, field, imageCallback);
|
|
40229
|
+
const root2 = rootElement(value, field, imageCallback, context);
|
|
40196
40230
|
root2.children.forEach((child) => {
|
|
40197
40231
|
children.push(child);
|
|
40198
40232
|
});
|
|
40199
40233
|
return;
|
|
40200
40234
|
} else {
|
|
40201
40235
|
const stringValue = stringifyMDX(value, field, imageCallback);
|
|
40202
|
-
|
|
40203
|
-
|
|
40204
|
-
}
|
|
40205
|
-
}
|
|
40206
|
-
if (flatten2) {
|
|
40207
|
-
attributes2.push({
|
|
40208
|
-
type: "mdxJsxAttribute",
|
|
40209
|
-
name: name2,
|
|
40210
|
-
value: {
|
|
40211
|
-
type: "mdxJsxAttributeValueExpression",
|
|
40212
|
-
value: `<>${val.trim()}</>`
|
|
40213
|
-
}
|
|
40214
|
-
});
|
|
40215
|
-
} else {
|
|
40216
|
-
attributes2.push({
|
|
40217
|
-
type: "mdxJsxAttribute",
|
|
40218
|
-
name: name2,
|
|
40219
|
-
value: {
|
|
40220
|
-
type: "mdxJsxAttributeValueExpression",
|
|
40221
|
-
value: `<>
|
|
40222
|
-
${val}
|
|
40223
|
-
</>`
|
|
40224
|
-
}
|
|
40225
|
-
});
|
|
40236
|
+
context._tinaEmbeds = context._tinaEmbeds || {};
|
|
40237
|
+
context._tinaEmbeds[code3] = stringValue;
|
|
40226
40238
|
}
|
|
40239
|
+
attributes2.push({
|
|
40240
|
+
type: "mdxJsxAttribute",
|
|
40241
|
+
name: name2,
|
|
40242
|
+
value: `_tinaEmbeds.${code3}`
|
|
40243
|
+
});
|
|
40227
40244
|
}
|
|
40228
40245
|
break;
|
|
40229
40246
|
default:
|
|
@@ -40488,7 +40505,7 @@ var eat2 = (c, field, imageCallback) => {
|
|
|
40488
40505
|
}
|
|
40489
40506
|
if (markToProcess === "inlineCode") {
|
|
40490
40507
|
if (nonMatchingSiblingIndex) {
|
|
40491
|
-
throw new Error(
|
|
40508
|
+
throw new Error("Marks inside inline code are not supported");
|
|
40492
40509
|
}
|
|
40493
40510
|
const node2 = {
|
|
40494
40511
|
type: markToProcess,
|
|
@@ -40523,7 +40540,8 @@ var cleanNode = (node2, mark) => {
|
|
|
40523
40540
|
const markToClear = {
|
|
40524
40541
|
strong: "bold",
|
|
40525
40542
|
emphasis: "italic",
|
|
40526
|
-
inlineCode: "code"
|
|
40543
|
+
inlineCode: "code",
|
|
40544
|
+
delete: "strikethrough"
|
|
40527
40545
|
}[mark];
|
|
40528
40546
|
Object.entries(node2).map(([key, value]) => {
|
|
40529
40547
|
if (key !== markToClear) {
|
|
@@ -40660,7 +40678,7 @@ ${match.start} /${match.name || template.name} ${match.end}`;
|
|
|
40660
40678
|
}
|
|
40661
40679
|
|
|
40662
40680
|
// src/stringify/index.ts
|
|
40663
|
-
var stringifyMDX = (value, field, imageCallback) => {
|
|
40681
|
+
var stringifyMDX = (value, field, imageCallback, context = {}) => {
|
|
40664
40682
|
if (field.parser?.type === "markdown") {
|
|
40665
40683
|
return stringifyMDX2(value, field, imageCallback);
|
|
40666
40684
|
}
|
|
@@ -40675,7 +40693,7 @@ var stringifyMDX = (value, field, imageCallback) => {
|
|
|
40675
40693
|
return value.children[0].value;
|
|
40676
40694
|
}
|
|
40677
40695
|
}
|
|
40678
|
-
const tree = rootElement(value, field, imageCallback);
|
|
40696
|
+
const tree = rootElement(value, field, imageCallback, context);
|
|
40679
40697
|
const res = toTinaMarkdown2(tree, field);
|
|
40680
40698
|
const templatesWithMatchers = field.templates?.filter(
|
|
40681
40699
|
(template) => template.match
|
|
@@ -40736,10 +40754,10 @@ var toTinaMarkdown2 = (tree, field) => {
|
|
|
40736
40754
|
handlers
|
|
40737
40755
|
});
|
|
40738
40756
|
};
|
|
40739
|
-
var rootElement = (content3, field, imageCallback) => {
|
|
40757
|
+
var rootElement = (content3, field, imageCallback, context) => {
|
|
40740
40758
|
const children = [];
|
|
40741
40759
|
content3.children?.forEach((child) => {
|
|
40742
|
-
const value = blockElement(child, field, imageCallback);
|
|
40760
|
+
const value = blockElement(child, field, imageCallback, context);
|
|
40743
40761
|
if (value) {
|
|
40744
40762
|
children.push(value);
|
|
40745
40763
|
}
|
|
@@ -40749,7 +40767,7 @@ var rootElement = (content3, field, imageCallback) => {
|
|
|
40749
40767
|
children
|
|
40750
40768
|
};
|
|
40751
40769
|
};
|
|
40752
|
-
var blockElement = (content3, field, imageCallback) => {
|
|
40770
|
+
var blockElement = (content3, field, imageCallback, context) => {
|
|
40753
40771
|
switch (content3.type) {
|
|
40754
40772
|
case "h1":
|
|
40755
40773
|
case "h2":
|
|
@@ -40811,7 +40829,7 @@ var blockElement = (content3, field, imageCallback) => {
|
|
|
40811
40829
|
})
|
|
40812
40830
|
};
|
|
40813
40831
|
}
|
|
40814
|
-
const { children, attributes: attributes2, useDirective, directiveType } = stringifyProps(content3, field, false, imageCallback);
|
|
40832
|
+
const { children, attributes: attributes2, useDirective, directiveType } = stringifyProps(content3, field, false, imageCallback, context);
|
|
40815
40833
|
if (useDirective) {
|
|
40816
40834
|
const name2 = content3.name;
|
|
40817
40835
|
if (!name2) {
|
|
@@ -40981,6 +40999,9 @@ var getMarks = (content3) => {
|
|
|
40981
40999
|
if (content3.code) {
|
|
40982
41000
|
marks.push("inlineCode");
|
|
40983
41001
|
}
|
|
41002
|
+
if (content3.strikethrough) {
|
|
41003
|
+
marks.push("delete");
|
|
41004
|
+
}
|
|
40984
41005
|
return marks;
|
|
40985
41006
|
};
|
|
40986
41007
|
|
|
@@ -41425,7 +41446,8 @@ var cleanNode2 = (node2, mark) => {
|
|
|
41425
41446
|
const markToClear = {
|
|
41426
41447
|
strong: "bold",
|
|
41427
41448
|
emphasis: "italic",
|
|
41428
|
-
inlineCode: "code"
|
|
41449
|
+
inlineCode: "code",
|
|
41450
|
+
delete: "strikethrough"
|
|
41429
41451
|
}[mark];
|
|
41430
41452
|
Object.entries(node2).map(([key, value]) => {
|
|
41431
41453
|
if (key !== markToClear) {
|
|
@@ -43978,7 +44000,7 @@ function compact(tree) {
|
|
|
43978
44000
|
var import_lodash = __toESM(require_lodash());
|
|
43979
44001
|
|
|
43980
44002
|
// src/parse/acorn.ts
|
|
43981
|
-
var extractAttributes = (attributes2, fields, imageCallback) => {
|
|
44003
|
+
var extractAttributes = (attributes2, fields, imageCallback, context) => {
|
|
43982
44004
|
const properties = {};
|
|
43983
44005
|
attributes2?.forEach((attribute) => {
|
|
43984
44006
|
assertType(attribute, "mdxJsxAttribute");
|
|
@@ -43992,7 +44014,9 @@ var extractAttributes = (attributes2, fields, imageCallback) => {
|
|
|
43992
44014
|
properties[attribute.name] = extractAttribute(
|
|
43993
44015
|
attribute,
|
|
43994
44016
|
field,
|
|
43995
|
-
imageCallback
|
|
44017
|
+
imageCallback,
|
|
44018
|
+
context,
|
|
44019
|
+
(name2, value) => properties[name2] = value
|
|
43996
44020
|
);
|
|
43997
44021
|
} catch (e) {
|
|
43998
44022
|
if (e instanceof Error) {
|
|
@@ -44005,7 +44029,7 @@ var extractAttributes = (attributes2, fields, imageCallback) => {
|
|
|
44005
44029
|
});
|
|
44006
44030
|
return properties;
|
|
44007
44031
|
};
|
|
44008
|
-
var extractAttribute = (attribute, field, imageCallback) => {
|
|
44032
|
+
var extractAttribute = (attribute, field, imageCallback, context, addProperty) => {
|
|
44009
44033
|
switch (field.type) {
|
|
44010
44034
|
case "boolean":
|
|
44011
44035
|
case "number":
|
|
@@ -44015,7 +44039,7 @@ var extractAttribute = (attribute, field, imageCallback) => {
|
|
|
44015
44039
|
if (field.list) {
|
|
44016
44040
|
return extractScalar(extractExpression(attribute), field);
|
|
44017
44041
|
} else {
|
|
44018
|
-
return extractString(attribute, field);
|
|
44042
|
+
return extractString(attribute, field, context, addProperty);
|
|
44019
44043
|
}
|
|
44020
44044
|
case "image":
|
|
44021
44045
|
if (field.list) {
|
|
@@ -44025,18 +44049,35 @@ var extractAttribute = (attribute, field, imageCallback) => {
|
|
|
44025
44049
|
);
|
|
44026
44050
|
return values2.split(",").map((value) => imageCallback(value));
|
|
44027
44051
|
} else {
|
|
44028
|
-
const value = extractString(attribute, field);
|
|
44052
|
+
const value = extractString(attribute, field, context, addProperty);
|
|
44029
44053
|
return imageCallback(value);
|
|
44030
44054
|
}
|
|
44031
44055
|
case "reference":
|
|
44032
44056
|
if (field.list) {
|
|
44033
44057
|
return extractScalar(extractExpression(attribute), field);
|
|
44034
44058
|
} else {
|
|
44035
|
-
return extractString(attribute, field);
|
|
44059
|
+
return extractString(attribute, field, context, addProperty);
|
|
44036
44060
|
}
|
|
44037
44061
|
case "object":
|
|
44038
44062
|
return extractObject(extractExpression(attribute), field, imageCallback);
|
|
44039
44063
|
case "rich-text":
|
|
44064
|
+
if (attribute.type === "mdxJsxAttribute") {
|
|
44065
|
+
if (typeof attribute.value === "string") {
|
|
44066
|
+
if (attribute.value.startsWith("_tinaEmbeds")) {
|
|
44067
|
+
const embedValue = context?._tinaEmbeds;
|
|
44068
|
+
const key = attribute.value.split(".")[1];
|
|
44069
|
+
if (typeof key !== "string") {
|
|
44070
|
+
throw new Error(`Unable to extract key from embed value`);
|
|
44071
|
+
}
|
|
44072
|
+
const value = embedValue[key];
|
|
44073
|
+
if (typeof value === "string") {
|
|
44074
|
+
const ast = parseMDX(value, field, imageCallback, context);
|
|
44075
|
+
ast.embedCode = attribute.value.split(".")[1];
|
|
44076
|
+
return ast;
|
|
44077
|
+
}
|
|
44078
|
+
}
|
|
44079
|
+
}
|
|
44080
|
+
}
|
|
44040
44081
|
const JSXString = extractRaw(attribute);
|
|
44041
44082
|
if (JSXString) {
|
|
44042
44083
|
return parseMDX(JSXString, field, imageCallback);
|
|
@@ -44142,9 +44183,21 @@ var extractStatement = (attribute) => {
|
|
|
44142
44183
|
}
|
|
44143
44184
|
throw new Error(`Unable to extract body from expression`);
|
|
44144
44185
|
};
|
|
44145
|
-
var extractString = (attribute, field) => {
|
|
44186
|
+
var extractString = (attribute, field, context, addProperty) => {
|
|
44146
44187
|
if (attribute.type === "mdxJsxAttribute") {
|
|
44147
44188
|
if (typeof attribute.value === "string") {
|
|
44189
|
+
if (attribute.value.startsWith("_tinaEmbeds")) {
|
|
44190
|
+
const embedValue = context?._tinaEmbeds;
|
|
44191
|
+
const key = attribute.value.split(".")[1];
|
|
44192
|
+
if (typeof key !== "string") {
|
|
44193
|
+
throw new Error(`Unable to extract key from embed value`);
|
|
44194
|
+
}
|
|
44195
|
+
const value = embedValue[key];
|
|
44196
|
+
if (typeof value === "string") {
|
|
44197
|
+
addProperty?.(`_tinaEmbeds.${attribute.name}`, key);
|
|
44198
|
+
return value;
|
|
44199
|
+
}
|
|
44200
|
+
}
|
|
44148
44201
|
return attribute.value;
|
|
44149
44202
|
}
|
|
44150
44203
|
}
|
|
@@ -44269,7 +44322,7 @@ function source(value, file) {
|
|
|
44269
44322
|
}
|
|
44270
44323
|
|
|
44271
44324
|
// src/parse/mdx.ts
|
|
44272
|
-
function mdxJsxElement(node2, field, imageCallback) {
|
|
44325
|
+
function mdxJsxElement(node2, field, imageCallback, context) {
|
|
44273
44326
|
try {
|
|
44274
44327
|
const template = field.templates?.find((template2) => {
|
|
44275
44328
|
const templateName = typeof template2 === "string" ? template2 : template2.name;
|
|
@@ -44289,7 +44342,8 @@ function mdxJsxElement(node2, field, imageCallback) {
|
|
|
44289
44342
|
const props = extractAttributes(
|
|
44290
44343
|
node2.attributes,
|
|
44291
44344
|
template.fields,
|
|
44292
|
-
imageCallback
|
|
44345
|
+
imageCallback,
|
|
44346
|
+
context
|
|
44293
44347
|
);
|
|
44294
44348
|
const childField = template.fields.find(
|
|
44295
44349
|
(field2) => field2.name === "children"
|
|
@@ -44357,7 +44411,7 @@ var directiveElement = (node2, field, imageCallback, raw) => {
|
|
|
44357
44411
|
};
|
|
44358
44412
|
|
|
44359
44413
|
// src/parse/remarkToPlate.ts
|
|
44360
|
-
var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
44414
|
+
var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess, context) => {
|
|
44361
44415
|
const mdxJsxElement2 = skipMDXProcess ? (node2) => node2 : mdxJsxElement;
|
|
44362
44416
|
const content3 = (content4) => {
|
|
44363
44417
|
switch (content4.type) {
|
|
@@ -44408,7 +44462,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
44408
44462
|
case "paragraph":
|
|
44409
44463
|
return paragraph2(content4);
|
|
44410
44464
|
case "mdxJsxFlowElement":
|
|
44411
|
-
return mdxJsxElement2(content4, field, imageCallback);
|
|
44465
|
+
return mdxJsxElement2(content4, field, imageCallback, context);
|
|
44412
44466
|
case "thematicBreak":
|
|
44413
44467
|
return {
|
|
44414
44468
|
type: "hr",
|
|
@@ -44504,7 +44558,8 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
44504
44558
|
mdxJsxElement2(
|
|
44505
44559
|
{ ...child, type: "mdxJsxTextElement" },
|
|
44506
44560
|
field,
|
|
44507
|
-
imageCallback
|
|
44561
|
+
imageCallback,
|
|
44562
|
+
context
|
|
44508
44563
|
)
|
|
44509
44564
|
]
|
|
44510
44565
|
};
|
|
@@ -44617,7 +44672,7 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
44617
44672
|
const staticPhrasingContent = (content4) => {
|
|
44618
44673
|
switch (content4.type) {
|
|
44619
44674
|
case "mdxJsxTextElement":
|
|
44620
|
-
return mdxJsxElement2(content4, field, imageCallback);
|
|
44675
|
+
return mdxJsxElement2(content4, field, imageCallback, context);
|
|
44621
44676
|
case "text":
|
|
44622
44677
|
return text7(content4);
|
|
44623
44678
|
case "inlineCode":
|
|
@@ -44637,12 +44692,14 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
44637
44692
|
switch (content4.type) {
|
|
44638
44693
|
case "text":
|
|
44639
44694
|
return text7(content4);
|
|
44695
|
+
case "delete":
|
|
44696
|
+
return phrashingMark(content4);
|
|
44640
44697
|
case "link":
|
|
44641
44698
|
return link2(content4);
|
|
44642
44699
|
case "image":
|
|
44643
44700
|
return image2(content4);
|
|
44644
44701
|
case "mdxJsxTextElement":
|
|
44645
|
-
return mdxJsxElement2(content4, field, imageCallback);
|
|
44702
|
+
return mdxJsxElement2(content4, field, imageCallback, context);
|
|
44646
44703
|
case "emphasis":
|
|
44647
44704
|
return phrashingMark(content4);
|
|
44648
44705
|
case "strong":
|
|
@@ -44701,6 +44758,17 @@ var remarkToSlate = (root2, field, imageCallback, raw, skipMDXProcess) => {
|
|
|
44701
44758
|
});
|
|
44702
44759
|
break;
|
|
44703
44760
|
}
|
|
44761
|
+
case "delete": {
|
|
44762
|
+
const children = (0, import_lodash.default)(
|
|
44763
|
+
node2.children.map(
|
|
44764
|
+
(child) => phrashingMark(child, [...marks, "strikethrough"])
|
|
44765
|
+
)
|
|
44766
|
+
);
|
|
44767
|
+
children.forEach((child) => {
|
|
44768
|
+
accum.push(child);
|
|
44769
|
+
});
|
|
44770
|
+
break;
|
|
44771
|
+
}
|
|
44704
44772
|
case "strong": {
|
|
44705
44773
|
const children = (0, import_lodash.default)(
|
|
44706
44774
|
node2.children.map((child) => phrashingMark(child, [...marks, "bold"]))
|
|
@@ -44904,7 +44972,7 @@ var mdxToAst = (value) => {
|
|
|
44904
44972
|
return remark().use(remarkMdx).use(remarkGfm).parse(value);
|
|
44905
44973
|
};
|
|
44906
44974
|
var MDX_PARSE_ERROR_MSG = "TinaCMS supports a stricter version of markdown and a subset of MDX. https://tina.io/docs/editing/mdx/#differences-from-other-mdx-implementations";
|
|
44907
|
-
var parseMDX = (value, field, imageCallback) => {
|
|
44975
|
+
var parseMDX = (value, field, imageCallback, context) => {
|
|
44908
44976
|
if (!value) {
|
|
44909
44977
|
return { type: "root", children: [] };
|
|
44910
44978
|
}
|
|
@@ -44929,7 +44997,7 @@ var parseMDX = (value, field, imageCallback) => {
|
|
|
44929
44997
|
});
|
|
44930
44998
|
tree = mdxToAst(preprocessedString);
|
|
44931
44999
|
if (tree) {
|
|
44932
|
-
return remarkToSlate(tree, field, imageCallback, value);
|
|
45000
|
+
return remarkToSlate(tree, field, imageCallback, value, false, context);
|
|
44933
45001
|
} else {
|
|
44934
45002
|
return { type: "root", children: [] };
|
|
44935
45003
|
}
|
|
@@ -5,5 +5,3 @@ import type { RootElement } from '../../parse/plate';
|
|
|
5
5
|
export declare const preProcess: (tree: RootElement, field: RichTextField, imageCallback: (url: string) => string) => Md.Root;
|
|
6
6
|
export declare const rootElement: (content: Plate.RootElement, field: RichTextField, imageCallback: (url: string) => string) => Md.Root;
|
|
7
7
|
export declare const blockElement: (content: Plate.BlockElement, field: RichTextField, imageCallback: (url: string) => string) => Md.Content | null;
|
|
8
|
-
export type Marks = 'strong' | 'emphasis' | 'inlineCode';
|
|
9
|
-
export declare const getMarks: (content: Plate.InlineElement) => Marks[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export declare function removePosition(tree: any): any;
|
|
2
2
|
export declare const print: (tree: object) => string;
|
|
3
3
|
export declare const nodePath: (dir: string) => string;
|
|
4
|
+
export declare const contextPath: (dir: string) => string;
|
|
5
|
+
export declare const frontmatterContext: (contextMarkdown: string) => {
|
|
6
|
+
_tinaEmbeds?: Record<string, string> | null | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const frontmatterString: (context: object) => string;
|
|
4
9
|
export declare const mdPath: (dir: string) => string;
|
|
10
|
+
export declare const mdContextPath: (dir: string) => string;
|
package/dist/parse/acorn.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from 'mdast-util-mdx-jsx';
|
|
2
2
|
import type { TinaField } from '@tinacms/schema-tools';
|
|
3
|
-
export declare const extractAttributes: (attributes: (MdxJsxAttribute | MdxJsxExpressionAttribute)[], fields: TinaField[], imageCallback: (image: string) => string) => Record<string, unknown>;
|
|
3
|
+
export declare const extractAttributes: (attributes: (MdxJsxAttribute | MdxJsxExpressionAttribute)[], fields: TinaField[], imageCallback: (image: string) => string, context: Record<string, unknown> | undefined) => Record<string, unknown>;
|
|
4
4
|
export declare const trimFragments: (string: string) => string;
|
package/dist/parse/index.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export declare const markdownToAst: (value: string, field: RichTextType) => impo
|
|
|
59
59
|
export declare const mdxToAst: (value: string) => import("mdast").Root;
|
|
60
60
|
export declare const MDX_PARSE_ERROR_MSG = "TinaCMS supports a stricter version of markdown and a subset of MDX. https://tina.io/docs/editing/mdx/#differences-from-other-mdx-implementations";
|
|
61
61
|
export declare const MDX_PARSE_ERROR_MSG_HTML = "TinaCMS supports a stricter version of markdown and a subset of MDX. <a href=\"https://tina.io/docs/editing/mdx/#differences-from-other-mdx-implementations\" target=\"_blank\" rel=\"noopener noreferrer\">Learn More</a>";
|
|
62
|
-
export declare const parseMDX: (value: string, field: RichTextType, imageCallback: (s: string) => string
|
|
62
|
+
export declare const parseMDX: (value: string, field: RichTextType, imageCallback: (s: string) => string, context?: {
|
|
63
|
+
_tinaEmbeds?: Record<string, string> | null | undefined;
|
|
64
|
+
}) => Plate.RootElement;
|
|
63
65
|
export declare const invalidMarkdown: (e: RichTextParseError, value: string) => Plate.RootElement;
|
|
64
66
|
export declare const replaceAll: (string: string, target: string, value: string) => string;
|
package/dist/parse/mdx.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ import type { RichTextType } from '@tinacms/schema-tools';
|
|
|
8
8
|
import type * as Plate from './plate';
|
|
9
9
|
import { ContainerDirective } from 'mdast-util-directive';
|
|
10
10
|
import { LeafDirective } from 'mdast-util-directive/lib';
|
|
11
|
-
export declare function mdxJsxElement(node: MdxJsxTextElement, field: RichTextType, imageCallback: (url: string) => string): Plate.MdxInlineElement;
|
|
12
|
-
export declare function mdxJsxElement(node: MdxJsxFlowElement, field: RichTextType, imageCallback: (url: string) => string): Plate.MdxBlockElement;
|
|
11
|
+
export declare function mdxJsxElement(node: MdxJsxTextElement, field: RichTextType, imageCallback: (url: string) => string, context?: Record<string, unknown>): Plate.MdxInlineElement;
|
|
12
|
+
export declare function mdxJsxElement(node: MdxJsxFlowElement, field: RichTextType, imageCallback: (url: string) => string, context?: Record<string, unknown>): Plate.MdxBlockElement;
|
|
13
13
|
export declare const directiveElement: (node: ContainerDirective | LeafDirective, field: RichTextType, imageCallback: (url: string) => string, raw?: string) => Plate.BlockElement | Plate.ParagraphElement;
|
package/dist/parse/plate.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
export type RootElement = {
|
|
10
10
|
type: 'root';
|
|
11
11
|
children: BlockElement[];
|
|
12
|
+
embedCode?: string;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
* @group BlockElement
|
|
@@ -181,6 +182,7 @@ export type TextElement = {
|
|
|
181
182
|
bold?: boolean;
|
|
182
183
|
italic?: boolean;
|
|
183
184
|
code?: boolean;
|
|
185
|
+
strikethrough?: boolean;
|
|
184
186
|
};
|
|
185
187
|
/**
|
|
186
188
|
* @remarks
|
|
@@ -23,7 +23,7 @@ declare module 'mdast' {
|
|
|
23
23
|
mdxJsxFlowElement: MdxJsxFlowElement;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export declare const remarkToSlate: (root: Md.Root | MdxJsxFlowElement | MdxJsxTextElement | ContainerDirective, field: RichTextType, imageCallback: (url: string) => string, raw?: string, skipMDXProcess?: boolean) => Plate.RootElement;
|
|
26
|
+
export declare const remarkToSlate: (root: Md.Root | MdxJsxFlowElement | MdxJsxTextElement | ContainerDirective, field: RichTextType, imageCallback: (url: string) => string, raw?: string, skipMDXProcess?: boolean, context?: Record<string, unknown>) => Plate.RootElement;
|
|
27
27
|
export declare class RichTextParseError extends Error {
|
|
28
28
|
position?: Plate.Position;
|
|
29
29
|
constructor(message: string, position?: Plate.Position);
|
|
@@ -2,17 +2,17 @@ import type { RichTextField } from '@tinacms/schema-tools';
|
|
|
2
2
|
import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
|
|
3
3
|
import * as Plate from '../parse/plate';
|
|
4
4
|
import type * as Md from 'mdast';
|
|
5
|
-
export declare const stringifyPropsInline: (element: Plate.MdxInlineElement, field: RichTextField, imageCallback: (url: string) => string) => {
|
|
5
|
+
export declare const stringifyPropsInline: (element: Plate.MdxInlineElement, field: RichTextField, imageCallback: (url: string) => string, context?: Record<string, any>) => {
|
|
6
6
|
attributes: MdxJsxAttribute[];
|
|
7
7
|
children: Md.PhrasingContent[];
|
|
8
8
|
};
|
|
9
|
-
export declare function stringifyProps(element: Plate.MdxInlineElement, parentField: RichTextField, flatten: boolean, imageCallback: (url: string) => string): {
|
|
9
|
+
export declare function stringifyProps(element: Plate.MdxInlineElement, parentField: RichTextField, flatten: boolean, imageCallback: (url: string) => string, context: Record<string, any>): {
|
|
10
10
|
attributes: MdxJsxAttribute[];
|
|
11
11
|
children: Md.PhrasingContent[];
|
|
12
12
|
useDirective: boolean;
|
|
13
13
|
directiveType: string;
|
|
14
14
|
};
|
|
15
|
-
export declare function stringifyProps(element: Plate.MdxBlockElement, parentField: RichTextField, flatten: boolean, imageCallback: (url: string) => string): {
|
|
15
|
+
export declare function stringifyProps(element: Plate.MdxBlockElement, parentField: RichTextField, flatten: boolean, imageCallback: (url: string) => string, context: Record<string, any>): {
|
|
16
16
|
attributes: MdxJsxAttribute[];
|
|
17
17
|
children: Md.BlockContent[];
|
|
18
18
|
useDirective: boolean;
|
|
@@ -21,7 +21,7 @@ declare module 'mdast' {
|
|
|
21
21
|
mdxJsxFlowElement: MdxJsxFlowElement;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
export declare const stringifyMDX: (value: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string) => string | undefined;
|
|
24
|
+
export declare const stringifyMDX: (value: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string, context?: Record<string, any>) => string | undefined;
|
|
25
25
|
export type Pattern = {
|
|
26
26
|
start: string;
|
|
27
27
|
end: string;
|
|
@@ -30,7 +30,7 @@ export type Pattern = {
|
|
|
30
30
|
type: 'block' | 'leaf';
|
|
31
31
|
};
|
|
32
32
|
export declare const toTinaMarkdown: (tree: Md.Root, field: RichTextType) => string;
|
|
33
|
-
export declare const rootElement: (content: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string) => Md.Root;
|
|
34
|
-
export declare const blockElement: (content: Plate.BlockElement, field: RichTextType, imageCallback: (url: string) => string) => Md.Content | null;
|
|
35
|
-
export type Marks = 'strong' | 'emphasis' | 'inlineCode';
|
|
33
|
+
export declare const rootElement: (content: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string, context: Record<string, any>) => Md.Root;
|
|
34
|
+
export declare const blockElement: (content: Plate.BlockElement, field: RichTextType, imageCallback: (url: string) => string, context: Record<string, any>) => Md.Content | null;
|
|
35
|
+
export type Marks = 'strong' | 'emphasis' | 'inlineCode' | 'delete';
|
|
36
36
|
export declare const getMarks: (content: Plate.InlineElement) => Marks[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/mdx",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-899eda4-20250227042836",
|
|
4
4
|
"typings": "dist/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"browser": "dist/index.browser.mjs",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"unist-util-visit": "4.1.2",
|
|
57
57
|
"uvu": "0.5.6",
|
|
58
58
|
"vfile-message": "3.1.4",
|
|
59
|
-
"@tinacms/schema-tools": "
|
|
59
|
+
"@tinacms/schema-tools": "0.0.0-899eda4-20250227042836"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"registry": "https://registry.npmjs.org"
|
|
@@ -67,20 +67,25 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/estree": "1.0.0",
|
|
70
|
+
"@types/js-yaml": "^4.0.9",
|
|
70
71
|
"@types/lodash.flatten": "^4.4.9",
|
|
71
72
|
"@types/mdast": "^3.0.15",
|
|
72
|
-
"@types/node": "^22.
|
|
73
|
+
"@types/node": "^22.13.1",
|
|
73
74
|
"@types/prettier": "^2.7.3",
|
|
74
75
|
"@types/unist": "^2.0.11",
|
|
75
76
|
"c8": "^7.14.0",
|
|
76
77
|
"concat-md": "^0.5.1",
|
|
77
78
|
"jest-file-snapshot": "^0.5.0",
|
|
79
|
+
"js-yaml": "^4.1.0",
|
|
80
|
+
"mdast-util-frontmatter": "1.0.1",
|
|
81
|
+
"micromark-extension-frontmatter": "1.1.0",
|
|
78
82
|
"ts-node": "^10.9.2",
|
|
79
83
|
"typedoc-plugin-markdown": "^3.17.1",
|
|
80
|
-
"typescript": "^5.
|
|
81
|
-
"vite": "^4.5.
|
|
84
|
+
"typescript": "^5.7.3",
|
|
85
|
+
"vite": "^4.5.9",
|
|
82
86
|
"vitest": "^0.32.4",
|
|
83
|
-
"
|
|
87
|
+
"zod": "^3.23.8",
|
|
88
|
+
"@tinacms/scripts": "1.3.2"
|
|
84
89
|
},
|
|
85
90
|
"scripts": {
|
|
86
91
|
"types": "tsc",
|