@tinacms/mdx 1.3.1 → 1.3.3
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.es.js +2617 -1337
- package/dist/index.js +17417 -11526
- package/dist/next/index.d.ts +2 -0
- package/dist/next/parse/index.d.ts +2 -0
- package/dist/next/parse/markdown.d.ts +2 -0
- package/dist/next/parse/post-processing.d.ts +3 -0
- package/dist/next/shortcodes/index.d.ts +2 -0
- package/dist/next/shortcodes/lib/factory-tag.d.ts +4 -0
- package/dist/next/shortcodes/lib/jsx-flow.d.ts +3 -0
- package/dist/next/shortcodes/lib/jsx-text.d.ts +3 -0
- package/dist/next/shortcodes/lib/syntax.d.ts +17 -0
- package/dist/next/shortcodes/lib/util.d.ts +3 -0
- package/dist/next/shortcodes/mdast/index.d.ts +106 -0
- package/dist/next/stringify/acorn.d.ts +21 -0
- package/dist/next/stringify/index.d.ts +3 -0
- package/dist/next/stringify/marks.d.ts +8 -0
- package/dist/next/stringify/pre-processing.d.ts +9 -0
- package/dist/next/stringify/to-markdown.d.ts +3 -0
- package/dist/next/tests/block-level-1/field.d.ts +2 -0
- package/dist/next/tests/block-level-2/field.d.ts +2 -0
- package/dist/next/tests/block-level-2/index.test.d.ts +1 -0
- package/dist/next/tests/block-level-3/field.d.ts +2 -0
- package/dist/next/tests/block-level-3/index.test.d.ts +1 -0
- package/dist/next/tests/block-level-nested/field.d.ts +2 -0
- package/dist/next/tests/block-level-nested/index.test.d.ts +1 -0
- package/dist/next/tests/block-level-unclosed/field.d.ts +2 -0
- package/dist/next/tests/block-level-unclosed/index.test.d.ts +1 -0
- package/dist/next/tests/expressions-in-text/field.d.ts +2 -0
- package/dist/next/tests/expressions-in-text/index.test.d.ts +1 -0
- package/dist/next/tests/image-at-block-level/field.d.ts +2 -0
- package/dist/next/tests/image-at-block-level/index.test.d.ts +1 -0
- package/dist/next/tests/image-callback/field.d.ts +2 -0
- package/dist/next/tests/image-callback/index.test.d.ts +1 -0
- package/dist/next/tests/inline/field.d.ts +2 -0
- package/dist/next/tests/inline/index.test.d.ts +1 -0
- package/dist/next/tests/inline-with-children/field.d.ts +2 -0
- package/dist/next/tests/inline-with-children/index.test.d.ts +1 -0
- package/dist/next/tests/invalid/field.d.ts +2 -0
- package/dist/next/tests/invalid/index.test.d.ts +1 -0
- package/dist/next/tests/invalid-2/field.d.ts +2 -0
- package/dist/next/tests/invalid-2/index.test.d.ts +1 -0
- package/dist/next/tests/invalid-3/field.d.ts +2 -0
- package/dist/next/tests/invalid-3/index.test.d.ts +1 -0
- package/dist/next/tests/invalid-4/field.d.ts +2 -0
- package/dist/next/tests/invalid-4/index.test.d.ts +1 -0
- package/dist/next/tests/lists/field.d.ts +2 -0
- package/dist/next/tests/lists/index.test.d.ts +1 -0
- package/dist/next/tests/markdoc/field.d.ts +2 -0
- package/dist/next/tests/markdoc/index.test.d.ts +1 -0
- package/dist/next/tests/unrecognized-shortcodes/field.d.ts +2 -0
- package/dist/next/tests/unrecognized-shortcodes/index.test.d.ts +1 -0
- package/dist/next/tests/util.d.ts +4 -0
- package/dist/next/tests/wordpress-style/field.d.ts +2 -0
- package/dist/next/tests/wordpress-style/index.test.d.ts +1 -0
- package/dist/next/tests/wordpress-style-2/field.d.ts +2 -0
- package/dist/next/tests/wordpress-style-2/index.test.d.ts +1 -0
- package/dist/next/tests/wordpress-style-2-block-with-children/field.d.ts +2 -0
- package/dist/next/tests/wordpress-style-2-block-with-children/index.test.d.ts +1 -0
- package/dist/next/tests/wordpress-style-2-with-children/field.d.ts +2 -0
- package/dist/next/tests/wordpress-style-2-with-children/index.test.d.ts +1 -0
- package/dist/next/util.d.ts +3 -0
- package/dist/parse/acorn.d.ts +2 -2
- package/dist/parse/index.d.ts +3 -3
- package/dist/parse/mdx.d.ts +4 -4
- package/dist/parse/parseShortcode.d.ts +2 -4
- package/dist/parse/remarkToPlate.d.ts +2 -2
- package/dist/stringify/acorn.d.ts +4 -4
- package/dist/stringify/index.d.ts +5 -5
- package/dist/stringify/marks.d.ts +2 -2
- package/dist/stringify/stringifyShortcode.d.ts +2 -4
- package/dist/tests/autotest/_config.d.ts +2 -2
- package/dist/tests/setup.d.ts +4 -4
- package/package.json +54 -48
- /package/dist/{tests/temp/shortcodes.test.d.ts → next/tests/block-level-1/index.test.d.ts} +0 -0
package/dist/index.es.js
CHANGED
|
@@ -8,210 +8,504 @@ var __publicField = (obj, key, value) => {
|
|
|
8
8
|
// src/parse/index.ts
|
|
9
9
|
import { remark } from "remark";
|
|
10
10
|
import remarkMdx from "remark-mdx";
|
|
11
|
-
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
12
11
|
|
|
13
|
-
// src/
|
|
14
|
-
import {
|
|
12
|
+
// src/next/stringify/to-markdown.ts
|
|
13
|
+
import { toMarkdown } from "mdast-util-to-markdown";
|
|
14
|
+
import { text } from "mdast-util-to-markdown/lib/handle/text";
|
|
15
15
|
|
|
16
|
-
// src/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
// src/next/shortcodes/mdast/index.ts
|
|
17
|
+
import { ccount } from "ccount";
|
|
18
|
+
import { parseEntities } from "parse-entities";
|
|
19
|
+
import { stringifyPosition } from "unist-util-stringify-position";
|
|
20
|
+
import { VFileMessage } from "vfile-message";
|
|
21
|
+
import { stringifyEntitiesLight } from "stringify-entities";
|
|
22
|
+
import { containerFlow } from "mdast-util-to-markdown/lib/util/container-flow.js";
|
|
23
|
+
import { containerPhrasing } from "mdast-util-to-markdown/lib/util/container-phrasing.js";
|
|
24
|
+
import { indentLines } from "mdast-util-to-markdown/lib/util/indent-lines.js";
|
|
25
|
+
import { track } from "mdast-util-to-markdown/lib/util/track.js";
|
|
26
|
+
function mdxJsxFromMarkdown({ patterns }) {
|
|
27
|
+
const buffer = function() {
|
|
28
|
+
this.buffer();
|
|
29
|
+
};
|
|
30
|
+
const data = function(token) {
|
|
31
|
+
this.config?.enter?.data?.call(this, token);
|
|
32
|
+
this.config?.exit?.data?.call(this, token);
|
|
33
|
+
};
|
|
34
|
+
const enterMdxJsxTag = function(token) {
|
|
35
|
+
const tag = {
|
|
36
|
+
name: void 0,
|
|
37
|
+
attributes: [],
|
|
38
|
+
close: false,
|
|
39
|
+
selfClosing: false,
|
|
40
|
+
start: token.start,
|
|
41
|
+
end: token.end
|
|
42
|
+
};
|
|
43
|
+
if (!this.getData("mdxJsxTagStack"))
|
|
44
|
+
this.setData("mdxJsxTagStack", []);
|
|
45
|
+
this.setData("mdxJsxTag", tag);
|
|
46
|
+
this.buffer();
|
|
47
|
+
};
|
|
48
|
+
const enterMdxJsxTagClosingMarker = function(token) {
|
|
49
|
+
const stack = this.getData("mdxJsxTagStack");
|
|
50
|
+
const tag = this.getData("mdxJsxTag");
|
|
51
|
+
if (stack?.length === 0) {
|
|
52
|
+
if (tag) {
|
|
53
|
+
tag.shouldFallback = true;
|
|
30
54
|
}
|
|
31
|
-
throw e;
|
|
32
55
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
};
|
|
57
|
+
const enterMdxJsxTagAnyAttribute = function(token) {
|
|
58
|
+
const tag = this.getData("mdxJsxTag");
|
|
59
|
+
};
|
|
60
|
+
const enterMdxJsxTagSelfClosingMarker = function(token) {
|
|
61
|
+
const tag = this.getData("mdxJsxTag");
|
|
62
|
+
if (tag?.close) {
|
|
63
|
+
throw new VFileMessage(
|
|
64
|
+
"Unexpected self-closing slash `/` in closing tag, expected the end of the tag",
|
|
65
|
+
{ start: token.start, end: token.end },
|
|
66
|
+
"mdast-util-mdx-jsx:unexpected-self-closing-slash"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const exitMdxJsxTagClosingMarker = function() {
|
|
71
|
+
const tag = this.getData("mdxJsxTag");
|
|
72
|
+
if (tag) {
|
|
73
|
+
tag.close = true;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const exitMdxJsxTagNamePrimary = function(token) {
|
|
77
|
+
const tag = this.getData("mdxJsxTag");
|
|
78
|
+
if (tag) {
|
|
79
|
+
tag.name = this.sliceSerialize(token);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const exitMdxJsxTagNameMember = function(token) {
|
|
83
|
+
const tag = this.getData("mdxJsxTag");
|
|
84
|
+
if (tag) {
|
|
85
|
+
tag.name += "." + this.sliceSerialize(token);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const exitMdxJsxTagNameLocal = function(token) {
|
|
89
|
+
const tag = this.getData("mdxJsxTag");
|
|
90
|
+
if (tag) {
|
|
91
|
+
tag.name += ":" + this.sliceSerialize(token);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const enterMdxJsxTagAttribute = function(token) {
|
|
95
|
+
const tag = this.getData("mdxJsxTag");
|
|
96
|
+
enterMdxJsxTagAnyAttribute.call(this, token);
|
|
97
|
+
if (tag) {
|
|
98
|
+
tag.attributes.push({ type: "mdxJsxAttribute", name: "", value: null });
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const enterMdxJsxTagExpressionAttribute = function(token) {
|
|
102
|
+
const tag = this.getData("mdxJsxTag");
|
|
103
|
+
enterMdxJsxTagAnyAttribute.call(this, token);
|
|
104
|
+
if (tag) {
|
|
105
|
+
tag.attributes.push({ type: "mdxJsxExpressionAttribute", value: "" });
|
|
106
|
+
}
|
|
107
|
+
this.buffer();
|
|
108
|
+
};
|
|
109
|
+
const exitMdxJsxTagExpressionAttribute = function(token) {
|
|
110
|
+
const tag = this.getData("mdxJsxTag");
|
|
111
|
+
if (tag) {
|
|
112
|
+
const tail = tag.attributes[tag.attributes.length - 1];
|
|
113
|
+
const estree = token.estree;
|
|
114
|
+
if (tail) {
|
|
115
|
+
tail.value = this.resume();
|
|
116
|
+
if (estree) {
|
|
117
|
+
tail.data = { estree };
|
|
118
|
+
}
|
|
47
119
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const exitMdxJsxTagAttributeNamePrimary = function(token) {
|
|
123
|
+
const tag = this.getData("mdxJsxTag");
|
|
124
|
+
if (tag) {
|
|
125
|
+
const node = tag.attributes[tag.attributes.length - 1];
|
|
126
|
+
if (node) {
|
|
127
|
+
node.name = this.sliceSerialize(token);
|
|
55
128
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const exitMdxJsxTagAttributeNameLocal = function(token) {
|
|
132
|
+
const tag = this.getData("mdxJsxTag");
|
|
133
|
+
if (tag) {
|
|
134
|
+
const node = tag.attributes[tag.attributes.length - 1];
|
|
135
|
+
if (node) {
|
|
136
|
+
node.name += ":" + this.sliceSerialize(token);
|
|
61
137
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const exitMdxJsxTagAttributeValueLiteral = function() {
|
|
141
|
+
const tag = this.getData("mdxJsxTag");
|
|
142
|
+
if (tag) {
|
|
143
|
+
const attribute = tag.attributes[tag.attributes.length - 1];
|
|
144
|
+
if (attribute) {
|
|
145
|
+
if (attribute.name === "") {
|
|
146
|
+
attribute.name = "_value";
|
|
147
|
+
}
|
|
148
|
+
attribute.value = parseEntities(this.resume(), { nonTerminated: false });
|
|
70
149
|
}
|
|
71
|
-
default:
|
|
72
|
-
throw new Error(`Extract attribute: Unhandled field type ${field.type}`);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var extractScalar = (attribute, field) => {
|
|
76
|
-
if (field.list) {
|
|
77
|
-
assertType(attribute.expression, "ArrayExpression");
|
|
78
|
-
return attribute.expression.elements.map((element) => {
|
|
79
|
-
assertHasType(element);
|
|
80
|
-
assertType(element, "Literal");
|
|
81
|
-
return element.value;
|
|
82
|
-
});
|
|
83
|
-
} else {
|
|
84
|
-
assertType(attribute.expression, "Literal");
|
|
85
|
-
return attribute.expression.value;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
var extractObject = (attribute, field) => {
|
|
89
|
-
if (field.list) {
|
|
90
|
-
assertType(attribute.expression, "ArrayExpression");
|
|
91
|
-
return attribute.expression.elements.map((element) => {
|
|
92
|
-
assertHasType(element);
|
|
93
|
-
assertType(element, "ObjectExpression");
|
|
94
|
-
return extractObjectExpression(element, field);
|
|
95
|
-
});
|
|
96
|
-
} else {
|
|
97
|
-
assertType(attribute.expression, "ObjectExpression");
|
|
98
|
-
return extractObjectExpression(attribute.expression, field);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var extractObjectExpression = (expression, field) => {
|
|
102
|
-
const properties = {};
|
|
103
|
-
expression.properties?.forEach((property) => {
|
|
104
|
-
assertType(property, "Property");
|
|
105
|
-
const { key, value } = extractKeyValue(property, field);
|
|
106
|
-
properties[key] = value;
|
|
107
|
-
});
|
|
108
|
-
return properties;
|
|
109
|
-
};
|
|
110
|
-
var getField = (objectField, name) => {
|
|
111
|
-
if (objectField.fields) {
|
|
112
|
-
if (typeof objectField.fields === "string") {
|
|
113
|
-
throw new Error("Global templates not supported");
|
|
114
150
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return extractObjectExpression(element, field);
|
|
129
|
-
});
|
|
130
|
-
return { key, value };
|
|
131
|
-
} else {
|
|
132
|
-
assertType(property.value, "ObjectExpression");
|
|
133
|
-
const value = extractObjectExpression(property.value, field);
|
|
134
|
-
return { key, value };
|
|
151
|
+
};
|
|
152
|
+
const exitMdxJsxTagAttributeValueExpression = function(token) {
|
|
153
|
+
const tag = this.getData("mdxJsxTag");
|
|
154
|
+
if (!tag)
|
|
155
|
+
return;
|
|
156
|
+
const tail = tag.attributes[tag.attributes.length - 1];
|
|
157
|
+
const node = {
|
|
158
|
+
type: "mdxJsxAttributeValueExpression",
|
|
159
|
+
value: this.resume()
|
|
160
|
+
};
|
|
161
|
+
const estree = token.estree;
|
|
162
|
+
if (estree) {
|
|
163
|
+
node.data = { estree };
|
|
135
164
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return { key, value: property.value.value };
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
var extractStatement = (attribute) => {
|
|
142
|
-
const body = attribute.data?.estree?.body;
|
|
143
|
-
if (body) {
|
|
144
|
-
if (body[0]) {
|
|
145
|
-
assertType(body[0], "ExpressionStatement");
|
|
146
|
-
return body[0];
|
|
165
|
+
if (tail) {
|
|
166
|
+
tail.value = node;
|
|
147
167
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (typeof attribute.value === "string") {
|
|
154
|
-
return attribute.value;
|
|
168
|
+
};
|
|
169
|
+
const exitMdxJsxTagSelfClosingMarker = function() {
|
|
170
|
+
const tag = this.getData("mdxJsxTag");
|
|
171
|
+
if (tag) {
|
|
172
|
+
tag.selfClosing = true;
|
|
155
173
|
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
assertHasType(attribute.value);
|
|
162
|
-
assertType(attribute.value, "mdxJsxAttributeValueExpression");
|
|
163
|
-
return extractStatement(attribute.value);
|
|
164
|
-
};
|
|
165
|
-
var extractRaw = (attribute) => {
|
|
166
|
-
assertType(attribute, "mdxJsxAttribute");
|
|
167
|
-
assertHasType(attribute.value);
|
|
168
|
-
assertType(attribute.value, "mdxJsxAttributeValueExpression");
|
|
169
|
-
const rawValue = attribute.value.value;
|
|
170
|
-
return trimFragments(rawValue);
|
|
171
|
-
};
|
|
172
|
-
function assertType(val, type) {
|
|
173
|
-
if (val.type !== type) {
|
|
174
|
-
throw new Error(`Expected type to be ${type} but received ${val.type}. ${MDX_PARSE_ERROR_MSG}`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function assertHasType(val) {
|
|
178
|
-
if (val) {
|
|
179
|
-
if (typeof val !== "string") {
|
|
174
|
+
};
|
|
175
|
+
const exitMdxJsxTag = function(token) {
|
|
176
|
+
const tag = this.getData("mdxJsxTag");
|
|
177
|
+
const stack = this.getData("mdxJsxTagStack");
|
|
178
|
+
if (!stack)
|
|
180
179
|
return;
|
|
180
|
+
const tail = stack[stack.length - 1];
|
|
181
|
+
if (!tag)
|
|
182
|
+
return;
|
|
183
|
+
if (tail && tag.close && tail.name !== tag.name) {
|
|
184
|
+
throw new VFileMessage(
|
|
185
|
+
"Unexpected closing tag `" + serializeAbbreviatedTag(tag) + "`, expected corresponding closing tag for `" + serializeAbbreviatedTag(tail) + "` (" + stringifyPosition(tail) + ")",
|
|
186
|
+
{ start: token.start, end: token.end },
|
|
187
|
+
"mdast-util-mdx-jsx:end-tag-mismatch"
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
this.resume();
|
|
191
|
+
if (tag.close) {
|
|
192
|
+
stack.pop();
|
|
193
|
+
} else {
|
|
194
|
+
const pattern = patterns.find((pattern2) => pattern2.name === tag.name);
|
|
195
|
+
const tagName = pattern?.templateName || tag.name;
|
|
196
|
+
this.enter(
|
|
197
|
+
{
|
|
198
|
+
type: token.type === "mdxJsxTextTag" ? "mdxJsxTextElement" : "mdxJsxFlowElement",
|
|
199
|
+
name: tagName || null,
|
|
200
|
+
attributes: tag.attributes,
|
|
201
|
+
children: []
|
|
202
|
+
},
|
|
203
|
+
token,
|
|
204
|
+
(left, right) => {
|
|
205
|
+
this.exit(right);
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
if (tag.selfClosing || tag.close) {
|
|
210
|
+
if (tag.shouldFallback) {
|
|
211
|
+
if (token.type === "mdxJsxFlowTag") {
|
|
212
|
+
this.enter(
|
|
213
|
+
{
|
|
214
|
+
type: "paragraph",
|
|
215
|
+
children: [{ type: "text", value: this.sliceSerialize(token) }]
|
|
216
|
+
},
|
|
217
|
+
token
|
|
218
|
+
);
|
|
219
|
+
this.exit(token);
|
|
220
|
+
} else {
|
|
221
|
+
this.enter(
|
|
222
|
+
{
|
|
223
|
+
type: "text",
|
|
224
|
+
value: this.sliceSerialize(token)
|
|
225
|
+
},
|
|
226
|
+
token
|
|
227
|
+
);
|
|
228
|
+
this.exit(token);
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
this.exit(token, onErrorLeftIsTag);
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
stack.push(tag);
|
|
181
235
|
}
|
|
236
|
+
};
|
|
237
|
+
const onErrorRightIsTag = function(closing, open) {
|
|
238
|
+
const tag = this.getData("mdxJsxTag");
|
|
239
|
+
if (!tag)
|
|
240
|
+
return;
|
|
241
|
+
const place = closing ? " before the end of `" + closing.type + "`" : "";
|
|
242
|
+
const position = closing ? { start: closing.start, end: closing.end } : void 0;
|
|
243
|
+
throw new VFileMessage(
|
|
244
|
+
"Expected a closing tag for `" + serializeAbbreviatedTag(tag) + "` (" + stringifyPosition({ start: open.start, end: open.end }) + ")" + place,
|
|
245
|
+
position,
|
|
246
|
+
"mdast-util-mdx-jsx:end-tag-mismatch"
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
const onErrorLeftIsTag = function(a, b) {
|
|
250
|
+
const tag = this.getData("mdxJsxTag");
|
|
251
|
+
};
|
|
252
|
+
function serializeAbbreviatedTag(tag) {
|
|
253
|
+
return "<" + (tag.close ? "/" : "") + (tag.name || "") + ">";
|
|
182
254
|
}
|
|
183
|
-
|
|
255
|
+
return {
|
|
256
|
+
canContainEols: ["mdxJsxTextElement"],
|
|
257
|
+
enter: {
|
|
258
|
+
mdxJsxFlowTag: enterMdxJsxTag,
|
|
259
|
+
mdxJsxFlowTagClosingMarker: enterMdxJsxTagClosingMarker,
|
|
260
|
+
mdxJsxFlowTagAttribute: enterMdxJsxTagAttribute,
|
|
261
|
+
mdxJsxFlowTagExpressionAttribute: enterMdxJsxTagExpressionAttribute,
|
|
262
|
+
mdxJsxFlowTagAttributeValueLiteral: buffer,
|
|
263
|
+
mdxJsxFlowTagAttributeValueExpression: buffer,
|
|
264
|
+
mdxJsxFlowTagSelfClosingMarker: enterMdxJsxTagSelfClosingMarker,
|
|
265
|
+
mdxJsxTextTag: enterMdxJsxTag,
|
|
266
|
+
mdxJsxTextTagClosingMarker: enterMdxJsxTagClosingMarker,
|
|
267
|
+
mdxJsxTextTagAttribute: enterMdxJsxTagAttribute,
|
|
268
|
+
mdxJsxTextTagExpressionAttribute: enterMdxJsxTagExpressionAttribute,
|
|
269
|
+
mdxJsxTextTagAttributeValueLiteral: buffer,
|
|
270
|
+
mdxJsxTextTagAttributeValueExpression: buffer,
|
|
271
|
+
mdxJsxTextTagSelfClosingMarker: enterMdxJsxTagSelfClosingMarker
|
|
272
|
+
},
|
|
273
|
+
exit: {
|
|
274
|
+
mdxJsxFlowTagClosingMarker: exitMdxJsxTagClosingMarker,
|
|
275
|
+
mdxJsxFlowTagNamePrimary: exitMdxJsxTagNamePrimary,
|
|
276
|
+
mdxJsxFlowTagNameMember: exitMdxJsxTagNameMember,
|
|
277
|
+
mdxJsxFlowTagNameLocal: exitMdxJsxTagNameLocal,
|
|
278
|
+
mdxJsxFlowTagExpressionAttribute: exitMdxJsxTagExpressionAttribute,
|
|
279
|
+
mdxJsxFlowTagExpressionAttributeValue: data,
|
|
280
|
+
mdxJsxFlowTagAttributeNamePrimary: exitMdxJsxTagAttributeNamePrimary,
|
|
281
|
+
mdxJsxFlowTagAttributeNameLocal: exitMdxJsxTagAttributeNameLocal,
|
|
282
|
+
mdxJsxFlowTagAttributeValueLiteral: exitMdxJsxTagAttributeValueLiteral,
|
|
283
|
+
mdxJsxFlowTagAttributeValueLiteralValue: data,
|
|
284
|
+
mdxJsxFlowTagAttributeValueExpression: exitMdxJsxTagAttributeValueExpression,
|
|
285
|
+
mdxJsxFlowTagAttributeValueExpressionValue: data,
|
|
286
|
+
mdxJsxFlowTagSelfClosingMarker: exitMdxJsxTagSelfClosingMarker,
|
|
287
|
+
mdxJsxFlowTag: exitMdxJsxTag,
|
|
288
|
+
mdxJsxTextTagClosingMarker: exitMdxJsxTagClosingMarker,
|
|
289
|
+
mdxJsxTextTagNamePrimary: exitMdxJsxTagNamePrimary,
|
|
290
|
+
mdxJsxTextTagNameMember: exitMdxJsxTagNameMember,
|
|
291
|
+
mdxJsxTextTagNameLocal: exitMdxJsxTagNameLocal,
|
|
292
|
+
mdxJsxTextTagExpressionAttribute: exitMdxJsxTagExpressionAttribute,
|
|
293
|
+
mdxJsxTextTagExpressionAttributeValue: data,
|
|
294
|
+
mdxJsxTextTagAttributeNamePrimary: exitMdxJsxTagAttributeNamePrimary,
|
|
295
|
+
mdxJsxTextTagAttributeNameLocal: exitMdxJsxTagAttributeNameLocal,
|
|
296
|
+
mdxJsxTextTagAttributeValueLiteral: exitMdxJsxTagAttributeValueLiteral,
|
|
297
|
+
mdxJsxTextTagAttributeValueLiteralValue: data,
|
|
298
|
+
mdxJsxTextTagAttributeValueExpression: exitMdxJsxTagAttributeValueExpression,
|
|
299
|
+
mdxJsxTextTagAttributeValueExpressionValue: data,
|
|
300
|
+
mdxJsxTextTagSelfClosingMarker: exitMdxJsxTagSelfClosingMarker,
|
|
301
|
+
mdxJsxTextTag: exitMdxJsxTag
|
|
302
|
+
}
|
|
303
|
+
};
|
|
184
304
|
}
|
|
185
|
-
var
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
305
|
+
var mdxJsxToMarkdown = function(options) {
|
|
306
|
+
const patterns = options.patterns || [];
|
|
307
|
+
const options_ = options || {};
|
|
308
|
+
const quote = options_.quote || '"';
|
|
309
|
+
const quoteSmart = options_.quoteSmart || false;
|
|
310
|
+
const tightSelfClosing = options_.tightSelfClosing || false;
|
|
311
|
+
const printWidth = options_.printWidth || Number.POSITIVE_INFINITY;
|
|
312
|
+
const alternative = quote === '"' ? "'" : '"';
|
|
313
|
+
if (quote !== '"' && quote !== "'") {
|
|
314
|
+
throw new Error(
|
|
315
|
+
"Cannot serialize attribute values with `" + quote + "` for `options.quote`, expected `\"`, or `'`"
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
const mdxElement = function(node, _, context, safeOptions) {
|
|
319
|
+
const pattern = patterns.find((p) => p.templateName === node.name);
|
|
320
|
+
if (!pattern) {
|
|
321
|
+
return "";
|
|
322
|
+
}
|
|
323
|
+
const patternName = pattern.name || pattern?.templateName;
|
|
324
|
+
const tracker = track(safeOptions);
|
|
325
|
+
const selfClosing = pattern.leaf;
|
|
326
|
+
const exit = context.enter(node.type);
|
|
327
|
+
let index = -1;
|
|
328
|
+
const serializedAttributes = [];
|
|
329
|
+
let value = tracker.move(pattern.start + " " + (patternName || ""));
|
|
330
|
+
if (node.attributes && node.attributes.length > 0) {
|
|
331
|
+
if (!node.name) {
|
|
332
|
+
throw new Error("Cannot serialize fragment w/ attributes");
|
|
333
|
+
}
|
|
334
|
+
while (++index < node.attributes.length) {
|
|
335
|
+
const attribute = node.attributes[index];
|
|
336
|
+
let result;
|
|
337
|
+
if (attribute?.type === "mdxJsxExpressionAttribute") {
|
|
338
|
+
result = "{" + (attribute.value || "") + "}";
|
|
339
|
+
} else {
|
|
340
|
+
if (!attribute?.name) {
|
|
341
|
+
throw new Error("Cannot serialize attribute w/o name");
|
|
342
|
+
}
|
|
343
|
+
const value2 = attribute.value;
|
|
344
|
+
const left = attribute.name;
|
|
345
|
+
let right = "";
|
|
346
|
+
if (value2 === void 0 || value2 === null) {
|
|
347
|
+
} else if (typeof value2 === "object") {
|
|
348
|
+
right = "{" + (value2.value || "") + "}";
|
|
349
|
+
} else {
|
|
350
|
+
const appliedQuote = quoteSmart && ccount(value2, quote) > ccount(value2, alternative) ? alternative : quote;
|
|
351
|
+
right = appliedQuote + stringifyEntitiesLight(value2, { subset: [appliedQuote] }) + appliedQuote;
|
|
352
|
+
}
|
|
353
|
+
if (left === "_value") {
|
|
354
|
+
result = right;
|
|
355
|
+
} else {
|
|
356
|
+
result = left + (right ? "=" : "") + right;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
serializedAttributes.push(result);
|
|
193
360
|
}
|
|
194
361
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
362
|
+
let attributesOnTheirOwnLine = false;
|
|
363
|
+
const attributesOnOneLine = serializedAttributes.join(" ");
|
|
364
|
+
if (node.type === "mdxJsxFlowElement" && (/\r?\n|\r/.test(attributesOnOneLine) || tracker.current().now.column + attributesOnOneLine.length + (selfClosing ? tightSelfClosing ? 2 : 3 : 1) > printWidth)) {
|
|
365
|
+
attributesOnTheirOwnLine = true;
|
|
366
|
+
}
|
|
367
|
+
if (attributesOnTheirOwnLine) {
|
|
368
|
+
value += tracker.move(
|
|
369
|
+
"\n" + indentLines(serializedAttributes.join("\n"), map)
|
|
370
|
+
);
|
|
371
|
+
} else if (attributesOnOneLine) {
|
|
372
|
+
value += tracker.move(" " + attributesOnOneLine);
|
|
373
|
+
}
|
|
374
|
+
if (attributesOnTheirOwnLine) {
|
|
375
|
+
value += tracker.move("\n");
|
|
376
|
+
}
|
|
377
|
+
if (selfClosing) {
|
|
378
|
+
value += tracker.move(
|
|
379
|
+
tightSelfClosing || attributesOnTheirOwnLine ? "" : ""
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
value += tracker.move(" " + pattern.end);
|
|
383
|
+
if (node.children) {
|
|
384
|
+
if (node.type === "mdxJsxFlowElement") {
|
|
385
|
+
const emptyChildren = node.children.length === 1 && node.children[0]?.type === "paragraph" && node.children[0].children[0]?.type === "text" && node.children[0].children[0].value === "";
|
|
386
|
+
if (!emptyChildren) {
|
|
387
|
+
tracker.shift(2);
|
|
388
|
+
value += tracker.move("\n");
|
|
389
|
+
value += tracker.move(containerFlow(node, context, tracker.current()));
|
|
390
|
+
value += tracker.move("\n");
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
value += tracker.move(
|
|
394
|
+
containerPhrasing(node, context, {
|
|
395
|
+
...tracker.current(),
|
|
396
|
+
before: "<",
|
|
397
|
+
after: ">"
|
|
398
|
+
})
|
|
399
|
+
);
|
|
201
400
|
}
|
|
202
401
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
402
|
+
if (!selfClosing) {
|
|
403
|
+
value += tracker.move(
|
|
404
|
+
pattern.start + " /" + (patternName || " ") + " " + pattern.end
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
exit();
|
|
408
|
+
return value;
|
|
409
|
+
};
|
|
410
|
+
const map = function(line, _, blank) {
|
|
411
|
+
return (blank ? "" : " ") + line;
|
|
412
|
+
};
|
|
413
|
+
const peekElement = function() {
|
|
414
|
+
return "<";
|
|
415
|
+
};
|
|
416
|
+
mdxElement.peek = peekElement;
|
|
417
|
+
return {
|
|
418
|
+
...options,
|
|
419
|
+
handlers: {
|
|
420
|
+
mdxJsxFlowElement: mdxElement,
|
|
421
|
+
mdxJsxTextElement: mdxElement
|
|
422
|
+
},
|
|
423
|
+
unsafe: [
|
|
424
|
+
{ character: "<", inConstruct: ["phrasing"] },
|
|
425
|
+
{ atBreak: true, character: "<" }
|
|
426
|
+
],
|
|
427
|
+
fences: true,
|
|
428
|
+
resourceLink: true
|
|
429
|
+
};
|
|
206
430
|
};
|
|
207
431
|
|
|
208
|
-
// src/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
432
|
+
// src/next/util.ts
|
|
433
|
+
var getFieldPatterns = (field) => {
|
|
434
|
+
const patterns = [];
|
|
435
|
+
const templates = [];
|
|
436
|
+
hoistAllTemplates(field, templates);
|
|
437
|
+
templates?.forEach((template) => {
|
|
438
|
+
if (typeof template === "string") {
|
|
439
|
+
throw new Error("Global templates not supported");
|
|
440
|
+
}
|
|
441
|
+
if (template.match) {
|
|
442
|
+
patterns.push({
|
|
443
|
+
start: template.match.start,
|
|
444
|
+
end: template.match.end,
|
|
445
|
+
name: template.match.name || template.name,
|
|
446
|
+
templateName: template.name,
|
|
447
|
+
type: template.inline ? "inline" : "flow",
|
|
448
|
+
leaf: !template.fields.some((f) => f.name === "children")
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
return patterns;
|
|
453
|
+
};
|
|
454
|
+
var hoistAllTemplates = (field, templates = []) => {
|
|
455
|
+
field.templates?.forEach((template) => {
|
|
456
|
+
if (typeof template === "string") {
|
|
457
|
+
throw new Error("Global templates not supported");
|
|
458
|
+
}
|
|
459
|
+
templates.push(template);
|
|
460
|
+
template.fields.forEach((field2) => {
|
|
461
|
+
if (field2.type === "rich-text") {
|
|
462
|
+
hoistAllTemplates(field2, templates);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
return templates;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/next/stringify/to-markdown.ts
|
|
470
|
+
var toTinaMarkdown = (tree, field) => {
|
|
471
|
+
const patterns = getFieldPatterns(field);
|
|
472
|
+
const handlers = {};
|
|
473
|
+
handlers["text"] = (node, parent, context, safeOptions) => {
|
|
474
|
+
context.unsafe = context.unsafe.filter((unsafeItem) => {
|
|
475
|
+
if (unsafeItem.character === " " && unsafeItem.inConstruct === "phrasing") {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
});
|
|
480
|
+
if (field.parser?.type === "markdown") {
|
|
481
|
+
if (field.parser.skipEscaping === "all") {
|
|
482
|
+
return node.value;
|
|
483
|
+
}
|
|
484
|
+
if (field.parser.skipEscaping === "html") {
|
|
485
|
+
context.unsafe = context.unsafe.filter((unsafeItem) => {
|
|
486
|
+
if (unsafeItem.character === "<") {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
return true;
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return text(node, parent, context, safeOptions);
|
|
494
|
+
};
|
|
495
|
+
return toMarkdown(tree, {
|
|
496
|
+
extensions: [mdxJsxToMarkdown({ patterns })],
|
|
497
|
+
listItemIndent: "one",
|
|
498
|
+
handlers
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/stringify/index.ts
|
|
503
|
+
import { toMarkdown as toMarkdown2 } from "mdast-util-to-markdown";
|
|
504
|
+
import { text as text3 } from "mdast-util-to-markdown/lib/handle/text";
|
|
505
|
+
import {
|
|
506
|
+
mdxJsxToMarkdown as mdxJsxToMarkdown2
|
|
507
|
+
} from "mdast-util-mdx-jsx";
|
|
508
|
+
|
|
215
509
|
// src/stringify/acorn.ts
|
|
216
510
|
import { format } from "prettier";
|
|
217
511
|
var stringifyPropsInline = (element, field, imageCallback) => {
|
|
@@ -297,7 +591,9 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
297
591
|
value
|
|
298
592
|
});
|
|
299
593
|
} else {
|
|
300
|
-
throw new Error(
|
|
594
|
+
throw new Error(
|
|
595
|
+
`Expected string for attribute on field ${field.name}`
|
|
596
|
+
);
|
|
301
597
|
}
|
|
302
598
|
}
|
|
303
599
|
break;
|
|
@@ -357,14 +653,20 @@ function stringifyProps(element, parentField, flatten2, imageCallback) {
|
|
|
357
653
|
break;
|
|
358
654
|
case "rich-text":
|
|
359
655
|
if (typeof value === "string") {
|
|
360
|
-
throw new Error(
|
|
656
|
+
throw new Error(
|
|
657
|
+
`Unexpected string for rich-text, ensure the value has been properly parsed`
|
|
658
|
+
);
|
|
361
659
|
}
|
|
362
660
|
if (field.list) {
|
|
363
661
|
throw new Error(`Rich-text list is not supported`);
|
|
364
662
|
} else {
|
|
365
663
|
const joiner = flatten2 ? " " : "\n";
|
|
366
664
|
let val = "";
|
|
367
|
-
assertShape(
|
|
665
|
+
assertShape(
|
|
666
|
+
value,
|
|
667
|
+
(value2) => value2.type === "root" && Array.isArray(value2.children),
|
|
668
|
+
`Nested rich-text element is not a valid shape for field ${field.name}`
|
|
669
|
+
);
|
|
368
670
|
if (field.name === "children") {
|
|
369
671
|
const root = rootElement(value, field, imageCallback);
|
|
370
672
|
root.children.forEach((child) => {
|
|
@@ -434,7 +736,9 @@ function stringifyObj(obj, flatten2) {
|
|
|
434
736
|
}).trim().replace(dummyFunc, "");
|
|
435
737
|
return flatten2 ? res.replaceAll("\n", "").replaceAll(" ", " ") : res;
|
|
436
738
|
} else {
|
|
437
|
-
throw new Error(
|
|
739
|
+
throw new Error(
|
|
740
|
+
`stringifyObj must be passed an object or an array of objects, received ${typeof obj}`
|
|
741
|
+
);
|
|
438
742
|
}
|
|
439
743
|
}
|
|
440
744
|
function assertShape(value, callback, errorMessage) {
|
|
@@ -480,7 +784,9 @@ var replaceLinksWithTextNodes = (content) => {
|
|
|
480
784
|
var inlineElementExceptLink = (content, field, imageCallback) => {
|
|
481
785
|
switch (content.type) {
|
|
482
786
|
case "a":
|
|
483
|
-
throw new Error(
|
|
787
|
+
throw new Error(
|
|
788
|
+
`Unexpected node of type "a", link elements should be processed after all inline elements have resolved`
|
|
789
|
+
);
|
|
484
790
|
case "img":
|
|
485
791
|
return {
|
|
486
792
|
type: "image",
|
|
@@ -493,7 +799,11 @@ var inlineElementExceptLink = (content, field, imageCallback) => {
|
|
|
493
799
|
type: "break"
|
|
494
800
|
};
|
|
495
801
|
case "mdxJsxTextElement": {
|
|
496
|
-
const { attributes: attributes2, children } = stringifyPropsInline(
|
|
802
|
+
const { attributes: attributes2, children } = stringifyPropsInline(
|
|
803
|
+
content,
|
|
804
|
+
field,
|
|
805
|
+
imageCallback
|
|
806
|
+
);
|
|
497
807
|
return {
|
|
498
808
|
type: "mdxJsxTextElement",
|
|
499
809
|
name: content.name,
|
|
@@ -509,12 +819,12 @@ var inlineElementExceptLink = (content, field, imageCallback) => {
|
|
|
509
819
|
}
|
|
510
820
|
default:
|
|
511
821
|
if (!content.type && typeof content.text === "string") {
|
|
512
|
-
return
|
|
822
|
+
return text2(content);
|
|
513
823
|
}
|
|
514
824
|
throw new Error(`InlineElement: ${content.type} is not supported`);
|
|
515
825
|
}
|
|
516
826
|
};
|
|
517
|
-
var
|
|
827
|
+
var text2 = (content) => {
|
|
518
828
|
return {
|
|
519
829
|
type: "text",
|
|
520
830
|
value: content.text
|
|
@@ -533,7 +843,11 @@ var eat = (c, field, imageCallback) => {
|
|
|
533
843
|
type: "link",
|
|
534
844
|
url: first.url,
|
|
535
845
|
title: first.title,
|
|
536
|
-
children: eat(
|
|
846
|
+
children: eat(
|
|
847
|
+
first.children,
|
|
848
|
+
field,
|
|
849
|
+
imageCallback
|
|
850
|
+
)
|
|
537
851
|
},
|
|
538
852
|
...eat(content.slice(1), field, imageCallback)
|
|
539
853
|
];
|
|
@@ -547,11 +861,11 @@ var eat = (c, field, imageCallback) => {
|
|
|
547
861
|
if (marks.length === 0) {
|
|
548
862
|
if (first.linkifyTextNode) {
|
|
549
863
|
return [
|
|
550
|
-
first.linkifyTextNode(
|
|
864
|
+
first.linkifyTextNode(text2(first)),
|
|
551
865
|
...eat(content.slice(1), field, imageCallback)
|
|
552
866
|
];
|
|
553
867
|
} else {
|
|
554
|
-
return [
|
|
868
|
+
return [text2(first), ...eat(content.slice(1), field, imageCallback)];
|
|
555
869
|
}
|
|
556
870
|
}
|
|
557
871
|
let nonMatchingSiblingIndex = 0;
|
|
@@ -587,7 +901,7 @@ var eat = (c, field, imageCallback) => {
|
|
|
587
901
|
}
|
|
588
902
|
});
|
|
589
903
|
if (!markToProcess) {
|
|
590
|
-
return [
|
|
904
|
+
return [text2(first), ...eat(content.slice(1), field, imageCallback)];
|
|
591
905
|
}
|
|
592
906
|
if (markToProcess === "inlineCode") {
|
|
593
907
|
if (nonMatchingSiblingIndex) {
|
|
@@ -605,9 +919,15 @@ var eat = (c, field, imageCallback) => {
|
|
|
605
919
|
return [
|
|
606
920
|
{
|
|
607
921
|
type: markToProcess,
|
|
608
|
-
children: eat(
|
|
609
|
-
|
|
610
|
-
|
|
922
|
+
children: eat(
|
|
923
|
+
[
|
|
924
|
+
...[first, ...matchingSiblings].map(
|
|
925
|
+
(sibling) => cleanNode(sibling, markToProcess)
|
|
926
|
+
)
|
|
927
|
+
],
|
|
928
|
+
field,
|
|
929
|
+
imageCallback
|
|
930
|
+
)
|
|
611
931
|
},
|
|
612
932
|
...eat(content.slice(nonMatchingSiblingIndex + 1), field, imageCallback)
|
|
613
933
|
];
|
|
@@ -634,11 +954,11 @@ var cleanNode = (node, mark) => {
|
|
|
634
954
|
};
|
|
635
955
|
|
|
636
956
|
// src/extensions/tina-shortcodes/to-markdown.ts
|
|
637
|
-
import { stringifyEntitiesLight } from "stringify-entities";
|
|
638
|
-
import { containerFlow } from "mdast-util-to-markdown/lib/util/container-flow";
|
|
639
|
-
import { containerPhrasing } from "mdast-util-to-markdown/lib/util/container-phrasing";
|
|
957
|
+
import { stringifyEntitiesLight as stringifyEntitiesLight2 } from "stringify-entities";
|
|
958
|
+
import { containerFlow as containerFlow2 } from "mdast-util-to-markdown/lib/util/container-flow";
|
|
959
|
+
import { containerPhrasing as containerPhrasing2 } from "mdast-util-to-markdown/lib/util/container-phrasing";
|
|
640
960
|
import { checkQuote } from "mdast-util-to-markdown/lib/util/check-quote";
|
|
641
|
-
import { track } from "mdast-util-to-markdown/lib/util/track";
|
|
961
|
+
import { track as track2 } from "mdast-util-to-markdown/lib/util/track";
|
|
642
962
|
var own = {}.hasOwnProperty;
|
|
643
963
|
var directiveToMarkdown = (patterns) => ({
|
|
644
964
|
unsafe: [
|
|
@@ -666,12 +986,14 @@ var directiveToMarkdown = (patterns) => ({
|
|
|
666
986
|
});
|
|
667
987
|
var handleDirective = function(patterns) {
|
|
668
988
|
const handleDirective2 = function(node, _, state, safeOptions) {
|
|
669
|
-
const tracker =
|
|
670
|
-
const
|
|
671
|
-
const pattern = patterns.find(
|
|
989
|
+
const tracker = track2(safeOptions);
|
|
990
|
+
const exit = state.enter(node.type);
|
|
991
|
+
const pattern = patterns.find(
|
|
992
|
+
(p) => p.name === node.name || p.templateName === node.name
|
|
993
|
+
);
|
|
672
994
|
if (!pattern) {
|
|
673
995
|
console.log("no pattern found for directive", node.name);
|
|
674
|
-
|
|
996
|
+
exit();
|
|
675
997
|
return "";
|
|
676
998
|
}
|
|
677
999
|
const patternName = pattern.name || pattern.templateName;
|
|
@@ -679,18 +1001,20 @@ var handleDirective = function(patterns) {
|
|
|
679
1001
|
let value = tracker.move(sequence + " " + patternName);
|
|
680
1002
|
let label;
|
|
681
1003
|
if (label && label.children && label.children.length > 0) {
|
|
682
|
-
const
|
|
1004
|
+
const exit2 = state.enter("label");
|
|
683
1005
|
const labelType = `${node.type}Label`;
|
|
684
1006
|
const subexit = state.enter(labelType);
|
|
685
1007
|
value += tracker.move("[");
|
|
686
|
-
value += tracker.move(
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
1008
|
+
value += tracker.move(
|
|
1009
|
+
containerPhrasing2(label, state, {
|
|
1010
|
+
...tracker.current(),
|
|
1011
|
+
before: value,
|
|
1012
|
+
after: "]"
|
|
1013
|
+
})
|
|
1014
|
+
);
|
|
691
1015
|
value += tracker.move("]");
|
|
692
1016
|
subexit();
|
|
693
|
-
|
|
1017
|
+
exit2();
|
|
694
1018
|
}
|
|
695
1019
|
value += tracker.move(" ");
|
|
696
1020
|
value += tracker.move(attributes(node, state));
|
|
@@ -703,12 +1027,12 @@ var handleDirective = function(patterns) {
|
|
|
703
1027
|
}
|
|
704
1028
|
if (shallow && shallow.children && shallow.children.length > 0) {
|
|
705
1029
|
value += tracker.move("\n");
|
|
706
|
-
value += tracker.move(
|
|
1030
|
+
value += tracker.move(containerFlow2(shallow, state, tracker.current()));
|
|
707
1031
|
}
|
|
708
1032
|
value += tracker.move("\n" + sequence);
|
|
709
1033
|
value += tracker.move(" /" + patternName + " " + pattern.end);
|
|
710
1034
|
}
|
|
711
|
-
|
|
1035
|
+
exit();
|
|
712
1036
|
return value;
|
|
713
1037
|
};
|
|
714
1038
|
handleDirective2.peek = peekDirective;
|
|
@@ -721,17 +1045,17 @@ function attributes(node, state) {
|
|
|
721
1045
|
const quote = checkQuote(state);
|
|
722
1046
|
const subset = node.type === "textDirective" ? [quote] : [quote, "\n", "\r"];
|
|
723
1047
|
const attrs = node.attributes || {};
|
|
724
|
-
const
|
|
1048
|
+
const values3 = [];
|
|
725
1049
|
let key;
|
|
726
1050
|
for (key in attrs) {
|
|
727
1051
|
if (own.call(attrs, key) && attrs[key] !== void 0 && attrs[key] !== null) {
|
|
728
1052
|
const value = String(attrs[key]);
|
|
729
|
-
|
|
1053
|
+
values3.push(quoted(key, value));
|
|
730
1054
|
}
|
|
731
1055
|
}
|
|
732
|
-
return
|
|
1056
|
+
return values3.length > 0 ? values3.join(" ") + " " : "";
|
|
733
1057
|
function quoted(key2, value) {
|
|
734
|
-
const v = quote +
|
|
1058
|
+
const v = quote + stringifyEntitiesLight2(value, { subset }) + quote;
|
|
735
1059
|
if (key2 === "_value") {
|
|
736
1060
|
return v;
|
|
737
1061
|
}
|
|
@@ -739,7 +1063,9 @@ function attributes(node, state) {
|
|
|
739
1063
|
}
|
|
740
1064
|
}
|
|
741
1065
|
function inlineDirectiveLabel(node) {
|
|
742
|
-
return Boolean(
|
|
1066
|
+
return Boolean(
|
|
1067
|
+
node && node.type === "paragraph" && node.data && node.data.directiveLabel
|
|
1068
|
+
);
|
|
743
1069
|
}
|
|
744
1070
|
|
|
745
1071
|
// src/stringify/stringifyShortcode.ts
|
|
@@ -757,6 +1083,9 @@ ${match.start} /${match.name || template.name} ${match.end}`;
|
|
|
757
1083
|
|
|
758
1084
|
// src/stringify/index.ts
|
|
759
1085
|
var stringifyMDX = (value, field, imageCallback) => {
|
|
1086
|
+
if (field.parser?.type === "markdown") {
|
|
1087
|
+
return stringifyMDX2(value, field, imageCallback);
|
|
1088
|
+
}
|
|
760
1089
|
if (!value) {
|
|
761
1090
|
return;
|
|
762
1091
|
}
|
|
@@ -769,8 +1098,10 @@ var stringifyMDX = (value, field, imageCallback) => {
|
|
|
769
1098
|
}
|
|
770
1099
|
}
|
|
771
1100
|
const tree = rootElement(value, field, imageCallback);
|
|
772
|
-
const res =
|
|
773
|
-
const templatesWithMatchers = field.templates?.filter(
|
|
1101
|
+
const res = toTinaMarkdown2(tree, field);
|
|
1102
|
+
const templatesWithMatchers = field.templates?.filter(
|
|
1103
|
+
(template) => template.match
|
|
1104
|
+
);
|
|
774
1105
|
let preprocessedString = res;
|
|
775
1106
|
templatesWithMatchers?.forEach((template) => {
|
|
776
1107
|
if (typeof template === "string") {
|
|
@@ -782,7 +1113,7 @@ var stringifyMDX = (value, field, imageCallback) => {
|
|
|
782
1113
|
});
|
|
783
1114
|
return preprocessedString;
|
|
784
1115
|
};
|
|
785
|
-
var
|
|
1116
|
+
var toTinaMarkdown2 = (tree, field) => {
|
|
786
1117
|
const patterns = [];
|
|
787
1118
|
field.templates?.forEach((template) => {
|
|
788
1119
|
if (typeof template === "string") {
|
|
@@ -815,10 +1146,10 @@ var toTinaMarkdown = (tree, field) => {
|
|
|
815
1146
|
});
|
|
816
1147
|
}
|
|
817
1148
|
}
|
|
818
|
-
return
|
|
1149
|
+
return text3(node, parent, context, safeOptions);
|
|
819
1150
|
};
|
|
820
|
-
return
|
|
821
|
-
extensions: [directiveToMarkdown(patterns),
|
|
1151
|
+
return toMarkdown2(tree, {
|
|
1152
|
+
extensions: [directiveToMarkdown(patterns), mdxJsxToMarkdown2()],
|
|
822
1153
|
listItemIndent: "one",
|
|
823
1154
|
handlers
|
|
824
1155
|
});
|
|
@@ -871,7 +1202,9 @@ var blockElement = (content, field, imageCallback) => {
|
|
|
871
1202
|
if (useDirective) {
|
|
872
1203
|
const name = content.name;
|
|
873
1204
|
if (!name) {
|
|
874
|
-
throw new Error(
|
|
1205
|
+
throw new Error(
|
|
1206
|
+
`Expective shortcode to have a name but it was not defined`
|
|
1207
|
+
);
|
|
875
1208
|
}
|
|
876
1209
|
const directiveAttributes = {};
|
|
877
1210
|
attributes2?.forEach((att) => {
|
|
@@ -921,7 +1254,9 @@ var blockElement = (content, field, imageCallback) => {
|
|
|
921
1254
|
type: "list",
|
|
922
1255
|
ordered: content.type === "ol",
|
|
923
1256
|
spread: false,
|
|
924
|
-
children: content.children.map(
|
|
1257
|
+
children: content.children.map(
|
|
1258
|
+
(child) => listItemElement(child, field, imageCallback)
|
|
1259
|
+
)
|
|
925
1260
|
};
|
|
926
1261
|
case "html": {
|
|
927
1262
|
return {
|
|
@@ -931,10 +1266,15 @@ var blockElement = (content, field, imageCallback) => {
|
|
|
931
1266
|
}
|
|
932
1267
|
case "img":
|
|
933
1268
|
return {
|
|
934
|
-
type: "
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1269
|
+
type: "paragraph",
|
|
1270
|
+
children: [
|
|
1271
|
+
{
|
|
1272
|
+
type: "image",
|
|
1273
|
+
url: imageCallback(content.url),
|
|
1274
|
+
alt: content.alt,
|
|
1275
|
+
title: content.caption
|
|
1276
|
+
}
|
|
1277
|
+
]
|
|
938
1278
|
};
|
|
939
1279
|
default:
|
|
940
1280
|
throw new Error(`BlockElement: ${content.type} is not yet supported`);
|
|
@@ -960,7 +1300,9 @@ var blockContentElement = (content, field, imageCallback) => {
|
|
|
960
1300
|
case "blockquote":
|
|
961
1301
|
return {
|
|
962
1302
|
type: "blockquote",
|
|
963
|
-
children: content.children.map(
|
|
1303
|
+
children: content.children.map(
|
|
1304
|
+
(child) => blockContentElement(child, field, imageCallback)
|
|
1305
|
+
)
|
|
964
1306
|
};
|
|
965
1307
|
case "p":
|
|
966
1308
|
return {
|
|
@@ -973,10 +1315,14 @@ var blockContentElement = (content, field, imageCallback) => {
|
|
|
973
1315
|
type: "list",
|
|
974
1316
|
ordered: content.type === "ol",
|
|
975
1317
|
spread: false,
|
|
976
|
-
children: content.children.map(
|
|
1318
|
+
children: content.children.map(
|
|
1319
|
+
(child) => listItemElement(child, field, imageCallback)
|
|
1320
|
+
)
|
|
977
1321
|
};
|
|
978
1322
|
default:
|
|
979
|
-
throw new Error(
|
|
1323
|
+
throw new Error(
|
|
1324
|
+
`BlockContentElement: ${content.type} is not yet supported`
|
|
1325
|
+
);
|
|
980
1326
|
}
|
|
981
1327
|
};
|
|
982
1328
|
var getMarks = (content) => {
|
|
@@ -996,1173 +1342,2126 @@ var getMarks = (content) => {
|
|
|
996
1342
|
return marks;
|
|
997
1343
|
};
|
|
998
1344
|
|
|
999
|
-
// src/
|
|
1000
|
-
import {
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
if (typeof template === "string") {
|
|
1008
|
-
throw new Error("Global templates not yet supported");
|
|
1009
|
-
}
|
|
1010
|
-
if (!template) {
|
|
1011
|
-
const string = toTinaMarkdown({ type: "root", children: [node] }, field);
|
|
1012
|
-
return {
|
|
1013
|
-
type: node.type === "mdxJsxFlowElement" ? "html" : "html_inline",
|
|
1014
|
-
value: string.trim(),
|
|
1015
|
-
children: [{ type: "text", text: "" }]
|
|
1016
|
-
};
|
|
1017
|
-
}
|
|
1018
|
-
const props = extractAttributes(node.attributes, template.fields, imageCallback);
|
|
1019
|
-
const childField = template.fields.find((field2) => field2.name === "children");
|
|
1020
|
-
if (childField) {
|
|
1021
|
-
if (childField.type === "rich-text") {
|
|
1022
|
-
props.children = remarkToSlate(node, childField, imageCallback);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
return {
|
|
1026
|
-
type: node.type,
|
|
1027
|
-
name: node.name,
|
|
1028
|
-
children: [{ type: "text", text: "" }],
|
|
1029
|
-
props
|
|
1030
|
-
};
|
|
1031
|
-
} catch (e) {
|
|
1032
|
-
if (e instanceof Error) {
|
|
1033
|
-
throw new RichTextParseError(e.message, node.position);
|
|
1034
|
-
}
|
|
1035
|
-
throw e;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
var directiveElement = (node, field, imageCallback, raw) => {
|
|
1345
|
+
// src/next/stringify/acorn.ts
|
|
1346
|
+
import { format as format2 } from "prettier";
|
|
1347
|
+
var stringifyPropsInline2 = (element, field, imageCallback) => {
|
|
1348
|
+
return stringifyProps2(element, field, true, imageCallback);
|
|
1349
|
+
};
|
|
1350
|
+
function stringifyProps2(element, parentField, flatten2, imageCallback) {
|
|
1351
|
+
const attributes2 = [];
|
|
1352
|
+
const children = [];
|
|
1039
1353
|
let template;
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1354
|
+
let useDirective = false;
|
|
1355
|
+
let directiveType = "leaf";
|
|
1356
|
+
template = parentField.templates?.find((template2) => {
|
|
1357
|
+
if (typeof template2 === "string") {
|
|
1358
|
+
throw new Error("Global templates not supported");
|
|
1359
|
+
}
|
|
1360
|
+
return template2.name === element.name;
|
|
1043
1361
|
});
|
|
1044
|
-
if (typeof template === "string") {
|
|
1045
|
-
throw new Error("Global templates not yet supported");
|
|
1046
|
-
}
|
|
1047
1362
|
if (!template) {
|
|
1048
|
-
template =
|
|
1363
|
+
template = parentField.templates?.find((template2) => {
|
|
1049
1364
|
const templateName = template2?.match?.name;
|
|
1050
|
-
return templateName ===
|
|
1365
|
+
return templateName === element.name;
|
|
1051
1366
|
});
|
|
1052
1367
|
}
|
|
1053
|
-
if (!template) {
|
|
1054
|
-
|
|
1055
|
-
type: "p",
|
|
1056
|
-
children: [{ type: "text", text: source(node, raw || "") || "" }]
|
|
1057
|
-
};
|
|
1368
|
+
if (!template || typeof template === "string") {
|
|
1369
|
+
throw new Error(`Unable to find template for JSX element ${element.name}`);
|
|
1058
1370
|
}
|
|
1059
|
-
if (
|
|
1060
|
-
|
|
1371
|
+
if (template.fields.find((f) => f.name === "children")) {
|
|
1372
|
+
directiveType = "block";
|
|
1061
1373
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
if (node.type === "containerDirective") {
|
|
1067
|
-
props.children = remarkToSlate(node, childField, imageCallback, raw);
|
|
1068
|
-
}
|
|
1374
|
+
useDirective = !!template.match;
|
|
1375
|
+
Object.entries(element.props).forEach(([name, value]) => {
|
|
1376
|
+
if (typeof template === "string") {
|
|
1377
|
+
throw new Error(`Unable to find template for JSX element ${name}`);
|
|
1069
1378
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
props,
|
|
1075
|
-
children: [{ type: "text", text: "" }]
|
|
1076
|
-
};
|
|
1077
|
-
};
|
|
1078
|
-
|
|
1079
|
-
// src/parse/remarkToPlate.ts
|
|
1080
|
-
var remarkToSlate = (root, field, imageCallback, raw) => {
|
|
1081
|
-
const content = (content2) => {
|
|
1082
|
-
switch (content2.type) {
|
|
1083
|
-
case "blockquote":
|
|
1084
|
-
const children = [];
|
|
1085
|
-
content2.children.map((child) => {
|
|
1086
|
-
const inlineElements = unwrapBlockContent(child);
|
|
1087
|
-
inlineElements.forEach((child2) => {
|
|
1088
|
-
children.push(child2);
|
|
1089
|
-
});
|
|
1090
|
-
});
|
|
1091
|
-
return {
|
|
1092
|
-
type: "blockquote",
|
|
1093
|
-
children
|
|
1094
|
-
};
|
|
1095
|
-
case "heading":
|
|
1096
|
-
return heading(content2);
|
|
1097
|
-
case "code":
|
|
1098
|
-
return code(content2);
|
|
1099
|
-
case "paragraph":
|
|
1100
|
-
return paragraph(content2);
|
|
1101
|
-
case "mdxJsxFlowElement":
|
|
1102
|
-
return mdxJsxElement(content2, field, imageCallback);
|
|
1103
|
-
case "thematicBreak":
|
|
1104
|
-
return {
|
|
1105
|
-
type: "hr",
|
|
1106
|
-
children: [{ type: "text", text: "" }]
|
|
1107
|
-
};
|
|
1108
|
-
case "listItem":
|
|
1109
|
-
return {
|
|
1110
|
-
type: "li",
|
|
1111
|
-
children: [
|
|
1112
|
-
{
|
|
1113
|
-
type: "lic",
|
|
1114
|
-
children: flatten(content2.children.map((child) => unwrapBlockContent(child)))
|
|
1115
|
-
}
|
|
1116
|
-
]
|
|
1117
|
-
};
|
|
1118
|
-
case "list":
|
|
1119
|
-
return list(content2);
|
|
1120
|
-
case "html":
|
|
1121
|
-
return html(content2);
|
|
1122
|
-
case "mdxFlowExpression":
|
|
1123
|
-
case "mdxjsEsm":
|
|
1124
|
-
throw new RichTextParseError(`Unexpected expression ${content2.value}.`, content2.position);
|
|
1125
|
-
case "leafDirective": {
|
|
1126
|
-
return directiveElement(content2, field, imageCallback, raw);
|
|
1127
|
-
}
|
|
1128
|
-
case "containerDirective": {
|
|
1129
|
-
return directiveElement(content2, field, imageCallback, raw);
|
|
1379
|
+
const field = template?.fields?.find((field2) => field2.name === name);
|
|
1380
|
+
if (!field) {
|
|
1381
|
+
if (name === "children") {
|
|
1382
|
+
return;
|
|
1130
1383
|
}
|
|
1131
|
-
|
|
1132
|
-
throw new RichTextParseError(`Content: ${content2.type} is not yet supported`, content2.position);
|
|
1384
|
+
return;
|
|
1133
1385
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
type: content2.ordered ? "ol" : "ul",
|
|
1147
|
-
children: content2.children.map((child) => listItem(child))
|
|
1148
|
-
};
|
|
1149
|
-
};
|
|
1150
|
-
const listItem = (content2) => {
|
|
1151
|
-
return {
|
|
1152
|
-
type: "li",
|
|
1153
|
-
children: content2.children.map((child) => {
|
|
1154
|
-
switch (child.type) {
|
|
1155
|
-
case "list":
|
|
1156
|
-
return list(child);
|
|
1157
|
-
case "heading":
|
|
1158
|
-
case "paragraph":
|
|
1159
|
-
return {
|
|
1160
|
-
type: "lic",
|
|
1161
|
-
children: flatten(child.children.map((child2) => phrasingContent(child2)))
|
|
1162
|
-
};
|
|
1163
|
-
case "blockquote": {
|
|
1164
|
-
return {
|
|
1165
|
-
...blockquote(child),
|
|
1166
|
-
type: "lic"
|
|
1167
|
-
};
|
|
1386
|
+
switch (field.type) {
|
|
1387
|
+
case "reference":
|
|
1388
|
+
if (field.list) {
|
|
1389
|
+
if (Array.isArray(value)) {
|
|
1390
|
+
attributes2.push({
|
|
1391
|
+
type: "mdxJsxAttribute",
|
|
1392
|
+
name,
|
|
1393
|
+
value: {
|
|
1394
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1395
|
+
value: `[${value.map((item) => `"${item}"`).join(", ")}]`
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1168
1398
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
};
|
|
1176
|
-
case "html":
|
|
1177
|
-
return {
|
|
1178
|
-
type: "lic",
|
|
1179
|
-
children: html_inline(child)
|
|
1180
|
-
};
|
|
1181
|
-
case "leafDirective": {
|
|
1182
|
-
return {
|
|
1183
|
-
type: "lic",
|
|
1184
|
-
children: [directiveElement(child, field, imageCallback)]
|
|
1185
|
-
};
|
|
1399
|
+
} else {
|
|
1400
|
+
if (typeof value === "string") {
|
|
1401
|
+
attributes2.push({
|
|
1402
|
+
type: "mdxJsxAttribute",
|
|
1403
|
+
name,
|
|
1404
|
+
value
|
|
1405
|
+
});
|
|
1186
1406
|
}
|
|
1187
|
-
case "code":
|
|
1188
|
-
case "thematicBreak":
|
|
1189
|
-
case "table":
|
|
1190
|
-
throw new RichTextParseError(`${child.type} inside list item is not supported`, child.position);
|
|
1191
|
-
default:
|
|
1192
|
-
throw new RichTextParseError(`Unknown list item of type ${child.type}`, child.position);
|
|
1193
1407
|
}
|
|
1194
|
-
|
|
1408
|
+
break;
|
|
1409
|
+
case "datetime":
|
|
1410
|
+
case "string":
|
|
1411
|
+
if (field.list) {
|
|
1412
|
+
if (Array.isArray(value)) {
|
|
1413
|
+
attributes2.push({
|
|
1414
|
+
type: "mdxJsxAttribute",
|
|
1415
|
+
name,
|
|
1416
|
+
value: {
|
|
1417
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1418
|
+
value: `[${value.map((item) => `"${item}"`).join(", ")}]`
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
} else {
|
|
1423
|
+
if (typeof value === "string") {
|
|
1424
|
+
attributes2.push({
|
|
1425
|
+
type: "mdxJsxAttribute",
|
|
1426
|
+
name,
|
|
1427
|
+
value
|
|
1428
|
+
});
|
|
1429
|
+
} else {
|
|
1430
|
+
throw new Error(
|
|
1431
|
+
`Expected string for attribute on field ${field.name}`
|
|
1432
|
+
);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
break;
|
|
1436
|
+
case "image":
|
|
1437
|
+
if (field.list) {
|
|
1438
|
+
if (Array.isArray(value)) {
|
|
1439
|
+
attributes2.push({
|
|
1440
|
+
type: "mdxJsxAttribute",
|
|
1441
|
+
name,
|
|
1442
|
+
value: {
|
|
1443
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1444
|
+
value: `[${value.map((item) => `"${imageCallback(item)}"`).join(", ")}]`
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
} else {
|
|
1449
|
+
attributes2.push({
|
|
1450
|
+
type: "mdxJsxAttribute",
|
|
1451
|
+
name,
|
|
1452
|
+
value: imageCallback(String(value))
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
break;
|
|
1456
|
+
case "number":
|
|
1457
|
+
case "boolean":
|
|
1458
|
+
if (field.list) {
|
|
1459
|
+
if (Array.isArray(value)) {
|
|
1460
|
+
attributes2.push({
|
|
1461
|
+
type: "mdxJsxAttribute",
|
|
1462
|
+
name,
|
|
1463
|
+
value: {
|
|
1464
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1465
|
+
value: `[${value.map((item) => `${item}`).join(", ")}]`
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
} else {
|
|
1470
|
+
attributes2.push({
|
|
1471
|
+
type: "mdxJsxAttribute",
|
|
1472
|
+
name,
|
|
1473
|
+
value: {
|
|
1474
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1475
|
+
value: String(value)
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
break;
|
|
1480
|
+
case "object":
|
|
1481
|
+
attributes2.push({
|
|
1482
|
+
type: "mdxJsxAttribute",
|
|
1483
|
+
name,
|
|
1484
|
+
value: {
|
|
1485
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1486
|
+
value: stringifyObj2(value, flatten2)
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
break;
|
|
1490
|
+
case "rich-text":
|
|
1491
|
+
if (typeof value === "string") {
|
|
1492
|
+
throw new Error(
|
|
1493
|
+
`Unexpected string for rich-text, ensure the value has been properly parsed`
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
if (field.list) {
|
|
1497
|
+
throw new Error(`Rich-text list is not supported`);
|
|
1498
|
+
} else {
|
|
1499
|
+
const joiner = flatten2 ? " " : "\n";
|
|
1500
|
+
let val = "";
|
|
1501
|
+
assertShape2(
|
|
1502
|
+
value,
|
|
1503
|
+
(value2) => value2.type === "root" && Array.isArray(value2.children),
|
|
1504
|
+
`Nested rich-text element is not a valid shape for field ${field.name}`
|
|
1505
|
+
);
|
|
1506
|
+
if (field.name === "children") {
|
|
1507
|
+
const root = rootElement2(value, field, imageCallback);
|
|
1508
|
+
root.children.forEach((child) => {
|
|
1509
|
+
children.push(child);
|
|
1510
|
+
});
|
|
1511
|
+
return;
|
|
1512
|
+
} else {
|
|
1513
|
+
const stringValue = stringifyMDX2(value, field, imageCallback);
|
|
1514
|
+
if (stringValue) {
|
|
1515
|
+
val = stringValue.trim().split("\n").map((str) => ` ${str.trim()}`).join(joiner);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
if (flatten2) {
|
|
1519
|
+
attributes2.push({
|
|
1520
|
+
type: "mdxJsxAttribute",
|
|
1521
|
+
name,
|
|
1522
|
+
value: {
|
|
1523
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1524
|
+
value: `<>${val.trim()}</>`
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
} else {
|
|
1528
|
+
attributes2.push({
|
|
1529
|
+
type: "mdxJsxAttribute",
|
|
1530
|
+
name,
|
|
1531
|
+
value: {
|
|
1532
|
+
type: "mdxJsxAttributeValueExpression",
|
|
1533
|
+
value: `<>
|
|
1534
|
+
${val}
|
|
1535
|
+
</>`
|
|
1536
|
+
}
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
break;
|
|
1541
|
+
default:
|
|
1542
|
+
throw new Error(`Stringify props: ${field.type} not yet supported`);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
if (template.match) {
|
|
1546
|
+
return {
|
|
1547
|
+
useDirective,
|
|
1548
|
+
directiveType,
|
|
1549
|
+
attributes: attributes2,
|
|
1550
|
+
children: children && children.length ? children : [
|
|
1551
|
+
{
|
|
1552
|
+
type: "paragraph",
|
|
1553
|
+
children: [
|
|
1554
|
+
{
|
|
1555
|
+
type: "text",
|
|
1556
|
+
value: ""
|
|
1557
|
+
}
|
|
1558
|
+
]
|
|
1559
|
+
}
|
|
1560
|
+
]
|
|
1195
1561
|
};
|
|
1562
|
+
}
|
|
1563
|
+
return { attributes: attributes2, children, useDirective, directiveType };
|
|
1564
|
+
}
|
|
1565
|
+
function stringifyObj2(obj, flatten2) {
|
|
1566
|
+
if (typeof obj === "object" && obj !== null) {
|
|
1567
|
+
const dummyFunc = `const dummyFunc = `;
|
|
1568
|
+
const res = format2(`${dummyFunc}${JSON.stringify(obj)}`, {
|
|
1569
|
+
parser: "acorn",
|
|
1570
|
+
trailingComma: "none",
|
|
1571
|
+
semi: false
|
|
1572
|
+
}).trim().replace(dummyFunc, "");
|
|
1573
|
+
return flatten2 ? res.replaceAll("\n", "").replaceAll(" ", " ") : res;
|
|
1574
|
+
} else {
|
|
1575
|
+
throw new Error(
|
|
1576
|
+
`stringifyObj must be passed an object or an array of objects, received ${typeof obj}`
|
|
1577
|
+
);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
function assertShape2(value, callback, errorMessage) {
|
|
1581
|
+
if (!callback(value)) {
|
|
1582
|
+
throw new Error(errorMessage || `Failed to assert shape`);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
// src/next/stringify/marks.ts
|
|
1587
|
+
var matches2 = (a, b) => {
|
|
1588
|
+
return a.some((v) => b.includes(v));
|
|
1589
|
+
};
|
|
1590
|
+
var replaceLinksWithTextNodes2 = (content) => {
|
|
1591
|
+
const newItems = [];
|
|
1592
|
+
content?.forEach((item) => {
|
|
1593
|
+
if (item.type === "a") {
|
|
1594
|
+
if (item.children.length === 1) {
|
|
1595
|
+
const firstChild = item.children[0];
|
|
1596
|
+
if (firstChild?.type === "text") {
|
|
1597
|
+
newItems.push({
|
|
1598
|
+
...firstChild,
|
|
1599
|
+
linkifyTextNode: (a) => {
|
|
1600
|
+
return {
|
|
1601
|
+
type: "link",
|
|
1602
|
+
url: item.url,
|
|
1603
|
+
title: item.title,
|
|
1604
|
+
children: [a]
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
} else {
|
|
1609
|
+
newItems.push(item);
|
|
1610
|
+
}
|
|
1611
|
+
} else {
|
|
1612
|
+
newItems.push(item);
|
|
1613
|
+
}
|
|
1614
|
+
} else {
|
|
1615
|
+
newItems.push(item);
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
return newItems;
|
|
1619
|
+
};
|
|
1620
|
+
var inlineElementExceptLink2 = (content, field, imageCallback) => {
|
|
1621
|
+
switch (content.type) {
|
|
1622
|
+
case "a":
|
|
1623
|
+
throw new Error(
|
|
1624
|
+
`Unexpected node of type "a", link elements should be processed after all inline elements have resolved`
|
|
1625
|
+
);
|
|
1626
|
+
case "img":
|
|
1627
|
+
return {
|
|
1628
|
+
type: "image",
|
|
1629
|
+
url: imageCallback(content.url),
|
|
1630
|
+
alt: content.alt,
|
|
1631
|
+
title: content.caption
|
|
1632
|
+
};
|
|
1633
|
+
case "break":
|
|
1634
|
+
return {
|
|
1635
|
+
type: "break"
|
|
1636
|
+
};
|
|
1637
|
+
case "mdxJsxTextElement": {
|
|
1638
|
+
const { attributes: attributes2, children } = stringifyPropsInline2(
|
|
1639
|
+
content,
|
|
1640
|
+
field,
|
|
1641
|
+
imageCallback
|
|
1642
|
+
);
|
|
1643
|
+
let c = children;
|
|
1644
|
+
if (children.length) {
|
|
1645
|
+
const firstChild = children[0];
|
|
1646
|
+
if (firstChild && firstChild.type === "paragraph") {
|
|
1647
|
+
c = firstChild.children;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
return {
|
|
1651
|
+
type: "mdxJsxTextElement",
|
|
1652
|
+
name: content.name,
|
|
1653
|
+
attributes: attributes2,
|
|
1654
|
+
children: c
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
case "html_inline": {
|
|
1658
|
+
return {
|
|
1659
|
+
type: "html",
|
|
1660
|
+
value: content.value
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
default:
|
|
1664
|
+
if (!content.type && typeof content.text === "string") {
|
|
1665
|
+
return text4(content);
|
|
1666
|
+
}
|
|
1667
|
+
throw new Error(`InlineElement: ${content.type} is not supported`);
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
var text4 = (content) => {
|
|
1671
|
+
return {
|
|
1672
|
+
type: "text",
|
|
1673
|
+
value: content.text
|
|
1196
1674
|
};
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1675
|
+
};
|
|
1676
|
+
var eat2 = (c, field, imageCallback) => {
|
|
1677
|
+
const content = replaceLinksWithTextNodes2(c);
|
|
1678
|
+
const first = content[0];
|
|
1679
|
+
if (!first) {
|
|
1680
|
+
return [];
|
|
1681
|
+
}
|
|
1682
|
+
if (first && first?.type !== "text") {
|
|
1683
|
+
if (first.type === "a") {
|
|
1684
|
+
return [
|
|
1685
|
+
{
|
|
1686
|
+
type: "link",
|
|
1687
|
+
url: first.url,
|
|
1688
|
+
title: first.title,
|
|
1689
|
+
children: eat2(
|
|
1690
|
+
first.children,
|
|
1691
|
+
field,
|
|
1692
|
+
imageCallback
|
|
1693
|
+
)
|
|
1694
|
+
},
|
|
1695
|
+
...eat2(content.slice(1), field, imageCallback)
|
|
1696
|
+
];
|
|
1697
|
+
}
|
|
1698
|
+
return [
|
|
1699
|
+
inlineElementExceptLink2(first, field, imageCallback),
|
|
1700
|
+
...eat2(content.slice(1), field, imageCallback)
|
|
1701
|
+
];
|
|
1702
|
+
}
|
|
1703
|
+
const marks = getMarks(first);
|
|
1704
|
+
if (marks.length === 0) {
|
|
1705
|
+
if (first.linkifyTextNode) {
|
|
1706
|
+
return [
|
|
1707
|
+
first.linkifyTextNode(text4(first)),
|
|
1708
|
+
...eat2(content.slice(1), field, imageCallback)
|
|
1709
|
+
];
|
|
1710
|
+
} else {
|
|
1711
|
+
return [text4(first), ...eat2(content.slice(1), field, imageCallback)];
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
let nonMatchingSiblingIndex = 0;
|
|
1715
|
+
if (content.slice(1).every((content2, index) => {
|
|
1716
|
+
if (matches2(marks, getMarks(content2))) {
|
|
1717
|
+
return true;
|
|
1718
|
+
} else {
|
|
1719
|
+
nonMatchingSiblingIndex = index;
|
|
1720
|
+
return false;
|
|
1721
|
+
}
|
|
1722
|
+
})) {
|
|
1723
|
+
nonMatchingSiblingIndex = content.length - 1;
|
|
1724
|
+
}
|
|
1725
|
+
const matchingSiblings = content.slice(1, nonMatchingSiblingIndex + 1);
|
|
1726
|
+
const markCounts = {};
|
|
1727
|
+
marks.forEach((mark) => {
|
|
1728
|
+
let count2 = 1;
|
|
1729
|
+
matchingSiblings.every((sibling, index) => {
|
|
1730
|
+
if (getMarks(sibling).includes(mark)) {
|
|
1731
|
+
count2 = index + 1;
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
});
|
|
1735
|
+
markCounts[mark] = count2;
|
|
1736
|
+
});
|
|
1737
|
+
let count = 0;
|
|
1738
|
+
let markToProcess = null;
|
|
1739
|
+
Object.entries(markCounts).forEach(([mark, markCount]) => {
|
|
1740
|
+
const m = mark;
|
|
1741
|
+
if (markCount > count) {
|
|
1742
|
+
count = markCount;
|
|
1743
|
+
markToProcess = m;
|
|
1744
|
+
}
|
|
1745
|
+
});
|
|
1746
|
+
if (!markToProcess) {
|
|
1747
|
+
return [text4(first), ...eat2(content.slice(1), field, imageCallback)];
|
|
1748
|
+
}
|
|
1749
|
+
if (markToProcess === "inlineCode") {
|
|
1750
|
+
if (nonMatchingSiblingIndex) {
|
|
1751
|
+
throw new Error(`Marks inside inline code are not supported`);
|
|
1752
|
+
}
|
|
1753
|
+
const node = {
|
|
1754
|
+
type: markToProcess,
|
|
1755
|
+
value: first.text
|
|
1201
1756
|
};
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1757
|
+
return [
|
|
1758
|
+
first.linkifyTextNode?.(node) ?? node,
|
|
1759
|
+
...eat2(content.slice(nonMatchingSiblingIndex + 1), field, imageCallback)
|
|
1760
|
+
];
|
|
1761
|
+
}
|
|
1762
|
+
return [
|
|
1763
|
+
{
|
|
1764
|
+
type: markToProcess,
|
|
1765
|
+
children: eat2(
|
|
1766
|
+
[
|
|
1767
|
+
...[first, ...matchingSiblings].map(
|
|
1768
|
+
(sibling) => cleanNode2(sibling, markToProcess)
|
|
1769
|
+
)
|
|
1770
|
+
],
|
|
1771
|
+
field,
|
|
1772
|
+
imageCallback
|
|
1773
|
+
)
|
|
1774
|
+
},
|
|
1775
|
+
...eat2(content.slice(nonMatchingSiblingIndex + 1), field, imageCallback)
|
|
1776
|
+
];
|
|
1777
|
+
};
|
|
1778
|
+
var cleanNode2 = (node, mark) => {
|
|
1779
|
+
if (!mark) {
|
|
1780
|
+
return node;
|
|
1781
|
+
}
|
|
1782
|
+
const cleanedNode = {};
|
|
1783
|
+
const markToClear = {
|
|
1784
|
+
strong: "bold",
|
|
1785
|
+
emphasis: "italic",
|
|
1786
|
+
inlineCode: "code"
|
|
1787
|
+
}[mark];
|
|
1788
|
+
Object.entries(node).map(([key, value]) => {
|
|
1789
|
+
if (key !== markToClear) {
|
|
1790
|
+
cleanedNode[key] = value;
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1793
|
+
if (node.linkifyTextNode) {
|
|
1794
|
+
cleanedNode.callback = node.linkifyTextNode;
|
|
1795
|
+
}
|
|
1796
|
+
return cleanedNode;
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
// src/next/stringify/pre-processing.ts
|
|
1800
|
+
var preProcess = (tree, field, imageCallback) => {
|
|
1801
|
+
const ast = rootElement2(tree, field, imageCallback);
|
|
1802
|
+
return ast;
|
|
1803
|
+
};
|
|
1804
|
+
var rootElement2 = (content, field, imageCallback) => {
|
|
1805
|
+
const children = [];
|
|
1806
|
+
content.children?.forEach((child) => {
|
|
1807
|
+
const value = blockElement2(child, field, imageCallback);
|
|
1808
|
+
if (value) {
|
|
1809
|
+
children.push(value);
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
return {
|
|
1813
|
+
type: "root",
|
|
1814
|
+
children
|
|
1815
|
+
};
|
|
1816
|
+
};
|
|
1817
|
+
var blockElement2 = (content, field, imageCallback) => {
|
|
1818
|
+
switch (content.type) {
|
|
1819
|
+
case "h1":
|
|
1820
|
+
case "h2":
|
|
1821
|
+
case "h3":
|
|
1822
|
+
case "h4":
|
|
1823
|
+
case "h5":
|
|
1824
|
+
case "h6":
|
|
1825
|
+
return {
|
|
1826
|
+
type: "heading",
|
|
1827
|
+
depth: { h1: 1, h2: 2, h3: 3, h4: 4, h5: 5, h6: 6 }[content.type],
|
|
1828
|
+
children: eat2(content.children, field, imageCallback)
|
|
1829
|
+
};
|
|
1830
|
+
case "p":
|
|
1831
|
+
if (content.children.length === 1) {
|
|
1832
|
+
const onlyChild = content.children[0];
|
|
1833
|
+
if (onlyChild && (onlyChild.type === "text" || !onlyChild.type) && onlyChild.text === "") {
|
|
1834
|
+
return null;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
return {
|
|
1838
|
+
type: "paragraph",
|
|
1839
|
+
children: eat2(content.children, field, imageCallback)
|
|
1840
|
+
};
|
|
1841
|
+
case "code_block":
|
|
1842
|
+
return {
|
|
1843
|
+
type: "code",
|
|
1844
|
+
lang: content.lang,
|
|
1845
|
+
value: content.value
|
|
1846
|
+
};
|
|
1847
|
+
case "mdxJsxFlowElement":
|
|
1848
|
+
const { children, attributes: attributes2, useDirective, directiveType } = stringifyProps2(content, field, false, imageCallback);
|
|
1849
|
+
return {
|
|
1850
|
+
type: "mdxJsxFlowElement",
|
|
1851
|
+
name: content.name,
|
|
1852
|
+
attributes: attributes2,
|
|
1853
|
+
children
|
|
1854
|
+
};
|
|
1855
|
+
case "blockquote":
|
|
1856
|
+
return {
|
|
1857
|
+
type: "blockquote",
|
|
1858
|
+
children: [
|
|
1859
|
+
{
|
|
1860
|
+
type: "paragraph",
|
|
1861
|
+
children: eat2(content.children, field, imageCallback)
|
|
1862
|
+
}
|
|
1863
|
+
]
|
|
1864
|
+
};
|
|
1865
|
+
case "hr":
|
|
1866
|
+
return {
|
|
1867
|
+
type: "thematicBreak"
|
|
1868
|
+
};
|
|
1869
|
+
case "ol":
|
|
1870
|
+
case "ul":
|
|
1871
|
+
return {
|
|
1872
|
+
type: "list",
|
|
1873
|
+
ordered: content.type === "ol",
|
|
1874
|
+
spread: false,
|
|
1875
|
+
children: content.children.map(
|
|
1876
|
+
(child) => listItemElement2(child, field, imageCallback)
|
|
1877
|
+
)
|
|
1878
|
+
};
|
|
1879
|
+
case "html": {
|
|
1880
|
+
return {
|
|
1881
|
+
type: "html",
|
|
1882
|
+
value: content.value
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
case "img":
|
|
1886
|
+
return {
|
|
1887
|
+
type: "paragraph",
|
|
1888
|
+
children: [
|
|
1889
|
+
{
|
|
1890
|
+
type: "image",
|
|
1891
|
+
url: imageCallback(content.url),
|
|
1892
|
+
alt: content.alt,
|
|
1893
|
+
title: content.caption
|
|
1894
|
+
}
|
|
1895
|
+
]
|
|
1896
|
+
};
|
|
1897
|
+
default:
|
|
1898
|
+
throw new Error(`BlockElement: ${content.type} is not yet supported`);
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
var listItemElement2 = (content, field, imageCallback) => {
|
|
1902
|
+
return {
|
|
1903
|
+
type: "listItem",
|
|
1904
|
+
spread: false,
|
|
1905
|
+
children: content.children.map((child) => {
|
|
1906
|
+
if (child.type === "lic") {
|
|
1907
|
+
return {
|
|
1908
|
+
type: "paragraph",
|
|
1909
|
+
children: eat2(child.children, field, imageCallback)
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
return blockContentElement2(child, field, imageCallback);
|
|
1913
|
+
})
|
|
1914
|
+
};
|
|
1915
|
+
};
|
|
1916
|
+
var blockContentElement2 = (content, field, imageCallback) => {
|
|
1917
|
+
switch (content.type) {
|
|
1918
|
+
case "blockquote":
|
|
1919
|
+
return {
|
|
1920
|
+
type: "blockquote",
|
|
1921
|
+
children: content.children.map(
|
|
1922
|
+
(child) => blockContentElement2(child, field, imageCallback)
|
|
1923
|
+
)
|
|
1924
|
+
};
|
|
1925
|
+
case "p":
|
|
1926
|
+
return {
|
|
1927
|
+
type: "paragraph",
|
|
1928
|
+
children: eat2(content.children, field, imageCallback)
|
|
1929
|
+
};
|
|
1930
|
+
case "ol":
|
|
1931
|
+
case "ul":
|
|
1932
|
+
return {
|
|
1933
|
+
type: "list",
|
|
1934
|
+
ordered: content.type === "ol",
|
|
1935
|
+
spread: false,
|
|
1936
|
+
children: content.children.map(
|
|
1937
|
+
(child) => listItemElement2(child, field, imageCallback)
|
|
1938
|
+
)
|
|
1939
|
+
};
|
|
1940
|
+
default:
|
|
1941
|
+
throw new Error(
|
|
1942
|
+
`BlockContentElement: ${content.type} is not yet supported`
|
|
1943
|
+
);
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
|
|
1947
|
+
// src/next/stringify/index.ts
|
|
1948
|
+
var stringifyMDX2 = (value, field, imageCallback) => {
|
|
1949
|
+
if (!value) {
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
const mdTree = preProcess(value, field, imageCallback);
|
|
1953
|
+
return toTinaMarkdown(mdTree, field);
|
|
1954
|
+
};
|
|
1955
|
+
|
|
1956
|
+
// src/next/parse/markdown.ts
|
|
1957
|
+
import { fromMarkdown as mdastFromMarkdown } from "mdast-util-from-markdown";
|
|
1958
|
+
|
|
1959
|
+
// src/next/shortcodes/lib/factory-tag.ts
|
|
1960
|
+
import { ok as assert } from "uvu/assert";
|
|
1961
|
+
import {
|
|
1962
|
+
start as idStart,
|
|
1963
|
+
cont as idCont
|
|
1964
|
+
} from "estree-util-is-identifier-name";
|
|
1965
|
+
import { factoryMdxExpression } from "micromark-factory-mdx-expression";
|
|
1966
|
+
import { factorySpace } from "micromark-factory-space";
|
|
1967
|
+
import {
|
|
1968
|
+
markdownLineEnding,
|
|
1969
|
+
markdownLineEndingOrSpace,
|
|
1970
|
+
markdownSpace,
|
|
1971
|
+
unicodeWhitespace
|
|
1972
|
+
} from "micromark-util-character";
|
|
1973
|
+
import { codes as codes2 } from "micromark-util-symbol/codes.js";
|
|
1974
|
+
import { constants } from "micromark-util-symbol/constants.js";
|
|
1975
|
+
import { types } from "micromark-util-symbol/types.js";
|
|
1976
|
+
import { VFileMessage as VFileMessage2 } from "vfile-message";
|
|
1977
|
+
|
|
1978
|
+
// src/next/shortcodes/lib/util.ts
|
|
1979
|
+
import { codes } from "micromark-util-symbol/codes";
|
|
1980
|
+
import { values } from "micromark-util-symbol/values";
|
|
1981
|
+
var findValue = (string) => {
|
|
1982
|
+
let lookupValue = null;
|
|
1983
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
1984
|
+
if (value === string) {
|
|
1985
|
+
lookupValue = key;
|
|
1986
|
+
}
|
|
1987
|
+
});
|
|
1988
|
+
return lookupValue;
|
|
1989
|
+
};
|
|
1990
|
+
var findCode = (string) => {
|
|
1991
|
+
if (!string) {
|
|
1992
|
+
return null;
|
|
1993
|
+
}
|
|
1994
|
+
const lookup = findValue(string);
|
|
1995
|
+
let lookupValue = null;
|
|
1996
|
+
if (lookup) {
|
|
1997
|
+
Object.entries(codes).forEach(([key, value]) => {
|
|
1998
|
+
if (key === lookup) {
|
|
1999
|
+
lookupValue = value;
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
return lookupValue;
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2006
|
+
// src/next/shortcodes/lib/factory-tag.ts
|
|
2007
|
+
function factoryTag(effects, ok, nok, acorn2, acornOptions, addResult, allowLazy, tagType, tagMarkerType, tagClosingMarkerType, tagSelfClosingMarker, tagNameType, tagNamePrimaryType, tagNameMemberMarkerType, tagNameMemberType, tagNamePrefixMarkerType, tagNameLocalType, tagExpressionAttributeType, tagExpressionAttributeMarkerType, tagExpressionAttributeValueType, tagAttributeType, tagAttributeNameType, tagAttributeNamePrimaryType, tagAttributeNamePrefixMarkerType, tagAttributeNameLocalType, tagAttributeInitializerMarkerType, tagAttributeValueLiteralType, tagAttributeValueLiteralMarkerType, tagAttributeValueLiteralValueType, tagAttributeValueExpressionType, tagAttributeValueExpressionMarkerType, tagAttributeValueExpressionValueType, pattern) {
|
|
2008
|
+
const self = this;
|
|
2009
|
+
let returnState;
|
|
2010
|
+
let marker;
|
|
2011
|
+
let startPoint;
|
|
2012
|
+
let tagOpenerIndex = 1;
|
|
2013
|
+
let tagCloserIndex = 1;
|
|
2014
|
+
let nameIndex = 1;
|
|
2015
|
+
const start = function(code) {
|
|
2016
|
+
startPoint = self.now();
|
|
2017
|
+
effects.enter(tagType);
|
|
2018
|
+
effects.enter(tagMarkerType);
|
|
2019
|
+
effects.consume(code);
|
|
2020
|
+
if (pattern.start.length === 1) {
|
|
2021
|
+
effects.exit(tagMarkerType);
|
|
2022
|
+
return afterStart;
|
|
2023
|
+
}
|
|
2024
|
+
return tagOpenerSequence;
|
|
2025
|
+
};
|
|
2026
|
+
const tagOpenerSequence = function(code) {
|
|
2027
|
+
const character = findCode(pattern.start[tagOpenerIndex]);
|
|
2028
|
+
if (code === character) {
|
|
2029
|
+
effects.consume(code);
|
|
2030
|
+
if (pattern.start.length - 1 === tagOpenerIndex) {
|
|
2031
|
+
effects.exit(tagMarkerType);
|
|
2032
|
+
return afterStart;
|
|
2033
|
+
}
|
|
2034
|
+
tagOpenerIndex++;
|
|
2035
|
+
return tagOpenerSequence;
|
|
2036
|
+
}
|
|
2037
|
+
return nok;
|
|
2038
|
+
};
|
|
2039
|
+
const afterStart = function(code) {
|
|
2040
|
+
returnState = beforeName;
|
|
2041
|
+
return optionalEsWhitespace(code);
|
|
2042
|
+
};
|
|
2043
|
+
const beforeName = function(code) {
|
|
2044
|
+
if (code === codes2.slash) {
|
|
2045
|
+
effects.enter(tagClosingMarkerType);
|
|
2046
|
+
effects.consume(code);
|
|
2047
|
+
effects.exit(tagClosingMarkerType);
|
|
2048
|
+
returnState = beforeClosingTagName;
|
|
2049
|
+
return optionalEsWhitespace;
|
|
2050
|
+
}
|
|
2051
|
+
if (code === codes2.greaterThan) {
|
|
2052
|
+
return tagEnd(code);
|
|
2053
|
+
}
|
|
2054
|
+
if (code !== codes2.eof && idStart(code) && findCode(pattern.name[0]) === code) {
|
|
2055
|
+
effects.enter(tagNameType);
|
|
2056
|
+
effects.enter(tagNamePrimaryType);
|
|
2057
|
+
effects.consume(code);
|
|
2058
|
+
return primaryName;
|
|
2059
|
+
}
|
|
2060
|
+
return nok(code);
|
|
2061
|
+
};
|
|
2062
|
+
const beforeClosingTagName = function(code) {
|
|
2063
|
+
if (code === codes2.greaterThan) {
|
|
2064
|
+
return tagEnd(code);
|
|
2065
|
+
}
|
|
2066
|
+
if (code !== codes2.eof && idStart(code)) {
|
|
2067
|
+
effects.enter(tagNameType);
|
|
2068
|
+
effects.enter(tagNamePrimaryType);
|
|
2069
|
+
effects.consume(code);
|
|
2070
|
+
return primaryName;
|
|
2071
|
+
}
|
|
2072
|
+
return nok(code);
|
|
2073
|
+
};
|
|
2074
|
+
const primaryName = function(code) {
|
|
2075
|
+
const nextCharacterInName = pattern.name[nameIndex];
|
|
2076
|
+
const nextCodeInName = nextCharacterInName ? findCode(nextCharacterInName) : null;
|
|
2077
|
+
if (nextCodeInName === code) {
|
|
2078
|
+
effects.consume(code);
|
|
2079
|
+
nameIndex++;
|
|
2080
|
+
return primaryName;
|
|
2081
|
+
}
|
|
2082
|
+
nameIndex = 0;
|
|
2083
|
+
if (code === codes2.dot || code === codes2.slash || code === codes2.colon || code === codes2.greaterThan || code === findCode(pattern.end[0]) || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) {
|
|
2084
|
+
effects.exit(tagNamePrimaryType);
|
|
2085
|
+
returnState = afterPrimaryName;
|
|
2086
|
+
return optionalEsWhitespace(code);
|
|
2087
|
+
}
|
|
2088
|
+
return nok(code);
|
|
2089
|
+
};
|
|
2090
|
+
const afterPrimaryName = function(code) {
|
|
2091
|
+
if (code === codes2.dot) {
|
|
2092
|
+
effects.enter(tagNameMemberMarkerType);
|
|
2093
|
+
effects.consume(code);
|
|
2094
|
+
effects.exit(tagNameMemberMarkerType);
|
|
2095
|
+
returnState = beforeMemberName;
|
|
2096
|
+
return optionalEsWhitespace;
|
|
2097
|
+
}
|
|
2098
|
+
if (code === codes2.colon) {
|
|
2099
|
+
effects.enter(tagNamePrefixMarkerType);
|
|
2100
|
+
effects.consume(code);
|
|
2101
|
+
effects.exit(tagNamePrefixMarkerType);
|
|
2102
|
+
returnState = beforeLocalName;
|
|
2103
|
+
return optionalEsWhitespace;
|
|
2104
|
+
}
|
|
2105
|
+
if (code === findCode(pattern.end[0])) {
|
|
2106
|
+
const tagCloserSequence = function(code2) {
|
|
2107
|
+
const character = findCode(pattern.end[tagCloserIndex]);
|
|
2108
|
+
if (code2 === character) {
|
|
2109
|
+
if (pattern.end.length - 1 === tagCloserIndex) {
|
|
2110
|
+
effects.exit(tagNameType);
|
|
2111
|
+
return beforeAttribute(code2);
|
|
2112
|
+
}
|
|
2113
|
+
tagCloserIndex++;
|
|
2114
|
+
effects.consume(code2);
|
|
2115
|
+
return tagCloserSequence;
|
|
2116
|
+
}
|
|
2117
|
+
tagCloserIndex = 0;
|
|
2118
|
+
return nok;
|
|
2119
|
+
};
|
|
2120
|
+
if (pattern.end.length === 1) {
|
|
2121
|
+
effects.exit(tagNameType);
|
|
2122
|
+
return beforeAttribute(code);
|
|
2123
|
+
} else {
|
|
2124
|
+
effects.consume(code);
|
|
2125
|
+
return tagCloserSequence;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
if (code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || code !== codes2.eof && idStart(code)) {
|
|
2129
|
+
effects.exit(tagNameType);
|
|
2130
|
+
return beforeAttribute(code);
|
|
2131
|
+
}
|
|
2132
|
+
if (code === codes2.quotationMark) {
|
|
2133
|
+
effects.exit(tagNameType);
|
|
2134
|
+
effects.enter(tagAttributeType);
|
|
2135
|
+
effects.enter(tagAttributeNameType);
|
|
2136
|
+
effects.enter(tagAttributeNamePrimaryType);
|
|
2137
|
+
effects.exit(tagAttributeNamePrimaryType);
|
|
2138
|
+
effects.exit(tagAttributeNameType);
|
|
2139
|
+
effects.enter(tagAttributeInitializerMarkerType);
|
|
2140
|
+
effects.exit(tagAttributeInitializerMarkerType);
|
|
2141
|
+
return beforeAttributeValue(code);
|
|
2142
|
+
}
|
|
2143
|
+
return nok(code);
|
|
2144
|
+
crash(
|
|
2145
|
+
code,
|
|
2146
|
+
"after name",
|
|
2147
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2148
|
+
);
|
|
2149
|
+
};
|
|
2150
|
+
const beforeMemberName = function(code) {
|
|
2151
|
+
if (code !== codes2.eof && idStart(code)) {
|
|
2152
|
+
effects.enter(tagNameMemberType);
|
|
2153
|
+
effects.consume(code);
|
|
2154
|
+
return memberName;
|
|
2155
|
+
}
|
|
2156
|
+
return nok(code);
|
|
2157
|
+
crash(
|
|
2158
|
+
code,
|
|
2159
|
+
"before member name",
|
|
2160
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2161
|
+
);
|
|
2162
|
+
};
|
|
2163
|
+
const memberName = function(code) {
|
|
2164
|
+
if (code === codes2.dash || code !== codes2.eof && idCont(code)) {
|
|
2165
|
+
effects.consume(code);
|
|
2166
|
+
return memberName;
|
|
2167
|
+
}
|
|
2168
|
+
if (code === codes2.dot || code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) {
|
|
2169
|
+
effects.exit(tagNameMemberType);
|
|
2170
|
+
returnState = afterMemberName;
|
|
2171
|
+
return optionalEsWhitespace(code);
|
|
2172
|
+
}
|
|
2173
|
+
crash(
|
|
2174
|
+
code,
|
|
2175
|
+
"in member name",
|
|
2176
|
+
"a name character such as letters, digits, `$`, or `_`; whitespace before attributes; or the end of the tag" + (code === codes2.atSign ? " (note: to create a link in MDX, use `[text](url)`)" : "")
|
|
2177
|
+
);
|
|
2178
|
+
};
|
|
2179
|
+
const afterMemberName = function(code) {
|
|
2180
|
+
if (code === codes2.dot) {
|
|
2181
|
+
effects.enter(tagNameMemberMarkerType);
|
|
2182
|
+
effects.consume(code);
|
|
2183
|
+
effects.exit(tagNameMemberMarkerType);
|
|
2184
|
+
returnState = beforeMemberName;
|
|
2185
|
+
return optionalEsWhitespace;
|
|
2186
|
+
}
|
|
2187
|
+
if (code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || code !== codes2.eof && idStart(code)) {
|
|
2188
|
+
effects.exit(tagNameType);
|
|
2189
|
+
return beforeAttribute(code);
|
|
2190
|
+
}
|
|
2191
|
+
return nok(code);
|
|
2192
|
+
};
|
|
2193
|
+
const beforeLocalName = function(code) {
|
|
2194
|
+
if (code !== codes2.eof && idStart(code)) {
|
|
2195
|
+
effects.enter(tagNameLocalType);
|
|
2196
|
+
effects.consume(code);
|
|
2197
|
+
return localName;
|
|
2198
|
+
}
|
|
2199
|
+
crash(
|
|
2200
|
+
code,
|
|
2201
|
+
"before local name",
|
|
2202
|
+
"a character that can start a name, such as a letter, `$`, or `_`" + (code === codes2.plusSign || code !== null && code > codes2.dot && code < codes2.colon ? " (note: to create a link in MDX, use `[text](url)`)" : "")
|
|
2203
|
+
);
|
|
2204
|
+
};
|
|
2205
|
+
const localName = function(code) {
|
|
2206
|
+
if (code === codes2.dash || code !== codes2.eof && idCont(code)) {
|
|
2207
|
+
effects.consume(code);
|
|
2208
|
+
return localName;
|
|
2209
|
+
}
|
|
2210
|
+
if (code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) {
|
|
2211
|
+
effects.exit(tagNameLocalType);
|
|
2212
|
+
returnState = afterLocalName;
|
|
2213
|
+
return optionalEsWhitespace(code);
|
|
2214
|
+
}
|
|
2215
|
+
crash(
|
|
2216
|
+
code,
|
|
2217
|
+
"in local name",
|
|
2218
|
+
"a name character such as letters, digits, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2219
|
+
);
|
|
2220
|
+
};
|
|
2221
|
+
const afterLocalName = function(code) {
|
|
2222
|
+
if (code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || code !== codes2.eof && idStart(code)) {
|
|
2223
|
+
effects.exit(tagNameType);
|
|
2224
|
+
return beforeAttribute(code);
|
|
2225
|
+
}
|
|
2226
|
+
if (code === findCode(pattern.end)) {
|
|
2227
|
+
effects.exit(tagNameType);
|
|
2228
|
+
return beforeAttribute(code);
|
|
2229
|
+
}
|
|
2230
|
+
crash(
|
|
2231
|
+
code,
|
|
2232
|
+
"after local name",
|
|
2233
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag"
|
|
2234
|
+
);
|
|
2235
|
+
};
|
|
2236
|
+
const beforeAttribute = function(code) {
|
|
2237
|
+
if (code === findCode(pattern.end[0])) {
|
|
2238
|
+
const tagCloserSequence = function(code2) {
|
|
2239
|
+
const character = findCode(pattern.end[tagCloserIndex]);
|
|
2240
|
+
if (code2 === character) {
|
|
2241
|
+
if (pattern.end.length - 1 === tagCloserIndex) {
|
|
2242
|
+
return beforeAttribute(code2);
|
|
2243
|
+
}
|
|
2244
|
+
tagCloserIndex++;
|
|
2245
|
+
effects.consume(code2);
|
|
2246
|
+
return tagCloserSequence;
|
|
2247
|
+
}
|
|
2248
|
+
tagCloserIndex = 0;
|
|
2249
|
+
return nok;
|
|
2250
|
+
};
|
|
2251
|
+
if (pattern.end.length === 1) {
|
|
2252
|
+
if (pattern.leaf) {
|
|
2253
|
+
effects.enter(tagSelfClosingMarker);
|
|
2254
|
+
effects.exit(tagSelfClosingMarker);
|
|
2255
|
+
returnState = selfClosing;
|
|
2256
|
+
return optionalEsWhitespace;
|
|
2257
|
+
} else {
|
|
2258
|
+
return tagEnd(code);
|
|
2259
|
+
}
|
|
2260
|
+
} else {
|
|
2261
|
+
effects.consume(code);
|
|
2262
|
+
return tagCloserSequence;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
if (code === findCode(pattern.end[pattern.end.length - 1])) {
|
|
2266
|
+
if (pattern.leaf) {
|
|
2267
|
+
effects.enter(tagSelfClosingMarker);
|
|
2268
|
+
effects.exit(tagSelfClosingMarker);
|
|
2269
|
+
returnState = selfClosing;
|
|
2270
|
+
return optionalEsWhitespace;
|
|
2271
|
+
} else {
|
|
2272
|
+
return tagEnd(code);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
if (code === codes2.greaterThan) {
|
|
2276
|
+
return tagEnd(code);
|
|
2277
|
+
}
|
|
2278
|
+
if (code === codes2.leftCurlyBrace) {
|
|
2279
|
+
assert(startPoint, "expected `startPoint` to be defined");
|
|
2280
|
+
return factoryMdxExpression.call(
|
|
2281
|
+
self,
|
|
2282
|
+
effects,
|
|
2283
|
+
afterAttributeExpression,
|
|
2284
|
+
tagExpressionAttributeType,
|
|
2285
|
+
tagExpressionAttributeMarkerType,
|
|
2286
|
+
tagExpressionAttributeValueType,
|
|
2287
|
+
acorn2,
|
|
2288
|
+
acornOptions,
|
|
2289
|
+
addResult,
|
|
2290
|
+
true,
|
|
2291
|
+
false,
|
|
2292
|
+
allowLazy,
|
|
2293
|
+
startPoint.column
|
|
2294
|
+
)(code);
|
|
2295
|
+
}
|
|
2296
|
+
if (code !== codes2.eof && idStart(code)) {
|
|
2297
|
+
effects.enter(tagAttributeType);
|
|
2298
|
+
effects.enter(tagAttributeNameType);
|
|
2299
|
+
effects.enter(tagAttributeNamePrimaryType);
|
|
2300
|
+
effects.consume(code);
|
|
2301
|
+
return attributePrimaryName;
|
|
2302
|
+
}
|
|
2303
|
+
return nok;
|
|
2304
|
+
};
|
|
2305
|
+
const afterAttributeExpression = function(code) {
|
|
2306
|
+
returnState = beforeAttribute;
|
|
2307
|
+
return optionalEsWhitespace(code);
|
|
2308
|
+
};
|
|
2309
|
+
const attributePrimaryName = function(code) {
|
|
2310
|
+
if (code === codes2.dash || code !== codes2.eof && idCont(code)) {
|
|
2311
|
+
effects.consume(code);
|
|
2312
|
+
return attributePrimaryName;
|
|
2313
|
+
}
|
|
2314
|
+
if (code === codes2.slash || code === codes2.colon || code === codes2.equalsTo || code === codes2.greaterThan || code === codes2.leftCurlyBrace || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) {
|
|
2315
|
+
effects.exit(tagAttributeNamePrimaryType);
|
|
2316
|
+
returnState = afterAttributePrimaryName;
|
|
2317
|
+
return optionalEsWhitespace(code);
|
|
2318
|
+
}
|
|
2319
|
+
return nok(code);
|
|
2320
|
+
};
|
|
2321
|
+
const afterAttributePrimaryName = function(code) {
|
|
2322
|
+
if (code === codes2.colon) {
|
|
2323
|
+
effects.enter(tagAttributeNamePrefixMarkerType);
|
|
2324
|
+
effects.consume(code);
|
|
2325
|
+
effects.exit(tagAttributeNamePrefixMarkerType);
|
|
2326
|
+
returnState = beforeAttributeLocalName;
|
|
2327
|
+
return optionalEsWhitespace;
|
|
2328
|
+
}
|
|
2329
|
+
if (code === codes2.equalsTo) {
|
|
2330
|
+
effects.exit(tagAttributeNameType);
|
|
2331
|
+
effects.enter(tagAttributeInitializerMarkerType);
|
|
2332
|
+
effects.consume(code);
|
|
2333
|
+
effects.exit(tagAttributeInitializerMarkerType);
|
|
2334
|
+
returnState = beforeAttributeValue;
|
|
2335
|
+
return optionalEsWhitespace;
|
|
1211
2336
|
}
|
|
2337
|
+
if (code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || markdownLineEndingOrSpace(code) || unicodeWhitespace(code) || code !== codes2.eof && idStart(code)) {
|
|
2338
|
+
effects.exit(tagAttributeNameType);
|
|
2339
|
+
effects.exit(tagAttributeType);
|
|
2340
|
+
returnState = beforeAttribute;
|
|
2341
|
+
return optionalEsWhitespace(code);
|
|
2342
|
+
}
|
|
2343
|
+
return nok(code);
|
|
1212
2344
|
};
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
2345
|
+
const beforeAttributeLocalName = function(code) {
|
|
2346
|
+
if (code !== codes2.eof && idStart(code)) {
|
|
2347
|
+
effects.enter(tagAttributeNameLocalType);
|
|
2348
|
+
effects.consume(code);
|
|
2349
|
+
return attributeLocalName;
|
|
2350
|
+
}
|
|
2351
|
+
crash(
|
|
2352
|
+
code,
|
|
2353
|
+
"before local attribute name",
|
|
2354
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; `=` to initialize a value; or the end of the tag"
|
|
2355
|
+
);
|
|
1223
2356
|
};
|
|
1224
|
-
const
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
2357
|
+
const attributeLocalName = function(code) {
|
|
2358
|
+
if (code === codes2.dash || code !== codes2.eof && idCont(code)) {
|
|
2359
|
+
effects.consume(code);
|
|
2360
|
+
return attributeLocalName;
|
|
2361
|
+
}
|
|
2362
|
+
if (code === codes2.slash || code === codes2.equalsTo || code === codes2.greaterThan || code === codes2.leftCurlyBrace || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) {
|
|
2363
|
+
effects.exit(tagAttributeNameLocalType);
|
|
2364
|
+
effects.exit(tagAttributeNameType);
|
|
2365
|
+
returnState = afterAttributeLocalName;
|
|
2366
|
+
return optionalEsWhitespace(code);
|
|
2367
|
+
}
|
|
2368
|
+
crash(
|
|
2369
|
+
code,
|
|
2370
|
+
"in local attribute name",
|
|
2371
|
+
"an attribute name character such as letters, digits, `$`, or `_`; `=` to initialize a value; whitespace before attributes; or the end of the tag"
|
|
2372
|
+
);
|
|
1231
2373
|
};
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
2374
|
+
const afterAttributeLocalName = function(code) {
|
|
2375
|
+
if (code === codes2.equalsTo) {
|
|
2376
|
+
effects.enter(tagAttributeInitializerMarkerType);
|
|
2377
|
+
effects.consume(code);
|
|
2378
|
+
effects.exit(tagAttributeInitializerMarkerType);
|
|
2379
|
+
returnState = beforeAttributeValue;
|
|
2380
|
+
return optionalEsWhitespace;
|
|
2381
|
+
}
|
|
2382
|
+
if (code === codes2.slash || code === codes2.greaterThan || code === codes2.leftCurlyBrace || code !== codes2.eof && idStart(code)) {
|
|
2383
|
+
effects.exit(tagAttributeType);
|
|
2384
|
+
return beforeAttribute(code);
|
|
2385
|
+
}
|
|
2386
|
+
crash(
|
|
2387
|
+
code,
|
|
2388
|
+
"after local attribute name",
|
|
2389
|
+
"a character that can start an attribute name, such as a letter, `$`, or `_`; `=` to initialize a value; or the end of the tag"
|
|
2390
|
+
);
|
|
1237
2391
|
};
|
|
1238
|
-
const
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
2392
|
+
const beforeAttributeValue = function(code) {
|
|
2393
|
+
if (code === codes2.quotationMark || code === codes2.apostrophe) {
|
|
2394
|
+
effects.enter(tagAttributeValueLiteralType);
|
|
2395
|
+
effects.enter(tagAttributeValueLiteralMarkerType);
|
|
2396
|
+
effects.consume(code);
|
|
2397
|
+
effects.exit(tagAttributeValueLiteralMarkerType);
|
|
2398
|
+
marker = code;
|
|
2399
|
+
return attributeValueQuotedStart;
|
|
2400
|
+
}
|
|
2401
|
+
if (code === codes2.leftCurlyBrace) {
|
|
2402
|
+
assert(startPoint, "expected `startPoint` to be defined");
|
|
2403
|
+
return factoryMdxExpression.call(
|
|
2404
|
+
self,
|
|
2405
|
+
effects,
|
|
2406
|
+
afterAttributeValueExpression,
|
|
2407
|
+
tagAttributeValueExpressionType,
|
|
2408
|
+
tagAttributeValueExpressionMarkerType,
|
|
2409
|
+
tagAttributeValueExpressionValueType,
|
|
2410
|
+
acorn2,
|
|
2411
|
+
acornOptions,
|
|
2412
|
+
addResult,
|
|
2413
|
+
false,
|
|
2414
|
+
false,
|
|
2415
|
+
allowLazy,
|
|
2416
|
+
startPoint.column
|
|
2417
|
+
)(code);
|
|
1253
2418
|
}
|
|
2419
|
+
return nok(code);
|
|
1254
2420
|
};
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
return html_inline(content2);
|
|
1275
|
-
case "mdxTextExpression":
|
|
1276
|
-
throw new RichTextParseError(`Unexpected expression ${content2.value}.`, content2.position);
|
|
1277
|
-
default:
|
|
1278
|
-
throw new Error(`PhrasingContent: ${content2.type} is not yet supported`);
|
|
2421
|
+
const afterAttributeValueExpression = function(code) {
|
|
2422
|
+
effects.exit(tagAttributeType);
|
|
2423
|
+
returnState = beforeAttribute;
|
|
2424
|
+
return optionalEsWhitespace(code);
|
|
2425
|
+
};
|
|
2426
|
+
const attributeValueQuotedStart = function(code) {
|
|
2427
|
+
assert(marker !== void 0, "expected `marker` to be defined");
|
|
2428
|
+
if (code === codes2.eof) {
|
|
2429
|
+
return nok(code);
|
|
2430
|
+
}
|
|
2431
|
+
if (code === marker) {
|
|
2432
|
+
effects.enter(tagAttributeValueLiteralMarkerType);
|
|
2433
|
+
effects.consume(code);
|
|
2434
|
+
effects.exit(tagAttributeValueLiteralMarkerType);
|
|
2435
|
+
effects.exit(tagAttributeValueLiteralType);
|
|
2436
|
+
effects.exit(tagAttributeType);
|
|
2437
|
+
marker = void 0;
|
|
2438
|
+
returnState = beforeAttribute;
|
|
2439
|
+
return optionalEsWhitespace;
|
|
1279
2440
|
}
|
|
2441
|
+
if (markdownLineEnding(code)) {
|
|
2442
|
+
returnState = attributeValueQuotedStart;
|
|
2443
|
+
return optionalEsWhitespace(code);
|
|
2444
|
+
}
|
|
2445
|
+
effects.enter(tagAttributeValueLiteralValueType);
|
|
2446
|
+
return attributeValueQuoted(code);
|
|
1280
2447
|
};
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
}
|
|
1289
|
-
]
|
|
1290
|
-
};
|
|
2448
|
+
const attributeValueQuoted = function(code) {
|
|
2449
|
+
if (code === codes2.eof || code === marker || markdownLineEnding(code)) {
|
|
2450
|
+
effects.exit(tagAttributeValueLiteralValueType);
|
|
2451
|
+
return attributeValueQuotedStart(code);
|
|
2452
|
+
}
|
|
2453
|
+
effects.consume(code);
|
|
2454
|
+
return attributeValueQuoted;
|
|
1291
2455
|
};
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
accum.push(image(node));
|
|
1322
|
-
break;
|
|
1323
|
-
}
|
|
1324
|
-
case "link": {
|
|
1325
|
-
const children = flatten(node.children.map((child) => phrashingMark(child, marks)));
|
|
1326
|
-
accum.push({ type: "a", url: node.url, title: node.title, children });
|
|
1327
|
-
break;
|
|
2456
|
+
const selfClosing = function(code) {
|
|
2457
|
+
if (code === findCode(pattern.end[pattern.end.length - 1])) {
|
|
2458
|
+
return tagEnd(code);
|
|
2459
|
+
}
|
|
2460
|
+
crash(
|
|
2461
|
+
code,
|
|
2462
|
+
"after self-closing slash",
|
|
2463
|
+
"`>` to end the tag" + (code === codes2.asterisk || code === codes2.slash ? " (note: JS comments in JSX tags are not supported in MDX)" : "")
|
|
2464
|
+
);
|
|
2465
|
+
};
|
|
2466
|
+
const tagEnd = function(code) {
|
|
2467
|
+
effects.enter(tagMarkerType);
|
|
2468
|
+
effects.consume(code);
|
|
2469
|
+
effects.exit(tagMarkerType);
|
|
2470
|
+
effects.exit(tagType);
|
|
2471
|
+
return ok;
|
|
2472
|
+
};
|
|
2473
|
+
const optionalEsWhitespace = function(code) {
|
|
2474
|
+
if (markdownLineEnding(code)) {
|
|
2475
|
+
if (allowLazy) {
|
|
2476
|
+
effects.enter(types.lineEnding);
|
|
2477
|
+
effects.consume(code);
|
|
2478
|
+
effects.exit(types.lineEnding);
|
|
2479
|
+
return factorySpace(
|
|
2480
|
+
effects,
|
|
2481
|
+
optionalEsWhitespace,
|
|
2482
|
+
types.linePrefix,
|
|
2483
|
+
constants.tabSize
|
|
2484
|
+
);
|
|
1328
2485
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
2486
|
+
return effects.attempt(
|
|
2487
|
+
lazyLineEnd,
|
|
2488
|
+
factorySpace(
|
|
2489
|
+
effects,
|
|
2490
|
+
optionalEsWhitespace,
|
|
2491
|
+
types.linePrefix,
|
|
2492
|
+
constants.tabSize
|
|
2493
|
+
),
|
|
2494
|
+
crashEol
|
|
2495
|
+
)(code);
|
|
2496
|
+
}
|
|
2497
|
+
if (markdownSpace(code) || unicodeWhitespace(code)) {
|
|
2498
|
+
effects.enter("esWhitespace");
|
|
2499
|
+
return optionalEsWhitespaceContinue(code);
|
|
2500
|
+
}
|
|
2501
|
+
return returnState(code);
|
|
2502
|
+
};
|
|
2503
|
+
const optionalEsWhitespaceContinue = function(code) {
|
|
2504
|
+
if (markdownLineEnding(code) || !(markdownSpace(code) || unicodeWhitespace(code))) {
|
|
2505
|
+
effects.exit("esWhitespace");
|
|
2506
|
+
return optionalEsWhitespace(code);
|
|
1340
2507
|
}
|
|
1341
|
-
|
|
2508
|
+
effects.consume(code);
|
|
2509
|
+
return optionalEsWhitespaceContinue;
|
|
1342
2510
|
};
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
2511
|
+
function crashEol() {
|
|
2512
|
+
throw new VFileMessage2(
|
|
2513
|
+
"Unexpected lazy line in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
|
|
2514
|
+
self.now(),
|
|
2515
|
+
"micromark-extension-mdx-jsx:unexpected-eof"
|
|
2516
|
+
);
|
|
2517
|
+
}
|
|
2518
|
+
function crash(code, at, expect) {
|
|
2519
|
+
throw new VFileMessage2(
|
|
2520
|
+
"Unexpected " + (code === codes2.eof ? "end of file" : "character `" + (code === codes2.graveAccent ? "` ` `" : String.fromCodePoint(code)) + "` (" + serializeCharCode(code) + ")") + " " + at + ", expected " + expect,
|
|
2521
|
+
self.now(),
|
|
2522
|
+
"micromark-extension-mdx-jsx:unexpected-" + (code === codes2.eof ? "eof" : "character")
|
|
2523
|
+
);
|
|
2524
|
+
}
|
|
2525
|
+
return start;
|
|
2526
|
+
}
|
|
2527
|
+
var tokenizeLazyLineEnd = function(effects, ok, nok) {
|
|
2528
|
+
const self = this;
|
|
2529
|
+
const start = function(code) {
|
|
2530
|
+
assert(markdownLineEnding(code), "expected eol");
|
|
2531
|
+
effects.enter(types.lineEnding);
|
|
2532
|
+
effects.consume(code);
|
|
2533
|
+
effects.exit(types.lineEnding);
|
|
2534
|
+
return lineStart;
|
|
1351
2535
|
};
|
|
1352
|
-
const
|
|
1353
|
-
return
|
|
1354
|
-
type: "text",
|
|
1355
|
-
text: content2.value
|
|
1356
|
-
};
|
|
2536
|
+
const lineStart = function(code) {
|
|
2537
|
+
return self.parser.lazy[self.now().line] ? nok(code) : ok(code);
|
|
1357
2538
|
};
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
2539
|
+
return start;
|
|
2540
|
+
};
|
|
2541
|
+
var serializeCharCode = function(code) {
|
|
2542
|
+
return "U+" + code.toString(constants.numericBaseHexadecimal).toUpperCase().padStart(4, "0");
|
|
2543
|
+
};
|
|
2544
|
+
var lazyLineEnd = { tokenize: tokenizeLazyLineEnd, partial: true };
|
|
2545
|
+
|
|
2546
|
+
// src/next/shortcodes/lib/jsx-text.ts
|
|
2547
|
+
var jsxText = function(acorn2, acornOptions, addResult, pattern) {
|
|
2548
|
+
const tokenizeJsxText = function(effects, ok, nok) {
|
|
2549
|
+
const self = this;
|
|
2550
|
+
return factoryTag.call(
|
|
2551
|
+
self,
|
|
2552
|
+
effects,
|
|
2553
|
+
ok,
|
|
2554
|
+
nok,
|
|
2555
|
+
acorn2,
|
|
2556
|
+
acornOptions,
|
|
2557
|
+
addResult,
|
|
2558
|
+
true,
|
|
2559
|
+
"mdxJsxTextTag",
|
|
2560
|
+
"mdxJsxTextTagMarker",
|
|
2561
|
+
"mdxJsxTextTagClosingMarker",
|
|
2562
|
+
"mdxJsxTextTagSelfClosingMarker",
|
|
2563
|
+
"mdxJsxTextTagName",
|
|
2564
|
+
"mdxJsxTextTagNamePrimary",
|
|
2565
|
+
"mdxJsxTextTagNameMemberMarker",
|
|
2566
|
+
"mdxJsxTextTagNameMember",
|
|
2567
|
+
"mdxJsxTextTagNamePrefixMarker",
|
|
2568
|
+
"mdxJsxTextTagNameLocal",
|
|
2569
|
+
"mdxJsxTextTagExpressionAttribute",
|
|
2570
|
+
"mdxJsxTextTagExpressionAttributeMarker",
|
|
2571
|
+
"mdxJsxTextTagExpressionAttributeValue",
|
|
2572
|
+
"mdxJsxTextTagAttribute",
|
|
2573
|
+
"mdxJsxTextTagAttributeName",
|
|
2574
|
+
"mdxJsxTextTagAttributeNamePrimary",
|
|
2575
|
+
"mdxJsxTextTagAttributeNamePrefixMarker",
|
|
2576
|
+
"mdxJsxTextTagAttributeNameLocal",
|
|
2577
|
+
"mdxJsxTextTagAttributeInitializerMarker",
|
|
2578
|
+
"mdxJsxTextTagAttributeValueLiteral",
|
|
2579
|
+
"mdxJsxTextTagAttributeValueLiteralMarker",
|
|
2580
|
+
"mdxJsxTextTagAttributeValueLiteralValue",
|
|
2581
|
+
"mdxJsxTextTagAttributeValueExpression",
|
|
2582
|
+
"mdxJsxTextTagAttributeValueExpressionMarker",
|
|
2583
|
+
"mdxJsxTextTagAttributeValueExpressionValue",
|
|
2584
|
+
pattern
|
|
2585
|
+
);
|
|
2586
|
+
};
|
|
2587
|
+
return { tokenize: tokenizeJsxText };
|
|
2588
|
+
};
|
|
2589
|
+
|
|
2590
|
+
// src/next/shortcodes/lib/jsx-flow.ts
|
|
2591
|
+
import { factorySpace as factorySpace2 } from "micromark-factory-space";
|
|
2592
|
+
import { markdownLineEnding as markdownLineEnding2 } from "micromark-util-character";
|
|
2593
|
+
import { codes as codes3 } from "micromark-util-symbol/codes.js";
|
|
2594
|
+
import { types as types2 } from "micromark-util-symbol/types.js";
|
|
2595
|
+
var jsxFlow = function(acorn2, acornOptions, addResult, pattern) {
|
|
2596
|
+
const tokenizeJsxFlow = function(effects, ok, nok) {
|
|
2597
|
+
const self = this;
|
|
2598
|
+
const start = function(code) {
|
|
2599
|
+
return factoryTag.call(
|
|
2600
|
+
self,
|
|
2601
|
+
effects,
|
|
2602
|
+
factorySpace2(effects, after, types2.whitespace),
|
|
2603
|
+
nok,
|
|
2604
|
+
acorn2,
|
|
2605
|
+
acornOptions,
|
|
2606
|
+
addResult,
|
|
2607
|
+
false,
|
|
2608
|
+
"mdxJsxFlowTag",
|
|
2609
|
+
"mdxJsxFlowTagMarker",
|
|
2610
|
+
"mdxJsxFlowTagClosingMarker",
|
|
2611
|
+
"mdxJsxFlowTagSelfClosingMarker",
|
|
2612
|
+
"mdxJsxFlowTagName",
|
|
2613
|
+
"mdxJsxFlowTagNamePrimary",
|
|
2614
|
+
"mdxJsxFlowTagNameMemberMarker",
|
|
2615
|
+
"mdxJsxFlowTagNameMember",
|
|
2616
|
+
"mdxJsxFlowTagNamePrefixMarker",
|
|
2617
|
+
"mdxJsxFlowTagNameLocal",
|
|
2618
|
+
"mdxJsxFlowTagExpressionAttribute",
|
|
2619
|
+
"mdxJsxFlowTagExpressionAttributeMarker",
|
|
2620
|
+
"mdxJsxFlowTagExpressionAttributeValue",
|
|
2621
|
+
"mdxJsxFlowTagAttribute",
|
|
2622
|
+
"mdxJsxFlowTagAttributeName",
|
|
2623
|
+
"mdxJsxFlowTagAttributeNamePrimary",
|
|
2624
|
+
"mdxJsxFlowTagAttributeNamePrefixMarker",
|
|
2625
|
+
"mdxJsxFlowTagAttributeNameLocal",
|
|
2626
|
+
"mdxJsxFlowTagAttributeInitializerMarker",
|
|
2627
|
+
"mdxJsxFlowTagAttributeValueLiteral",
|
|
2628
|
+
"mdxJsxFlowTagAttributeValueLiteralMarker",
|
|
2629
|
+
"mdxJsxFlowTagAttributeValueLiteralValue",
|
|
2630
|
+
"mdxJsxFlowTagAttributeValueExpression",
|
|
2631
|
+
"mdxJsxFlowTagAttributeValueExpressionMarker",
|
|
2632
|
+
"mdxJsxFlowTagAttributeValueExpressionValue",
|
|
2633
|
+
pattern
|
|
2634
|
+
)(code);
|
|
2635
|
+
};
|
|
2636
|
+
const after = function(code) {
|
|
2637
|
+
return code === codes3.lessThan ? start(code) : code === codes3.eof || markdownLineEnding2(code) ? ok(code) : nok(code);
|
|
1369
2638
|
};
|
|
2639
|
+
return start;
|
|
1370
2640
|
};
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
2641
|
+
return { tokenize: tokenizeJsxFlow, concrete: true };
|
|
2642
|
+
};
|
|
2643
|
+
|
|
2644
|
+
// src/next/shortcodes/lib/syntax.ts
|
|
2645
|
+
function mdxJsx(options = {}) {
|
|
2646
|
+
const acorn2 = options.acorn;
|
|
2647
|
+
let acornOptions;
|
|
2648
|
+
if (acorn2) {
|
|
2649
|
+
if (!acorn2.parse || !acorn2.parseExpressionAt) {
|
|
2650
|
+
throw new Error(
|
|
2651
|
+
"Expected a proper `acorn` instance passed in as `options.acorn`"
|
|
2652
|
+
);
|
|
2653
|
+
}
|
|
2654
|
+
acornOptions = Object.assign(
|
|
2655
|
+
{ ecmaVersion: 2020, sourceType: "module" },
|
|
2656
|
+
options.acornOptions,
|
|
2657
|
+
{ locations: true }
|
|
2658
|
+
);
|
|
2659
|
+
} else if (options.acornOptions || options.addResult) {
|
|
2660
|
+
throw new Error("Expected an `acorn` instance passed in as `options.acorn`");
|
|
2661
|
+
}
|
|
2662
|
+
const patterns = options.patterns || [];
|
|
2663
|
+
const flowRules = {};
|
|
2664
|
+
const textRules = {};
|
|
2665
|
+
patterns.forEach((pattern) => {
|
|
2666
|
+
const firstCharacter = findCode(pattern.start[0])?.toString();
|
|
2667
|
+
if (!firstCharacter) {
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
if (pattern.type === "flow") {
|
|
2671
|
+
const existing = flowRules[firstCharacter];
|
|
2672
|
+
flowRules[firstCharacter] = existing ? [
|
|
2673
|
+
...existing,
|
|
2674
|
+
jsxFlow(acorn2, acornOptions, options.addResult, pattern)
|
|
2675
|
+
] : [jsxFlow(acorn2, acornOptions, options.addResult, pattern)];
|
|
2676
|
+
} else {
|
|
2677
|
+
const existing = textRules[firstCharacter];
|
|
2678
|
+
textRules[firstCharacter] = existing ? [
|
|
2679
|
+
...existing,
|
|
2680
|
+
jsxText(acorn2, acornOptions, options.addResult, pattern)
|
|
2681
|
+
] : [jsxText(acorn2, acornOptions, options.addResult, pattern)];
|
|
2682
|
+
}
|
|
2683
|
+
});
|
|
2684
|
+
return {
|
|
2685
|
+
flow: flowRules,
|
|
2686
|
+
text: textRules
|
|
2687
|
+
};
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
// src/next/parse/markdown.ts
|
|
2691
|
+
import * as acorn from "acorn";
|
|
2692
|
+
var fromMarkdown = (value, field) => {
|
|
2693
|
+
const patterns = getFieldPatterns(field);
|
|
2694
|
+
const acornDefault = acorn;
|
|
2695
|
+
const tree = mdastFromMarkdown(value, {
|
|
2696
|
+
extensions: [mdxJsx({ acorn: acornDefault, patterns, addResult: true })],
|
|
2697
|
+
mdastExtensions: [mdxJsxFromMarkdown({ patterns })]
|
|
2698
|
+
});
|
|
2699
|
+
return tree;
|
|
2700
|
+
};
|
|
2701
|
+
|
|
2702
|
+
// src/next/parse/index.ts
|
|
2703
|
+
import { compact } from "mdast-util-compact";
|
|
2704
|
+
|
|
2705
|
+
// src/next/parse/post-processing.ts
|
|
2706
|
+
import { visit } from "unist-util-visit";
|
|
2707
|
+
|
|
2708
|
+
// src/parse/remarkToPlate.ts
|
|
2709
|
+
import { flatten } from "lodash-es";
|
|
2710
|
+
|
|
2711
|
+
// src/parse/acorn.ts
|
|
2712
|
+
var extractAttributes = (attributes2, fields, imageCallback) => {
|
|
2713
|
+
const properties = {};
|
|
2714
|
+
attributes2?.forEach((attribute) => {
|
|
2715
|
+
assertType(attribute, "mdxJsxAttribute");
|
|
2716
|
+
const field = fields.find((field2) => field2.name === attribute.name);
|
|
2717
|
+
if (!field) {
|
|
2718
|
+
throw new Error(
|
|
2719
|
+
`Unable to find field definition for property "${attribute.name}"`
|
|
2720
|
+
);
|
|
2721
|
+
}
|
|
2722
|
+
try {
|
|
2723
|
+
properties[attribute.name] = extractAttribute(
|
|
2724
|
+
attribute,
|
|
2725
|
+
field,
|
|
2726
|
+
imageCallback
|
|
2727
|
+
);
|
|
2728
|
+
} catch (e) {
|
|
2729
|
+
if (e instanceof Error) {
|
|
2730
|
+
throw new Error(
|
|
2731
|
+
`Unable to parse field value for field "${field.name}" (type: ${field.type}). ${e.message}`
|
|
2732
|
+
);
|
|
2733
|
+
}
|
|
2734
|
+
throw e;
|
|
2735
|
+
}
|
|
2736
|
+
});
|
|
2737
|
+
return properties;
|
|
2738
|
+
};
|
|
2739
|
+
var extractAttribute = (attribute, field, imageCallback) => {
|
|
2740
|
+
switch (field.type) {
|
|
2741
|
+
case "boolean":
|
|
2742
|
+
case "number":
|
|
2743
|
+
return extractScalar(extractExpression(attribute), field);
|
|
2744
|
+
case "datetime":
|
|
2745
|
+
case "string":
|
|
2746
|
+
if (field.list) {
|
|
2747
|
+
return extractScalar(extractExpression(attribute), field);
|
|
2748
|
+
} else {
|
|
2749
|
+
return extractString(attribute, field);
|
|
2750
|
+
}
|
|
2751
|
+
case "image":
|
|
2752
|
+
if (field.list) {
|
|
2753
|
+
const values3 = extractScalar(
|
|
2754
|
+
extractExpression(attribute),
|
|
2755
|
+
field
|
|
2756
|
+
);
|
|
2757
|
+
return values3.split(",").map((value) => imageCallback(value));
|
|
2758
|
+
} else {
|
|
2759
|
+
const value = extractString(attribute, field);
|
|
2760
|
+
return imageCallback(value);
|
|
2761
|
+
}
|
|
2762
|
+
case "reference":
|
|
2763
|
+
if (field.list) {
|
|
2764
|
+
return extractScalar(extractExpression(attribute), field);
|
|
2765
|
+
} else {
|
|
2766
|
+
return extractString(attribute, field);
|
|
2767
|
+
}
|
|
2768
|
+
case "object":
|
|
2769
|
+
return extractObject(extractExpression(attribute), field);
|
|
2770
|
+
case "rich-text":
|
|
2771
|
+
const JSXString = extractRaw(attribute);
|
|
2772
|
+
if (JSXString) {
|
|
2773
|
+
return parseMDX(JSXString, field, imageCallback);
|
|
2774
|
+
} else {
|
|
2775
|
+
return {};
|
|
1381
2776
|
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
type: "p",
|
|
1385
|
-
children
|
|
1386
|
-
};
|
|
1387
|
-
};
|
|
1388
|
-
return {
|
|
1389
|
-
type: "root",
|
|
1390
|
-
children: root.children.map((child) => {
|
|
1391
|
-
return content(child);
|
|
1392
|
-
})
|
|
1393
|
-
};
|
|
1394
|
-
};
|
|
1395
|
-
var RichTextParseError = class extends Error {
|
|
1396
|
-
constructor(message, position) {
|
|
1397
|
-
super(message);
|
|
1398
|
-
__publicField(this, "position");
|
|
1399
|
-
if (Error.captureStackTrace) {
|
|
1400
|
-
Error.captureStackTrace(this, RichTextParseError);
|
|
1401
|
-
}
|
|
1402
|
-
this.name = "RichTextParseError";
|
|
1403
|
-
this.position = position;
|
|
2777
|
+
default:
|
|
2778
|
+
throw new Error(`Extract attribute: Unhandled field type ${field.type}`);
|
|
1404
2779
|
}
|
|
1405
2780
|
};
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
};
|
|
1418
|
-
var enter = function(type, token) {
|
|
1419
|
-
this.enter({ type, name: "", attributes: {}, children: [] }, token);
|
|
1420
|
-
};
|
|
1421
|
-
function exitName(token) {
|
|
1422
|
-
const node = this.stack[this.stack.length - 1];
|
|
1423
|
-
node.name = this.sliceSerialize(token);
|
|
1424
|
-
}
|
|
1425
|
-
var enterContainerLabel = function(token) {
|
|
1426
|
-
this.enter({ type: "paragraph", data: { directiveLabel: true }, children: [] }, token);
|
|
1427
|
-
};
|
|
1428
|
-
var exitContainerLabel = function(token) {
|
|
1429
|
-
this.exit(token);
|
|
1430
|
-
};
|
|
1431
|
-
var enterAttributes = function() {
|
|
1432
|
-
this.setData("directiveAttributes", []);
|
|
1433
|
-
this.buffer();
|
|
1434
|
-
};
|
|
1435
|
-
var exitAttributeIdValue = function(token) {
|
|
1436
|
-
const list = this.getData("directiveAttributes");
|
|
1437
|
-
if (list) {
|
|
1438
|
-
list.push([
|
|
1439
|
-
"id",
|
|
1440
|
-
parseEntities(this.sliceSerialize(token), {
|
|
1441
|
-
attribute: true
|
|
1442
|
-
})
|
|
1443
|
-
]);
|
|
2781
|
+
var extractScalar = (attribute, field) => {
|
|
2782
|
+
if (field.list) {
|
|
2783
|
+
assertType(attribute.expression, "ArrayExpression");
|
|
2784
|
+
return attribute.expression.elements.map((element) => {
|
|
2785
|
+
assertHasType(element);
|
|
2786
|
+
assertType(element, "Literal");
|
|
2787
|
+
return element.value;
|
|
2788
|
+
});
|
|
2789
|
+
} else {
|
|
2790
|
+
assertType(attribute.expression, "Literal");
|
|
2791
|
+
return attribute.expression.value;
|
|
1444
2792
|
}
|
|
1445
2793
|
};
|
|
1446
|
-
var
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
2794
|
+
var extractObject = (attribute, field) => {
|
|
2795
|
+
if (field.list) {
|
|
2796
|
+
assertType(attribute.expression, "ArrayExpression");
|
|
2797
|
+
return attribute.expression.elements.map((element) => {
|
|
2798
|
+
assertHasType(element);
|
|
2799
|
+
assertType(element, "ObjectExpression");
|
|
2800
|
+
return extractObjectExpression(element, field);
|
|
2801
|
+
});
|
|
2802
|
+
} else {
|
|
2803
|
+
assertType(attribute.expression, "ObjectExpression");
|
|
2804
|
+
return extractObjectExpression(attribute.expression, field);
|
|
1455
2805
|
}
|
|
1456
2806
|
};
|
|
1457
|
-
var
|
|
1458
|
-
const
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
2807
|
+
var extractObjectExpression = (expression, field) => {
|
|
2808
|
+
const properties = {};
|
|
2809
|
+
expression.properties?.forEach((property) => {
|
|
2810
|
+
assertType(property, "Property");
|
|
2811
|
+
const { key, value } = extractKeyValue(property, field);
|
|
2812
|
+
properties[key] = value;
|
|
2813
|
+
});
|
|
2814
|
+
return properties;
|
|
2815
|
+
};
|
|
2816
|
+
var getField = (objectField, name) => {
|
|
2817
|
+
if (objectField.fields) {
|
|
2818
|
+
if (typeof objectField.fields === "string") {
|
|
2819
|
+
throw new Error("Global templates not supported");
|
|
1465
2820
|
}
|
|
2821
|
+
return objectField.fields.find((f) => f.name === name);
|
|
1466
2822
|
}
|
|
1467
2823
|
};
|
|
1468
|
-
var
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
2824
|
+
var extractKeyValue = (property, parentField) => {
|
|
2825
|
+
assertType(property.key, "Identifier");
|
|
2826
|
+
const key = property.key.name;
|
|
2827
|
+
const field = getField(parentField, key);
|
|
2828
|
+
if (field?.type === "object") {
|
|
2829
|
+
if (field.list) {
|
|
2830
|
+
assertType(property.value, "ArrayExpression");
|
|
2831
|
+
const value = property.value.elements.map((element) => {
|
|
2832
|
+
assertHasType(element);
|
|
2833
|
+
assertType(element, "ObjectExpression");
|
|
2834
|
+
return extractObjectExpression(element, field);
|
|
2835
|
+
});
|
|
2836
|
+
return { key, value };
|
|
1474
2837
|
} else {
|
|
1475
|
-
|
|
2838
|
+
assertType(property.value, "ObjectExpression");
|
|
2839
|
+
const value = extractObjectExpression(property.value, field);
|
|
2840
|
+
return { key, value };
|
|
1476
2841
|
}
|
|
2842
|
+
} else {
|
|
2843
|
+
assertType(property.value, "Literal");
|
|
2844
|
+
return { key, value: property.value.value };
|
|
1477
2845
|
}
|
|
1478
2846
|
};
|
|
1479
|
-
|
|
1480
|
-
const
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
const attribute = list[index];
|
|
1486
|
-
if (attribute) {
|
|
1487
|
-
if (attribute[0] === "class" && cleaned.class) {
|
|
1488
|
-
cleaned.class += " " + attribute[1];
|
|
1489
|
-
} else {
|
|
1490
|
-
cleaned[attribute[0]] = attribute[1];
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
2847
|
+
var extractStatement = (attribute) => {
|
|
2848
|
+
const body = attribute.data?.estree?.body;
|
|
2849
|
+
if (body) {
|
|
2850
|
+
if (body[0]) {
|
|
2851
|
+
assertType(body[0], "ExpressionStatement");
|
|
2852
|
+
return body[0];
|
|
1493
2853
|
}
|
|
1494
2854
|
}
|
|
1495
|
-
|
|
1496
|
-
this.resume();
|
|
1497
|
-
const node = this.stack[this.stack.length - 1];
|
|
1498
|
-
node.attributes = cleaned;
|
|
1499
|
-
}
|
|
1500
|
-
function exit(token) {
|
|
1501
|
-
this.exit(token);
|
|
1502
|
-
}
|
|
1503
|
-
var directiveFromMarkdown = {
|
|
1504
|
-
canContainEols: ["textDirective"],
|
|
1505
|
-
enter: {
|
|
1506
|
-
directiveContainer: enterContainer,
|
|
1507
|
-
directiveContainerAttributes: enterAttributes,
|
|
1508
|
-
directiveContainerLabel: enterContainerLabel,
|
|
1509
|
-
directiveLeaf: enterLeaf,
|
|
1510
|
-
directiveLeafAttributes: enterAttributes,
|
|
1511
|
-
directiveText: enterText,
|
|
1512
|
-
directiveTextAttributes: enterAttributes
|
|
1513
|
-
},
|
|
1514
|
-
exit: {
|
|
1515
|
-
directiveContainer: exit,
|
|
1516
|
-
directiveContainerAttributeClassValue: exitAttributeClassValue,
|
|
1517
|
-
directiveContainerAttributeIdValue: exitAttributeIdValue,
|
|
1518
|
-
directiveContainerAttributeName: exitAttributeName,
|
|
1519
|
-
directiveContainerAttributeValue: exitAttributeValue,
|
|
1520
|
-
directiveContainerAttributes: exitAttributes,
|
|
1521
|
-
directiveContainerLabel: exitContainerLabel,
|
|
1522
|
-
directiveContainerName: exitName,
|
|
1523
|
-
directiveLeaf: exit,
|
|
1524
|
-
directiveLeafAttributeClassValue: exitAttributeClassValue,
|
|
1525
|
-
directiveLeafAttributeIdValue: exitAttributeIdValue,
|
|
1526
|
-
directiveLeafAttributeName: exitAttributeName,
|
|
1527
|
-
directiveLeafAttributeValue: exitAttributeValue,
|
|
1528
|
-
directiveLeafAttributes: exitAttributes,
|
|
1529
|
-
directiveLeafName: exitName,
|
|
1530
|
-
directiveText: exit,
|
|
1531
|
-
directiveTextAttributeClassValue: exitAttributeClassValue,
|
|
1532
|
-
directiveTextAttributeIdValue: exitAttributeIdValue,
|
|
1533
|
-
directiveTextAttributeName: exitAttributeName,
|
|
1534
|
-
directiveTextAttributeValue: exitAttributeValue,
|
|
1535
|
-
directiveTextAttributes: exitAttributes,
|
|
1536
|
-
directiveTextName: exitName
|
|
1537
|
-
}
|
|
2855
|
+
throw new Error(`Unable to extract body from expression`);
|
|
1538
2856
|
};
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
import { codes as codes3 } from "micromark-util-symbol/codes";
|
|
1544
|
-
import { values } from "micromark-util-symbol/values";
|
|
1545
|
-
import { types as types2 } from "micromark-util-symbol/types";
|
|
1546
|
-
|
|
1547
|
-
// src/extensions/tina-shortcodes/factory-attributes.ts
|
|
1548
|
-
import { factorySpace } from "micromark-factory-space";
|
|
1549
|
-
import { factoryWhitespace } from "micromark-factory-whitespace";
|
|
1550
|
-
import {
|
|
1551
|
-
asciiAlpha,
|
|
1552
|
-
asciiAlphanumeric,
|
|
1553
|
-
markdownLineEnding,
|
|
1554
|
-
markdownLineEndingOrSpace,
|
|
1555
|
-
markdownSpace
|
|
1556
|
-
} from "micromark-util-character";
|
|
1557
|
-
import { codes } from "micromark-util-symbol/codes";
|
|
1558
|
-
import { types } from "micromark-util-symbol/types";
|
|
1559
|
-
function factoryAttributes(effects, ok, nnok, attributesType, attributesMarkerType, attributeType, attributeIdType, attributeClassType, attributeNameType, attributeInitializerType, attributeValueLiteralType, attributeValueType, attributeValueMarker, attributeValueData, disallowEol) {
|
|
1560
|
-
let type;
|
|
1561
|
-
let marker;
|
|
1562
|
-
const nok = function(code) {
|
|
1563
|
-
return nnok(code);
|
|
1564
|
-
};
|
|
1565
|
-
const start = function(code) {
|
|
1566
|
-
effects.enter(attributesType);
|
|
1567
|
-
return between(code);
|
|
1568
|
-
};
|
|
1569
|
-
const between = function(code) {
|
|
1570
|
-
if (code === codes.numberSign) {
|
|
1571
|
-
type = attributeIdType;
|
|
1572
|
-
return shortcutStart(code);
|
|
1573
|
-
}
|
|
1574
|
-
if (code === codes.dot) {
|
|
1575
|
-
type = attributeClassType;
|
|
1576
|
-
return shortcutStart(code);
|
|
1577
|
-
}
|
|
1578
|
-
if (code === codes.colon || code === codes.underscore || asciiAlpha(code)) {
|
|
1579
|
-
effects.enter(attributeType);
|
|
1580
|
-
effects.enter(attributeNameType);
|
|
1581
|
-
effects.consume(code);
|
|
1582
|
-
return name;
|
|
1583
|
-
}
|
|
1584
|
-
if (code === codes.quotationMark || code === codes.apostrophe) {
|
|
1585
|
-
effects.enter(attributeNameType);
|
|
1586
|
-
effects.exit(attributeNameType);
|
|
1587
|
-
effects.enter(attributeType);
|
|
1588
|
-
return valueBefore(code);
|
|
1589
|
-
}
|
|
1590
|
-
if (disallowEol && markdownSpace(code)) {
|
|
1591
|
-
return factorySpace(effects, between, types.whitespace)(code);
|
|
1592
|
-
}
|
|
1593
|
-
if (!disallowEol && markdownLineEndingOrSpace(code)) {
|
|
1594
|
-
return factoryWhitespace(effects, between)(code);
|
|
1595
|
-
}
|
|
1596
|
-
return end(code);
|
|
1597
|
-
};
|
|
1598
|
-
const shortcutStart = function(code) {
|
|
1599
|
-
effects.enter(attributeType);
|
|
1600
|
-
effects.enter(type);
|
|
1601
|
-
effects.enter(type + "Marker");
|
|
1602
|
-
effects.consume(code);
|
|
1603
|
-
effects.exit(type + "Marker");
|
|
1604
|
-
return shortcutStartAfter;
|
|
1605
|
-
};
|
|
1606
|
-
const shortcutStartAfter = function(code) {
|
|
1607
|
-
if (code === codes.eof || code === codes.quotationMark || code === codes.numberSign || code === codes.apostrophe || code === codes.dot || code === codes.lessThan || code === codes.equalsTo || code === codes.greaterThan || code === codes.graveAccent || code === codes.rightCurlyBrace || markdownLineEndingOrSpace(code)) {
|
|
1608
|
-
return nok(code);
|
|
1609
|
-
}
|
|
1610
|
-
effects.enter(type + "Value");
|
|
1611
|
-
effects.consume(code);
|
|
1612
|
-
return shortcut;
|
|
1613
|
-
};
|
|
1614
|
-
const shortcut = function(code) {
|
|
1615
|
-
if (code === codes.eof || code === codes.quotationMark || code === codes.apostrophe || code === codes.lessThan || code === codes.equalsTo || code === codes.greaterThan || code === codes.graveAccent) {
|
|
1616
|
-
return nok(code);
|
|
1617
|
-
}
|
|
1618
|
-
if (code === codes.numberSign || code === codes.dot || code === codes.rightCurlyBrace || markdownLineEndingOrSpace(code)) {
|
|
1619
|
-
effects.exit(type + "Value");
|
|
1620
|
-
effects.exit(type);
|
|
1621
|
-
effects.exit(attributeType);
|
|
1622
|
-
return between(code);
|
|
1623
|
-
}
|
|
1624
|
-
effects.consume(code);
|
|
1625
|
-
return shortcut;
|
|
1626
|
-
};
|
|
1627
|
-
const name = function(code) {
|
|
1628
|
-
if (code === codes.dash || code === codes.dot || code === codes.colon || code === codes.underscore || asciiAlphanumeric(code)) {
|
|
1629
|
-
effects.consume(code);
|
|
1630
|
-
return name;
|
|
1631
|
-
}
|
|
1632
|
-
effects.exit(attributeNameType);
|
|
1633
|
-
if (disallowEol && markdownSpace(code)) {
|
|
1634
|
-
return factorySpace(effects, nameAfter, types.whitespace)(code);
|
|
1635
|
-
}
|
|
1636
|
-
if (!disallowEol && markdownLineEndingOrSpace(code)) {
|
|
1637
|
-
return factoryWhitespace(effects, nameAfter)(code);
|
|
1638
|
-
}
|
|
1639
|
-
return nameAfter(code);
|
|
1640
|
-
};
|
|
1641
|
-
const nameAfter = function(code) {
|
|
1642
|
-
if (code === codes.equalsTo) {
|
|
1643
|
-
effects.enter(attributeInitializerType);
|
|
1644
|
-
effects.consume(code);
|
|
1645
|
-
effects.exit(attributeInitializerType);
|
|
1646
|
-
return valueBefore;
|
|
1647
|
-
}
|
|
1648
|
-
effects.exit(attributeType);
|
|
1649
|
-
return between(code);
|
|
1650
|
-
};
|
|
1651
|
-
const valueBefore = function(code) {
|
|
1652
|
-
if (code === codes.eof || code === codes.lessThan || code === codes.equalsTo || code === codes.greaterThan || code === codes.graveAccent || code === codes.rightCurlyBrace || disallowEol && markdownLineEnding(code)) {
|
|
1653
|
-
return nok(code);
|
|
1654
|
-
}
|
|
1655
|
-
if (code === codes.quotationMark || code === codes.apostrophe) {
|
|
1656
|
-
effects.enter(attributeValueLiteralType);
|
|
1657
|
-
effects.enter(attributeValueMarker);
|
|
1658
|
-
effects.consume(code);
|
|
1659
|
-
effects.exit(attributeValueMarker);
|
|
1660
|
-
marker = code;
|
|
1661
|
-
return valueQuotedStart;
|
|
1662
|
-
}
|
|
1663
|
-
if (disallowEol && markdownSpace(code)) {
|
|
1664
|
-
return factorySpace(effects, valueBefore, types.whitespace)(code);
|
|
1665
|
-
}
|
|
1666
|
-
if (!disallowEol && markdownLineEndingOrSpace(code)) {
|
|
1667
|
-
return factoryWhitespace(effects, valueBefore)(code);
|
|
1668
|
-
}
|
|
1669
|
-
effects.enter(attributeValueType);
|
|
1670
|
-
effects.enter(attributeValueData);
|
|
1671
|
-
effects.consume(code);
|
|
1672
|
-
marker = void 0;
|
|
1673
|
-
return valueUnquoted;
|
|
1674
|
-
};
|
|
1675
|
-
const valueUnquoted = function(code) {
|
|
1676
|
-
if (code === codes.eof || code === codes.quotationMark || code === codes.apostrophe || code === codes.lessThan || code === codes.equalsTo || code === codes.greaterThan || code === codes.graveAccent) {
|
|
1677
|
-
return nok(code);
|
|
1678
|
-
}
|
|
1679
|
-
if (code === codes.rightCurlyBrace || markdownLineEndingOrSpace(code)) {
|
|
1680
|
-
effects.exit(attributeValueData);
|
|
1681
|
-
effects.exit(attributeValueType);
|
|
1682
|
-
effects.exit(attributeType);
|
|
1683
|
-
return between(code);
|
|
1684
|
-
}
|
|
1685
|
-
effects.consume(code);
|
|
1686
|
-
return valueUnquoted;
|
|
1687
|
-
};
|
|
1688
|
-
const valueQuotedStart = function(code) {
|
|
1689
|
-
if (code === marker) {
|
|
1690
|
-
effects.enter(attributeValueMarker);
|
|
1691
|
-
effects.consume(code);
|
|
1692
|
-
effects.exit(attributeValueMarker);
|
|
1693
|
-
effects.exit(attributeValueLiteralType);
|
|
1694
|
-
effects.exit(attributeType);
|
|
1695
|
-
return valueQuotedAfter;
|
|
1696
|
-
}
|
|
1697
|
-
effects.enter(attributeValueType);
|
|
1698
|
-
return valueQuotedBetween(code);
|
|
1699
|
-
};
|
|
1700
|
-
const valueQuotedBetween = function(code) {
|
|
1701
|
-
if (code === marker) {
|
|
1702
|
-
effects.exit(attributeValueType);
|
|
1703
|
-
return valueQuotedStart(code);
|
|
1704
|
-
}
|
|
1705
|
-
if (code === codes.eof) {
|
|
1706
|
-
return nok(code);
|
|
2857
|
+
var extractString = (attribute, field) => {
|
|
2858
|
+
if (attribute.type === "mdxJsxAttribute") {
|
|
2859
|
+
if (typeof attribute.value === "string") {
|
|
2860
|
+
return attribute.value;
|
|
1707
2861
|
}
|
|
1708
|
-
|
|
1709
|
-
|
|
2862
|
+
}
|
|
2863
|
+
return extractScalar(extractExpression(attribute), field);
|
|
2864
|
+
};
|
|
2865
|
+
var extractExpression = (attribute) => {
|
|
2866
|
+
assertType(attribute, "mdxJsxAttribute");
|
|
2867
|
+
assertHasType(attribute.value);
|
|
2868
|
+
assertType(attribute.value, "mdxJsxAttributeValueExpression");
|
|
2869
|
+
return extractStatement(attribute.value);
|
|
2870
|
+
};
|
|
2871
|
+
var extractRaw = (attribute) => {
|
|
2872
|
+
assertType(attribute, "mdxJsxAttribute");
|
|
2873
|
+
assertHasType(attribute.value);
|
|
2874
|
+
assertType(attribute.value, "mdxJsxAttributeValueExpression");
|
|
2875
|
+
const rawValue = attribute.value.value;
|
|
2876
|
+
return trimFragments(rawValue);
|
|
2877
|
+
};
|
|
2878
|
+
function assertType(val, type) {
|
|
2879
|
+
if (val.type !== type) {
|
|
2880
|
+
throw new Error(
|
|
2881
|
+
`Expected type to be ${type} but received ${val.type}. ${MDX_PARSE_ERROR_MSG}`
|
|
2882
|
+
);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
function assertHasType(val) {
|
|
2886
|
+
if (val) {
|
|
2887
|
+
if (typeof val !== "string") {
|
|
2888
|
+
return;
|
|
1710
2889
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
const
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
2890
|
+
}
|
|
2891
|
+
throw new Error(`Expect value to be an object with property "type"`);
|
|
2892
|
+
}
|
|
2893
|
+
var trimFragments = (string) => {
|
|
2894
|
+
const rawArr = string.split("\n");
|
|
2895
|
+
let openingFragmentIndex = null;
|
|
2896
|
+
let closingFragmentIndex = null;
|
|
2897
|
+
rawArr.forEach((item, index) => {
|
|
2898
|
+
if (item.trim() === "<>") {
|
|
2899
|
+
if (!openingFragmentIndex) {
|
|
2900
|
+
openingFragmentIndex = index + 1;
|
|
2901
|
+
}
|
|
1719
2902
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
if (!asciiAlpha(code)) {
|
|
1728
|
-
effects.enter(attributesMarkerType);
|
|
1729
|
-
effects.exit(attributesMarkerType);
|
|
1730
|
-
effects.exit(attributesType);
|
|
1731
|
-
return ok(code);
|
|
2903
|
+
});
|
|
2904
|
+
rawArr.reverse().forEach((item, index) => {
|
|
2905
|
+
if (item.trim() === "</>") {
|
|
2906
|
+
const length = rawArr.length - 1;
|
|
2907
|
+
if (!closingFragmentIndex) {
|
|
2908
|
+
closingFragmentIndex = length - index;
|
|
2909
|
+
}
|
|
1732
2910
|
}
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
return
|
|
1736
|
-
}
|
|
2911
|
+
});
|
|
2912
|
+
const value = rawArr.reverse().slice(openingFragmentIndex || 0, closingFragmentIndex || rawArr.length - 1).join("\n");
|
|
2913
|
+
return value;
|
|
2914
|
+
};
|
|
1737
2915
|
|
|
1738
|
-
// src/
|
|
1739
|
-
import {
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
if (
|
|
1747
|
-
|
|
1748
|
-
effects.enter(type);
|
|
1749
|
-
effects.consume(code);
|
|
1750
|
-
return name;
|
|
2916
|
+
// src/parse/mdx.ts
|
|
2917
|
+
import { source } from "unist-util-source";
|
|
2918
|
+
function mdxJsxElement(node, field, imageCallback) {
|
|
2919
|
+
try {
|
|
2920
|
+
const template = field.templates?.find((template2) => {
|
|
2921
|
+
const templateName = typeof template2 === "string" ? template2 : template2.name;
|
|
2922
|
+
return templateName === node.name;
|
|
2923
|
+
});
|
|
2924
|
+
if (typeof template === "string") {
|
|
2925
|
+
throw new Error("Global templates not yet supported");
|
|
1751
2926
|
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
2927
|
+
if (!template) {
|
|
2928
|
+
const string = toTinaMarkdown2({ type: "root", children: [node] }, field);
|
|
2929
|
+
return {
|
|
2930
|
+
type: node.type === "mdxJsxFlowElement" ? "html" : "html_inline",
|
|
2931
|
+
value: string.trim(),
|
|
2932
|
+
children: [{ type: "text", text: "" }]
|
|
2933
|
+
};
|
|
2934
|
+
}
|
|
2935
|
+
const props = extractAttributes(
|
|
2936
|
+
node.attributes,
|
|
2937
|
+
template.fields,
|
|
2938
|
+
imageCallback
|
|
2939
|
+
);
|
|
2940
|
+
const childField = template.fields.find(
|
|
2941
|
+
(field2) => field2.name === "children"
|
|
2942
|
+
);
|
|
2943
|
+
if (childField) {
|
|
2944
|
+
if (childField.type === "rich-text") {
|
|
2945
|
+
props.children = remarkToSlate(node, childField, imageCallback);
|
|
1761
2946
|
}
|
|
1762
|
-
return nok(code);
|
|
1763
2947
|
}
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
1774
|
-
if (value === string) {
|
|
1775
|
-
lookupValue = key;
|
|
2948
|
+
return {
|
|
2949
|
+
type: node.type,
|
|
2950
|
+
name: node.name,
|
|
2951
|
+
children: [{ type: "text", text: "" }],
|
|
2952
|
+
props
|
|
2953
|
+
};
|
|
2954
|
+
} catch (e) {
|
|
2955
|
+
if (e instanceof Error) {
|
|
2956
|
+
throw new RichTextParseError(e.message, node.position);
|
|
1776
2957
|
}
|
|
2958
|
+
throw e;
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
var directiveElement = (node, field, imageCallback, raw) => {
|
|
2962
|
+
let template;
|
|
2963
|
+
template = field.templates?.find((template2) => {
|
|
2964
|
+
const templateName = typeof template2 === "string" ? template2 : template2.name;
|
|
2965
|
+
return templateName === node.name;
|
|
1777
2966
|
});
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
var findCode = (string) => {
|
|
1781
|
-
if (!string) {
|
|
1782
|
-
return null;
|
|
2967
|
+
if (typeof template === "string") {
|
|
2968
|
+
throw new Error("Global templates not yet supported");
|
|
1783
2969
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
if (key === lookup) {
|
|
1789
|
-
lookupValue = value;
|
|
1790
|
-
}
|
|
2970
|
+
if (!template) {
|
|
2971
|
+
template = field.templates?.find((template2) => {
|
|
2972
|
+
const templateName = template2?.match?.name;
|
|
2973
|
+
return templateName === node.name;
|
|
1791
2974
|
});
|
|
1792
2975
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
const self = this;
|
|
1798
|
-
let startSequenceIndex = 1;
|
|
1799
|
-
let endSequenceIndex = 0;
|
|
1800
|
-
const ok = function(code) {
|
|
1801
|
-
return ook(code);
|
|
1802
|
-
};
|
|
1803
|
-
const nok = function(code) {
|
|
1804
|
-
return nnok(code);
|
|
1805
|
-
};
|
|
1806
|
-
const start = function(code) {
|
|
1807
|
-
const firstCharacter = pattern.start[0];
|
|
1808
|
-
if (findCode(firstCharacter) === code) {
|
|
1809
|
-
effects.enter("directiveLeaf");
|
|
1810
|
-
effects.enter("directiveLeafFence");
|
|
1811
|
-
effects.enter("directiveLeafSequence");
|
|
1812
|
-
effects.consume(code);
|
|
1813
|
-
return sequenceOpen(code);
|
|
1814
|
-
}
|
|
1815
|
-
return nok(code);
|
|
1816
|
-
};
|
|
1817
|
-
const sequenceOpen = function(code) {
|
|
1818
|
-
const nextCharacter = pattern.start[startSequenceIndex];
|
|
1819
|
-
if (findCode(nextCharacter) === code) {
|
|
1820
|
-
effects.consume(code);
|
|
1821
|
-
startSequenceIndex++;
|
|
1822
|
-
return sequenceOpen;
|
|
1823
|
-
}
|
|
1824
|
-
if (startSequenceIndex < pattern.start.length) {
|
|
1825
|
-
return nok(code);
|
|
1826
|
-
}
|
|
1827
|
-
effects.exit("directiveLeafSequence");
|
|
1828
|
-
return factorName(code);
|
|
1829
|
-
};
|
|
1830
|
-
const factorName = (code) => {
|
|
1831
|
-
if (markdownSpace2(code)) {
|
|
1832
|
-
return factorySpace2(effects, factorName, types2.whitespace)(code);
|
|
1833
|
-
}
|
|
1834
|
-
return factoryName.call(self, effects, afterName, nok, "directiveLeafName", pattern.name || pattern.templateName)(code);
|
|
1835
|
-
};
|
|
1836
|
-
const afterName = function(code) {
|
|
1837
|
-
if (markdownSpace2(code)) {
|
|
1838
|
-
return factorySpace2(effects, afterName, types2.whitespace)(code);
|
|
1839
|
-
}
|
|
1840
|
-
if (markdownLineEnding2(code)) {
|
|
1841
|
-
return nok;
|
|
1842
|
-
}
|
|
1843
|
-
return startAttributes;
|
|
1844
|
-
};
|
|
1845
|
-
const startAttributes = function(code) {
|
|
1846
|
-
const nextCharacter = pattern.end[endSequenceIndex];
|
|
1847
|
-
if (findCode(nextCharacter) === code) {
|
|
1848
|
-
return afterAttributes(code);
|
|
1849
|
-
}
|
|
1850
|
-
return effects.attempt(attributes2, afterAttributes, afterAttributes)(code);
|
|
1851
|
-
};
|
|
1852
|
-
const end = function(code) {
|
|
1853
|
-
effects.exit("directiveLeafFence");
|
|
1854
|
-
effects.exit("directiveLeaf");
|
|
1855
|
-
return ok(code);
|
|
2976
|
+
if (!template) {
|
|
2977
|
+
return {
|
|
2978
|
+
type: "p",
|
|
2979
|
+
children: [{ type: "text", text: source(node, raw || "") || "" }]
|
|
1856
2980
|
};
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
if (
|
|
1866
|
-
|
|
1867
|
-
endSequenceIndex++;
|
|
1868
|
-
return afterAttributes;
|
|
2981
|
+
}
|
|
2982
|
+
if (typeof template === "string") {
|
|
2983
|
+
throw new Error(`Global templates not supported`);
|
|
2984
|
+
}
|
|
2985
|
+
const props = node.attributes || {};
|
|
2986
|
+
const childField = template.fields.find((field2) => field2.name === "children");
|
|
2987
|
+
if (childField) {
|
|
2988
|
+
if (childField.type === "rich-text") {
|
|
2989
|
+
if (node.type === "containerDirective") {
|
|
2990
|
+
props.children = remarkToSlate(node, childField, imageCallback, raw);
|
|
1869
2991
|
}
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
return start;
|
|
1873
|
-
};
|
|
1874
|
-
const tokenizeAttributes = function(effects, ok, nok) {
|
|
1875
|
-
return factoryAttributes(effects, ok, nok, "directiveLeafAttributes", "directiveLeafAttributesMarker", "directiveLeafAttribute", "directiveLeafAttributeId", "directiveLeafAttributeClass", "directiveLeafAttributeName", "directiveLeafAttributeInitializerMarker", "directiveLeafAttributeValueLiteral", "directiveLeafAttributeValue", "directiveLeafAttributeValueMarker", "directiveLeafAttributeValueData", true);
|
|
1876
|
-
};
|
|
1877
|
-
const attributes2 = { tokenize: tokenizeAttributes, partial: true };
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
1878
2994
|
return {
|
|
1879
|
-
|
|
2995
|
+
type: "mdxJsxFlowElement",
|
|
2996
|
+
name: template.name,
|
|
2997
|
+
props,
|
|
2998
|
+
children: [{ type: "text", text: "" }]
|
|
1880
2999
|
};
|
|
1881
3000
|
};
|
|
1882
3001
|
|
|
1883
|
-
// src/
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
return
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
3002
|
+
// src/parse/remarkToPlate.ts
|
|
3003
|
+
var remarkToSlate = (root, field, imageCallback, raw, skipMDXProcess) => {
|
|
3004
|
+
const mdxJsxElement2 = skipMDXProcess ? (node) => node : mdxJsxElement;
|
|
3005
|
+
const content = (content2) => {
|
|
3006
|
+
switch (content2.type) {
|
|
3007
|
+
case "blockquote":
|
|
3008
|
+
const children = [];
|
|
3009
|
+
content2.children.map((child) => {
|
|
3010
|
+
const inlineElements = unwrapBlockContent(child);
|
|
3011
|
+
inlineElements.forEach((child2) => {
|
|
3012
|
+
children.push(child2);
|
|
3013
|
+
});
|
|
3014
|
+
});
|
|
3015
|
+
return {
|
|
3016
|
+
type: "blockquote",
|
|
3017
|
+
children
|
|
3018
|
+
};
|
|
3019
|
+
case "heading":
|
|
3020
|
+
return heading(content2);
|
|
3021
|
+
case "code":
|
|
3022
|
+
return code(content2);
|
|
3023
|
+
case "paragraph":
|
|
3024
|
+
return paragraph(content2);
|
|
3025
|
+
case "mdxJsxFlowElement":
|
|
3026
|
+
return mdxJsxElement2(content2, field, imageCallback);
|
|
3027
|
+
case "thematicBreak":
|
|
3028
|
+
return {
|
|
3029
|
+
type: "hr",
|
|
3030
|
+
children: [{ type: "text", text: "" }]
|
|
3031
|
+
};
|
|
3032
|
+
case "listItem":
|
|
3033
|
+
return {
|
|
3034
|
+
type: "li",
|
|
3035
|
+
children: [
|
|
3036
|
+
{
|
|
3037
|
+
type: "lic",
|
|
3038
|
+
children: flatten(
|
|
3039
|
+
content2.children.map((child) => unwrapBlockContent(child))
|
|
3040
|
+
)
|
|
3041
|
+
}
|
|
3042
|
+
]
|
|
3043
|
+
};
|
|
3044
|
+
case "list":
|
|
3045
|
+
return list(content2);
|
|
3046
|
+
case "html":
|
|
3047
|
+
return html(content2);
|
|
3048
|
+
case "mdxFlowExpression":
|
|
3049
|
+
case "mdxjsEsm":
|
|
3050
|
+
throw new RichTextParseError(
|
|
3051
|
+
`Unexpected expression ${content2.value}.`,
|
|
3052
|
+
content2.position
|
|
3053
|
+
);
|
|
3054
|
+
case "leafDirective": {
|
|
3055
|
+
return directiveElement(content2, field, imageCallback, raw);
|
|
1924
3056
|
}
|
|
1925
|
-
|
|
1926
|
-
return
|
|
3057
|
+
case "containerDirective": {
|
|
3058
|
+
return directiveElement(content2, field, imageCallback, raw);
|
|
1927
3059
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
3060
|
+
default:
|
|
3061
|
+
throw new RichTextParseError(
|
|
3062
|
+
`Content: ${content2.type} is not yet supported`,
|
|
3063
|
+
content2.position
|
|
3064
|
+
);
|
|
3065
|
+
}
|
|
3066
|
+
};
|
|
3067
|
+
const html = (content2) => {
|
|
3068
|
+
return {
|
|
3069
|
+
type: "p",
|
|
3070
|
+
children: [{ type: "text", text: content2.value }]
|
|
1930
3071
|
};
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
3072
|
+
};
|
|
3073
|
+
const html_inline = (content2) => {
|
|
3074
|
+
return { type: "text", text: content2.value };
|
|
3075
|
+
};
|
|
3076
|
+
const list = (content2) => {
|
|
3077
|
+
return {
|
|
3078
|
+
type: content2.ordered ? "ol" : "ul",
|
|
3079
|
+
children: content2.children.map((child) => listItem(child))
|
|
1936
3080
|
};
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
3081
|
+
};
|
|
3082
|
+
const listItem = (content2) => {
|
|
3083
|
+
return {
|
|
3084
|
+
type: "li",
|
|
3085
|
+
children: content2.children.map((child) => {
|
|
3086
|
+
switch (child.type) {
|
|
3087
|
+
case "list":
|
|
3088
|
+
return list(child);
|
|
3089
|
+
case "heading":
|
|
3090
|
+
case "paragraph":
|
|
3091
|
+
return {
|
|
3092
|
+
type: "lic",
|
|
3093
|
+
children: flatten(
|
|
3094
|
+
child.children.map((child2) => phrasingContent(child2))
|
|
3095
|
+
)
|
|
3096
|
+
};
|
|
3097
|
+
case "blockquote": {
|
|
3098
|
+
return {
|
|
3099
|
+
...blockquote(child),
|
|
3100
|
+
type: "lic"
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3103
|
+
case "mdxJsxFlowElement":
|
|
3104
|
+
return {
|
|
3105
|
+
type: "lic",
|
|
3106
|
+
children: [
|
|
3107
|
+
mdxJsxElement2(
|
|
3108
|
+
{ ...child, type: "mdxJsxTextElement" },
|
|
3109
|
+
field,
|
|
3110
|
+
imageCallback
|
|
3111
|
+
)
|
|
3112
|
+
]
|
|
3113
|
+
};
|
|
3114
|
+
case "html":
|
|
3115
|
+
return {
|
|
3116
|
+
type: "lic",
|
|
3117
|
+
children: html_inline(child)
|
|
3118
|
+
};
|
|
3119
|
+
case "leafDirective": {
|
|
3120
|
+
return {
|
|
3121
|
+
type: "lic",
|
|
3122
|
+
children: [directiveElement(child, field, imageCallback)]
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
case "code":
|
|
3126
|
+
case "thematicBreak":
|
|
3127
|
+
case "table":
|
|
3128
|
+
throw new RichTextParseError(
|
|
3129
|
+
`${child.type} inside list item is not supported`,
|
|
3130
|
+
child.position
|
|
3131
|
+
);
|
|
3132
|
+
default:
|
|
3133
|
+
let position;
|
|
3134
|
+
if (child.type !== "containerDirective") {
|
|
3135
|
+
position = child.position;
|
|
3136
|
+
}
|
|
3137
|
+
throw new RichTextParseError(
|
|
3138
|
+
`Unknown list item of type ${child.type}`,
|
|
3139
|
+
position
|
|
3140
|
+
);
|
|
3141
|
+
}
|
|
3142
|
+
})
|
|
3143
|
+
};
|
|
3144
|
+
};
|
|
3145
|
+
const unwrapBlockContent = (content2) => {
|
|
3146
|
+
const flattenPhrasingContent = (children) => {
|
|
3147
|
+
const children2 = children.map((child) => phrasingContent(child));
|
|
3148
|
+
return flatten(Array.isArray(children2) ? children2 : [children2]);
|
|
3149
|
+
};
|
|
3150
|
+
switch (content2.type) {
|
|
3151
|
+
case "heading":
|
|
3152
|
+
case "paragraph":
|
|
3153
|
+
return flattenPhrasingContent(content2.children);
|
|
3154
|
+
case "html":
|
|
3155
|
+
return [html_inline(content2)];
|
|
3156
|
+
case "blockquote":
|
|
3157
|
+
default:
|
|
3158
|
+
throw new RichTextParseError(
|
|
3159
|
+
`UnwrapBlock: Unknown block content of type ${content2.type}`,
|
|
3160
|
+
content2.position
|
|
3161
|
+
);
|
|
3162
|
+
}
|
|
3163
|
+
};
|
|
3164
|
+
const code = (content2) => {
|
|
3165
|
+
const extra = {};
|
|
3166
|
+
if (content2.lang)
|
|
3167
|
+
extra["lang"] = content2.lang;
|
|
3168
|
+
return {
|
|
3169
|
+
type: "code_block",
|
|
3170
|
+
...extra,
|
|
3171
|
+
value: content2.value,
|
|
3172
|
+
children: [{ type: "text", text: "" }]
|
|
1945
3173
|
};
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
3174
|
+
};
|
|
3175
|
+
const link = (content2) => {
|
|
3176
|
+
return {
|
|
3177
|
+
type: "a",
|
|
3178
|
+
url: content2.url,
|
|
3179
|
+
title: content2.title,
|
|
3180
|
+
children: flatten(
|
|
3181
|
+
content2.children.map((child) => staticPhrasingContent(child))
|
|
3182
|
+
)
|
|
1952
3183
|
};
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
if (findCode(nextCharacter) === code) {
|
|
1959
|
-
effects.consume(code);
|
|
1960
|
-
endSequenceIndex++;
|
|
1961
|
-
return afterAttributes;
|
|
1962
|
-
}
|
|
1963
|
-
if (pattern.end.length === endSequenceIndex) {
|
|
1964
|
-
return factorySpace3(effects, openAfter, types3.whitespace)(code);
|
|
1965
|
-
}
|
|
1966
|
-
return nok;
|
|
3184
|
+
};
|
|
3185
|
+
const heading = (content2) => {
|
|
3186
|
+
return {
|
|
3187
|
+
type: ["h1", "h2", "h3", "h4", "h5", "h6"][content2.depth - 1],
|
|
3188
|
+
children: flatten(content2.children.map(phrasingContent))
|
|
1967
3189
|
};
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
3190
|
+
};
|
|
3191
|
+
const staticPhrasingContent = (content2) => {
|
|
3192
|
+
switch (content2.type) {
|
|
3193
|
+
case "mdxJsxTextElement":
|
|
3194
|
+
return mdxJsxElement2(content2, field, imageCallback);
|
|
3195
|
+
case "text":
|
|
3196
|
+
return text5(content2);
|
|
3197
|
+
case "inlineCode":
|
|
3198
|
+
case "emphasis":
|
|
3199
|
+
case "image":
|
|
3200
|
+
case "strong":
|
|
3201
|
+
return phrashingMark(content2);
|
|
3202
|
+
case "html":
|
|
3203
|
+
return html_inline(content2);
|
|
3204
|
+
default:
|
|
3205
|
+
throw new Error(
|
|
3206
|
+
`StaticPhrasingContent: ${content2.type} is not yet supported`
|
|
3207
|
+
);
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
const phrasingContent = (content2) => {
|
|
3211
|
+
switch (content2.type) {
|
|
3212
|
+
case "text":
|
|
3213
|
+
return text5(content2);
|
|
3214
|
+
case "link":
|
|
3215
|
+
return link(content2);
|
|
3216
|
+
case "image":
|
|
3217
|
+
return image(content2);
|
|
3218
|
+
case "mdxJsxTextElement":
|
|
3219
|
+
return mdxJsxElement2(content2, field, imageCallback);
|
|
3220
|
+
case "emphasis":
|
|
3221
|
+
return phrashingMark(content2);
|
|
3222
|
+
case "strong":
|
|
3223
|
+
return phrashingMark(content2);
|
|
3224
|
+
case "break":
|
|
3225
|
+
return breakContent();
|
|
3226
|
+
case "inlineCode":
|
|
3227
|
+
return phrashingMark(content2);
|
|
3228
|
+
case "html":
|
|
3229
|
+
return html_inline(content2);
|
|
3230
|
+
case "mdxTextExpression":
|
|
3231
|
+
throw new RichTextParseError(
|
|
3232
|
+
`Unexpected expression ${content2.value}.`,
|
|
3233
|
+
content2.position
|
|
3234
|
+
);
|
|
3235
|
+
default:
|
|
3236
|
+
throw new Error(`PhrasingContent: ${content2.type} is not yet supported`);
|
|
3237
|
+
}
|
|
3238
|
+
};
|
|
3239
|
+
const breakContent = () => {
|
|
3240
|
+
return {
|
|
3241
|
+
type: "break",
|
|
3242
|
+
children: [
|
|
3243
|
+
{
|
|
3244
|
+
type: "text",
|
|
3245
|
+
text: ""
|
|
1976
3246
|
}
|
|
1977
|
-
|
|
1978
|
-
}
|
|
1979
|
-
return nok(code);
|
|
1980
|
-
};
|
|
1981
|
-
const afterOpening = function(code) {
|
|
1982
|
-
return nok(code);
|
|
3247
|
+
]
|
|
1983
3248
|
};
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
3249
|
+
};
|
|
3250
|
+
const phrashingMark = (node, marks = []) => {
|
|
3251
|
+
const accum = [];
|
|
3252
|
+
switch (node.type) {
|
|
3253
|
+
case "emphasis": {
|
|
3254
|
+
const children = flatten(
|
|
3255
|
+
node.children.map(
|
|
3256
|
+
(child) => phrashingMark(child, [...marks, "italic"])
|
|
3257
|
+
)
|
|
3258
|
+
);
|
|
3259
|
+
children.forEach((child) => {
|
|
3260
|
+
accum.push(child);
|
|
3261
|
+
});
|
|
3262
|
+
break;
|
|
1987
3263
|
}
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
3264
|
+
case "inlineCode": {
|
|
3265
|
+
const markProps2 = {};
|
|
3266
|
+
marks.forEach((mark) => markProps2[mark] = true);
|
|
3267
|
+
accum.push({
|
|
3268
|
+
type: "text",
|
|
3269
|
+
text: node.value,
|
|
3270
|
+
code: true,
|
|
3271
|
+
...markProps2
|
|
3272
|
+
});
|
|
3273
|
+
break;
|
|
1994
3274
|
}
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
3275
|
+
case "strong": {
|
|
3276
|
+
const children = flatten(
|
|
3277
|
+
node.children.map((child) => phrashingMark(child, [...marks, "bold"]))
|
|
3278
|
+
);
|
|
3279
|
+
children.forEach((child) => {
|
|
3280
|
+
accum.push(child);
|
|
3281
|
+
});
|
|
3282
|
+
break;
|
|
2000
3283
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
});
|
|
2005
|
-
if (previous)
|
|
2006
|
-
previous.next = token;
|
|
2007
|
-
previous = token;
|
|
2008
|
-
return contentContinue(code);
|
|
2009
|
-
};
|
|
2010
|
-
const contentContinue = function(code) {
|
|
2011
|
-
if (code === codes4.eof) {
|
|
2012
|
-
const t = effects.exit(types3.chunkDocument);
|
|
2013
|
-
self.parser.lazy[t.start.line] = false;
|
|
2014
|
-
return nok(code);
|
|
3284
|
+
case "image": {
|
|
3285
|
+
accum.push(image(node));
|
|
3286
|
+
break;
|
|
2015
3287
|
}
|
|
2016
|
-
|
|
2017
|
-
|
|
3288
|
+
case "link": {
|
|
3289
|
+
const children = flatten(
|
|
3290
|
+
node.children.map((child) => phrashingMark(child, marks))
|
|
3291
|
+
);
|
|
3292
|
+
accum.push({ type: "a", url: node.url, title: node.title, children });
|
|
3293
|
+
break;
|
|
2018
3294
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
};
|
|
2044
|
-
const closingSequence = function(code) {
|
|
2045
|
-
const nextCharacter = pattern.start[closeStartSequenceIndex];
|
|
2046
|
-
if (findCode(nextCharacter) === code) {
|
|
2047
|
-
effects2.consume(code);
|
|
2048
|
-
closeStartSequenceIndex++;
|
|
2049
|
-
return closingSequence;
|
|
2050
|
-
}
|
|
2051
|
-
if (closeStartSequenceIndex < pattern.end.length - 1) {
|
|
2052
|
-
return nok2(code);
|
|
2053
|
-
}
|
|
2054
|
-
effects2.exit("directiveContainerSequence");
|
|
2055
|
-
return factorySpace3(effects2, closingSequenceNameStart, types3.whitespace)(code);
|
|
2056
|
-
};
|
|
2057
|
-
const closingSequenceName = function(code) {
|
|
2058
|
-
const patternName = pattern.name || pattern.templateName;
|
|
2059
|
-
const nextCharacter = patternName[endNameIndex];
|
|
2060
|
-
if (code === codes4.eof) {
|
|
2061
|
-
return nok2;
|
|
2062
|
-
}
|
|
2063
|
-
if (markdownLineEnding3(code)) {
|
|
2064
|
-
return nok2;
|
|
2065
|
-
}
|
|
2066
|
-
if (findCode(nextCharacter) === code) {
|
|
2067
|
-
effects2.consume(code);
|
|
2068
|
-
endNameIndex++;
|
|
2069
|
-
return closingSequenceName;
|
|
2070
|
-
}
|
|
2071
|
-
if (patternName.length === endNameIndex) {
|
|
2072
|
-
return closingSequenceEnd;
|
|
2073
|
-
}
|
|
2074
|
-
return nok2;
|
|
2075
|
-
};
|
|
2076
|
-
const closingSequenceNameStart = function(code) {
|
|
2077
|
-
if (markdownSpace3(code)) {
|
|
2078
|
-
return factorySpace3(effects2, closingSequenceNameStart, types3.whitespace);
|
|
2079
|
-
}
|
|
2080
|
-
if (code === codes4.slash) {
|
|
2081
|
-
effects2.consume(code);
|
|
2082
|
-
return closingSequenceName;
|
|
2083
|
-
}
|
|
2084
|
-
return nok2(code);
|
|
2085
|
-
};
|
|
2086
|
-
const closingSequenceEnd = function(code) {
|
|
2087
|
-
if (markdownSpace3(code)) {
|
|
2088
|
-
return factorySpace3(effects2, closingSequenceEnd, types3.whitespace);
|
|
2089
|
-
}
|
|
2090
|
-
if (code === codes4.eof) {
|
|
2091
|
-
return nok2;
|
|
2092
|
-
}
|
|
2093
|
-
if (pattern.end.length - 1 === closeEndSequenceIndex) {
|
|
2094
|
-
effects2.exit("directiveContainerFence");
|
|
2095
|
-
return ok2(code);
|
|
2096
|
-
}
|
|
2097
|
-
const nextCharacter = pattern.end[closeEndSequenceIndex];
|
|
2098
|
-
if (findCode(nextCharacter) === code) {
|
|
2099
|
-
effects2.consume(code);
|
|
2100
|
-
closeEndSequenceIndex++;
|
|
2101
|
-
return closingSequenceEnd;
|
|
2102
|
-
}
|
|
2103
|
-
return nok2(code);
|
|
2104
|
-
};
|
|
2105
|
-
return factorySpace3(effects2, closingPrefixAfter, types3.linePrefix, constants.tabSize);
|
|
3295
|
+
case "html":
|
|
3296
|
+
case "text":
|
|
3297
|
+
const markProps = {};
|
|
3298
|
+
marks.forEach((mark) => markProps[mark] = true);
|
|
3299
|
+
accum.push({ type: "text", text: node.value, ...markProps });
|
|
3300
|
+
break;
|
|
3301
|
+
case "break":
|
|
3302
|
+
accum.push(breakContent());
|
|
3303
|
+
break;
|
|
3304
|
+
default:
|
|
3305
|
+
throw new RichTextParseError(
|
|
3306
|
+
`Unexpected inline element of type ${node.type}`,
|
|
3307
|
+
node?.position
|
|
3308
|
+
);
|
|
3309
|
+
}
|
|
3310
|
+
return accum;
|
|
3311
|
+
};
|
|
3312
|
+
const image = (content2) => {
|
|
3313
|
+
return {
|
|
3314
|
+
type: "img",
|
|
3315
|
+
url: imageCallback(content2.url),
|
|
3316
|
+
alt: content2.alt || void 0,
|
|
3317
|
+
caption: content2.title,
|
|
3318
|
+
children: [{ type: "text", text: "" }]
|
|
2106
3319
|
};
|
|
2107
|
-
return start;
|
|
2108
3320
|
};
|
|
2109
|
-
const
|
|
2110
|
-
return
|
|
3321
|
+
const text5 = (content2) => {
|
|
3322
|
+
return {
|
|
3323
|
+
type: "text",
|
|
3324
|
+
text: content2.value
|
|
3325
|
+
};
|
|
2111
3326
|
};
|
|
2112
|
-
const
|
|
2113
|
-
const
|
|
2114
|
-
|
|
2115
|
-
|
|
3327
|
+
const blockquote = (content2) => {
|
|
3328
|
+
const children = [];
|
|
3329
|
+
content2.children.map((child) => {
|
|
3330
|
+
const inlineElements = unwrapBlockContent(child);
|
|
3331
|
+
inlineElements.forEach((child2) => {
|
|
3332
|
+
children.push(child2);
|
|
3333
|
+
});
|
|
3334
|
+
});
|
|
3335
|
+
return {
|
|
3336
|
+
type: "blockquote",
|
|
3337
|
+
children
|
|
2116
3338
|
};
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
3339
|
+
};
|
|
3340
|
+
const paragraph = (content2) => {
|
|
3341
|
+
const children = flatten(content2.children.map(phrasingContent));
|
|
3342
|
+
if (children.length === 1) {
|
|
3343
|
+
if (children[0]) {
|
|
3344
|
+
if (children[0].type === "html_inline") {
|
|
3345
|
+
return {
|
|
3346
|
+
...children[0],
|
|
3347
|
+
type: "html"
|
|
3348
|
+
};
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
return {
|
|
3353
|
+
type: "p",
|
|
3354
|
+
children
|
|
2123
3355
|
};
|
|
2124
|
-
return start;
|
|
2125
3356
|
};
|
|
2126
|
-
const attributes2 = { tokenize: tokenizeAttributes, partial: true };
|
|
2127
|
-
const nonLazyLine = { tokenize: tokenizeNonLazyLine, partial: true };
|
|
2128
3357
|
return {
|
|
2129
|
-
|
|
2130
|
-
|
|
3358
|
+
type: "root",
|
|
3359
|
+
children: root.children.map((child) => {
|
|
3360
|
+
return content(child);
|
|
3361
|
+
})
|
|
2131
3362
|
};
|
|
2132
3363
|
};
|
|
3364
|
+
var RichTextParseError = class extends Error {
|
|
3365
|
+
constructor(message, position) {
|
|
3366
|
+
super(message);
|
|
3367
|
+
__publicField(this, "position");
|
|
3368
|
+
if (Error.captureStackTrace) {
|
|
3369
|
+
Error.captureStackTrace(this, RichTextParseError);
|
|
3370
|
+
}
|
|
3371
|
+
this.name = "RichTextParseError";
|
|
3372
|
+
this.position = position;
|
|
3373
|
+
}
|
|
3374
|
+
};
|
|
2133
3375
|
|
|
2134
|
-
// src/
|
|
2135
|
-
var
|
|
2136
|
-
const
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
3376
|
+
// src/next/parse/post-processing.ts
|
|
3377
|
+
var postProcessor = (tree, field, imageCallback) => {
|
|
3378
|
+
const addPropsToMdxFlow = (node) => {
|
|
3379
|
+
const props = {};
|
|
3380
|
+
node.attributes.forEach((attribute) => {
|
|
3381
|
+
if (attribute.type === "mdxJsxAttribute") {
|
|
3382
|
+
props[attribute.name] = attribute.value;
|
|
3383
|
+
} else {
|
|
3384
|
+
throw new Error("HANDLE mdxJsxExpressionAttribute");
|
|
3385
|
+
}
|
|
3386
|
+
});
|
|
3387
|
+
if (node.children.length) {
|
|
3388
|
+
let tree2;
|
|
3389
|
+
if (node.type === "mdxJsxTextElement") {
|
|
3390
|
+
tree2 = postProcessor(
|
|
3391
|
+
{
|
|
3392
|
+
type: "root",
|
|
3393
|
+
children: [{ type: "paragraph", children: node.children }]
|
|
3394
|
+
},
|
|
3395
|
+
field,
|
|
3396
|
+
imageCallback
|
|
3397
|
+
);
|
|
3398
|
+
} else {
|
|
3399
|
+
tree2 = postProcessor(
|
|
3400
|
+
{ type: "root", children: node.children },
|
|
3401
|
+
field,
|
|
3402
|
+
imageCallback
|
|
3403
|
+
);
|
|
2158
3404
|
}
|
|
3405
|
+
props.children = tree2;
|
|
2159
3406
|
}
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
3407
|
+
node.props = props;
|
|
3408
|
+
delete node.attributes;
|
|
3409
|
+
node.children = [{ type: "text", text: "" }];
|
|
2163
3410
|
};
|
|
3411
|
+
visit(tree, "mdxJsxFlowElement", addPropsToMdxFlow);
|
|
3412
|
+
visit(tree, "mdxJsxTextElement", addPropsToMdxFlow);
|
|
3413
|
+
return remarkToSlate(tree, field, imageCallback, "", true);
|
|
3414
|
+
};
|
|
3415
|
+
|
|
3416
|
+
// src/next/parse/index.ts
|
|
3417
|
+
var parseMDX2 = (value, field, imageCallback) => {
|
|
3418
|
+
const backup = (v) => v;
|
|
3419
|
+
const callback = imageCallback || backup;
|
|
3420
|
+
const tree = fromMarkdown(value, field);
|
|
3421
|
+
return postProcess(tree, field, callback);
|
|
3422
|
+
};
|
|
3423
|
+
var postProcess = (tree, field, imageCallback) => {
|
|
3424
|
+
return postProcessor(compact(tree), field, imageCallback);
|
|
2164
3425
|
};
|
|
2165
3426
|
|
|
3427
|
+
// src/parse/index.ts
|
|
3428
|
+
import { fromMarkdown as fromMarkdown2 } from "mdast-util-from-markdown";
|
|
3429
|
+
|
|
3430
|
+
// src/extensions/tina-shortcodes/from-markdown.ts
|
|
3431
|
+
import { parseEntities as parseEntities2 } from "parse-entities";
|
|
3432
|
+
|
|
3433
|
+
// src/extensions/tina-shortcodes/shortcode-leaf.ts
|
|
3434
|
+
import { factorySpace as factorySpace4 } from "micromark-factory-space";
|
|
3435
|
+
import { markdownLineEnding as markdownLineEnding4, markdownSpace as markdownSpace3 } from "micromark-util-character";
|
|
3436
|
+
import { codes as codes6 } from "micromark-util-symbol/codes";
|
|
3437
|
+
import { values as values2 } from "micromark-util-symbol/values";
|
|
3438
|
+
import { types as types4 } from "micromark-util-symbol/types";
|
|
3439
|
+
|
|
3440
|
+
// src/extensions/tina-shortcodes/factory-attributes.ts
|
|
3441
|
+
import { factorySpace as factorySpace3 } from "micromark-factory-space";
|
|
3442
|
+
import { factoryWhitespace } from "micromark-factory-whitespace";
|
|
3443
|
+
import {
|
|
3444
|
+
asciiAlpha,
|
|
3445
|
+
asciiAlphanumeric,
|
|
3446
|
+
markdownLineEnding as markdownLineEnding3,
|
|
3447
|
+
markdownLineEndingOrSpace as markdownLineEndingOrSpace2,
|
|
3448
|
+
markdownSpace as markdownSpace2
|
|
3449
|
+
} from "micromark-util-character";
|
|
3450
|
+
import { codes as codes4 } from "micromark-util-symbol/codes";
|
|
3451
|
+
import { types as types3 } from "micromark-util-symbol/types";
|
|
3452
|
+
|
|
3453
|
+
// src/extensions/tina-shortcodes/factory-name.ts
|
|
3454
|
+
import { asciiAlpha as asciiAlpha2, asciiAlphanumeric as asciiAlphanumeric2 } from "micromark-util-character";
|
|
3455
|
+
import { codes as codes5 } from "micromark-util-symbol/codes";
|
|
3456
|
+
|
|
3457
|
+
// src/extensions/tina-shortcodes/shortcode-container.ts
|
|
3458
|
+
import { ok as assert2 } from "uvu/assert";
|
|
3459
|
+
import { factorySpace as factorySpace5 } from "micromark-factory-space";
|
|
3460
|
+
import { markdownLineEnding as markdownLineEnding5, markdownSpace as markdownSpace4 } from "micromark-util-character";
|
|
3461
|
+
import { codes as codes7 } from "micromark-util-symbol/codes";
|
|
3462
|
+
import { constants as constants2 } from "micromark-util-symbol/constants";
|
|
3463
|
+
import { types as types5 } from "micromark-util-symbol/types";
|
|
3464
|
+
|
|
2166
3465
|
// src/parse/parseShortcode.ts
|
|
2167
3466
|
function parseShortcode(preprocessedString, template) {
|
|
2168
3467
|
const match = template.match;
|
|
@@ -2175,26 +3474,6 @@ function parseShortcode(preprocessedString, template) {
|
|
|
2175
3474
|
}
|
|
2176
3475
|
|
|
2177
3476
|
// src/parse/index.ts
|
|
2178
|
-
var markdownToAst = (value, field) => {
|
|
2179
|
-
const patterns = [];
|
|
2180
|
-
field.templates?.forEach((template) => {
|
|
2181
|
-
if (typeof template === "string") {
|
|
2182
|
-
return;
|
|
2183
|
-
}
|
|
2184
|
-
if (template && template.match) {
|
|
2185
|
-
patterns.push({
|
|
2186
|
-
...template.match,
|
|
2187
|
-
name: template.match?.name || template.name,
|
|
2188
|
-
templateName: template.name,
|
|
2189
|
-
type: template.fields.find((f) => f.name === "children") ? "block" : "leaf"
|
|
2190
|
-
});
|
|
2191
|
-
}
|
|
2192
|
-
});
|
|
2193
|
-
return fromMarkdown(value, {
|
|
2194
|
-
extensions: [tinaDirective(patterns)],
|
|
2195
|
-
mdastExtensions: [directiveFromMarkdown]
|
|
2196
|
-
});
|
|
2197
|
-
};
|
|
2198
3477
|
var mdxToAst = (value) => {
|
|
2199
3478
|
return remark().use(remarkMdx).parse(value);
|
|
2200
3479
|
};
|
|
@@ -2206,22 +3485,23 @@ var parseMDX = (value, field, imageCallback) => {
|
|
|
2206
3485
|
let tree;
|
|
2207
3486
|
try {
|
|
2208
3487
|
if (field.parser?.type === "markdown") {
|
|
2209
|
-
|
|
2210
|
-
}
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
3488
|
+
return parseMDX2(value, field, imageCallback);
|
|
3489
|
+
}
|
|
3490
|
+
let preprocessedString = value;
|
|
3491
|
+
const templatesWithMatchers = field.templates?.filter(
|
|
3492
|
+
(template) => template.match
|
|
3493
|
+
);
|
|
3494
|
+
templatesWithMatchers?.forEach((template) => {
|
|
3495
|
+
if (typeof template === "string") {
|
|
3496
|
+
throw new Error("Global templates are not supported");
|
|
3497
|
+
}
|
|
3498
|
+
if (template.match) {
|
|
3499
|
+
if (preprocessedString) {
|
|
3500
|
+
preprocessedString = parseShortcode(preprocessedString, template);
|
|
2221
3501
|
}
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
|
-
|
|
3502
|
+
}
|
|
3503
|
+
});
|
|
3504
|
+
tree = mdxToAst(preprocessedString);
|
|
2225
3505
|
if (tree) {
|
|
2226
3506
|
return remarkToSlate(tree, field, imageCallback, value);
|
|
2227
3507
|
} else {
|