@portabletext/block-tools 3.4.0 → 3.5.0
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/lib/_chunks-cjs/helpers.cjs +479 -0
- package/lib/_chunks-cjs/helpers.cjs.map +1 -0
- package/lib/_chunks-dts/types.d.cts +85 -0
- package/lib/_chunks-dts/types.d.ts +85 -0
- package/lib/_chunks-es/helpers.js +478 -0
- package/lib/_chunks-es/helpers.js.map +1 -0
- package/lib/index.cjs +84 -534
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1 -83
- package/lib/index.d.ts +1 -83
- package/lib/index.js +3 -453
- package/lib/index.js.map +1 -1
- package/lib/rules/index.cjs +66 -0
- package/lib/rules/index.cjs.map +1 -0
- package/lib/rules/index.d.cts +72 -0
- package/lib/rules/index.d.ts +72 -0
- package/lib/rules/index.js +67 -0
- package/lib/rules/index.js.map +1 -0
- package/package.json +12 -6
- package/src/HtmlDeserializer/flatten-nested-blocks.test.ts +5 -8
- package/src/HtmlDeserializer/flatten-nested-blocks.ts +0 -1
- package/src/HtmlDeserializer/index.ts +1 -1
- package/src/rules/_exports/index.ts +1 -0
- package/src/rules/flatten-tables.test.ts +224 -0
- package/src/rules/flatten-tables.ts +202 -0
- package/src/rules/index.ts +1 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var schema = require("@portabletext/schema"), isEqual = require("lodash/isEqual.js"), uniq = require("lodash/uniq.js");
|
|
3
|
+
function _interopDefaultCompat(e) {
|
|
4
|
+
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
|
+
}
|
|
6
|
+
var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq);
|
|
7
|
+
const objectToString = Object.prototype.toString;
|
|
8
|
+
function resolveJsType(val) {
|
|
9
|
+
switch (objectToString.call(val)) {
|
|
10
|
+
case "[object Function]":
|
|
11
|
+
return "function";
|
|
12
|
+
case "[object Date]":
|
|
13
|
+
return "date";
|
|
14
|
+
case "[object RegExp]":
|
|
15
|
+
return "regexp";
|
|
16
|
+
case "[object Arguments]":
|
|
17
|
+
return "arguments";
|
|
18
|
+
case "[object Array]":
|
|
19
|
+
return "array";
|
|
20
|
+
case "[object String]":
|
|
21
|
+
return "string";
|
|
22
|
+
}
|
|
23
|
+
return val === null ? "null" : val === void 0 ? "undefined" : val && typeof val == "object" && "nodeType" in val && val.nodeType === 1 ? "element" : val === Object(val) ? "object" : typeof val;
|
|
24
|
+
}
|
|
25
|
+
function isArbitraryTypedObject(object) {
|
|
26
|
+
return isRecord(object) && typeof object._type == "string";
|
|
27
|
+
}
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return !!value && (typeof value == "object" || typeof value == "function");
|
|
30
|
+
}
|
|
31
|
+
function flattenNestedBlocks(context, blocks) {
|
|
32
|
+
return blocks.flatMap((block) => {
|
|
33
|
+
if (isBlockContainer(block))
|
|
34
|
+
return flattenNestedBlocks(context, [block.block]);
|
|
35
|
+
if (schema.isTextBlock(context, block)) {
|
|
36
|
+
const hasBlockObjects = block.children.some((child) => context.schema.blockObjects.some(
|
|
37
|
+
(blockObject) => blockObject.name === child._type
|
|
38
|
+
)), hasBlocks = block.children.some(
|
|
39
|
+
(child) => child._type === "__block" || child._type === "block"
|
|
40
|
+
);
|
|
41
|
+
if (hasBlockObjects || hasBlocks) {
|
|
42
|
+
const splitChildren = getSplitChildren(context, block);
|
|
43
|
+
return splitChildren.length === 1 && splitChildren[0].type === "children" && isEqual__default.default(splitChildren[0].children, block.children) ? [block] : splitChildren.flatMap((slice) => slice.type === "block object" ? [slice.block] : slice.type === "block" ? flattenNestedBlocks(context, [
|
|
44
|
+
slice.block
|
|
45
|
+
]) : slice.children.length > 0 ? slice.children.every(
|
|
46
|
+
(child) => schema.isSpan(context, child) && child.text.trim() === ""
|
|
47
|
+
) ? [] : flattenNestedBlocks(context, [
|
|
48
|
+
{
|
|
49
|
+
...block,
|
|
50
|
+
children: slice.children
|
|
51
|
+
}
|
|
52
|
+
]) : []);
|
|
53
|
+
}
|
|
54
|
+
return [block];
|
|
55
|
+
}
|
|
56
|
+
return [block];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function isBlockContainer(block) {
|
|
60
|
+
return block._type === "__block" && isArbitraryTypedObject(block.block);
|
|
61
|
+
}
|
|
62
|
+
function getSplitChildren(context, block) {
|
|
63
|
+
return block.children.reduce(
|
|
64
|
+
(slices, child) => {
|
|
65
|
+
const knownInlineObject = context.schema.inlineObjects.some(
|
|
66
|
+
(inlineObject) => inlineObject.name === child._type
|
|
67
|
+
), knownBlockObject = context.schema.blockObjects.some(
|
|
68
|
+
(blockObject) => blockObject.name === child._type
|
|
69
|
+
), lastSlice = slices.pop();
|
|
70
|
+
return !schema.isSpan(context, child) && !knownInlineObject && knownBlockObject ? [
|
|
71
|
+
...slices,
|
|
72
|
+
...lastSlice ? [lastSlice] : [],
|
|
73
|
+
{ type: "block object", block: child }
|
|
74
|
+
] : child._type === "__block" ? [
|
|
75
|
+
...slices,
|
|
76
|
+
...lastSlice ? [lastSlice] : [],
|
|
77
|
+
{
|
|
78
|
+
type: "block object",
|
|
79
|
+
block: child.block
|
|
80
|
+
}
|
|
81
|
+
] : child._type === "block" ? [
|
|
82
|
+
...slices,
|
|
83
|
+
...lastSlice ? [lastSlice] : [],
|
|
84
|
+
{ type: "block", block: child }
|
|
85
|
+
] : lastSlice && lastSlice.type === "children" ? [
|
|
86
|
+
...slices,
|
|
87
|
+
{
|
|
88
|
+
type: "children",
|
|
89
|
+
children: [...lastSlice.children, child]
|
|
90
|
+
}
|
|
91
|
+
] : [
|
|
92
|
+
...slices,
|
|
93
|
+
...lastSlice ? [lastSlice] : [],
|
|
94
|
+
{ type: "children", children: [child] }
|
|
95
|
+
];
|
|
96
|
+
},
|
|
97
|
+
[]
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
var s = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, c = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 };
|
|
101
|
+
new Array(4).fill(String.fromCodePoint(c[0])).join("");
|
|
102
|
+
Object.fromEntries(Object.entries(c).map((t) => t.reverse()));
|
|
103
|
+
Object.fromEntries(Object.entries(s).map((t) => t.reverse()));
|
|
104
|
+
var S = `${Object.values(s).map((t) => `\\u{${t.toString(16)}}`).join("")}`, f = new RegExp(`[${S}]{4,}`, "gu");
|
|
105
|
+
function _(t) {
|
|
106
|
+
var e;
|
|
107
|
+
return { cleaned: t.replace(f, ""), encoded: ((e = t.match(f)) == null ? void 0 : e[0]) || "" };
|
|
108
|
+
}
|
|
109
|
+
function O(t) {
|
|
110
|
+
return t && JSON.parse(_(JSON.stringify(t)).cleaned);
|
|
111
|
+
}
|
|
112
|
+
const PRESERVE_WHITESPACE_TAGS = ["pre", "textarea", "code"], BLOCK_DEFAULT_STYLE = "normal", DEFAULT_BLOCK = Object.freeze({
|
|
113
|
+
_type: "block",
|
|
114
|
+
markDefs: [],
|
|
115
|
+
style: BLOCK_DEFAULT_STYLE
|
|
116
|
+
}), DEFAULT_SPAN = Object.freeze({
|
|
117
|
+
_type: "span",
|
|
118
|
+
marks: []
|
|
119
|
+
}), HTML_BLOCK_TAGS = {
|
|
120
|
+
p: DEFAULT_BLOCK,
|
|
121
|
+
blockquote: { ...DEFAULT_BLOCK, style: "blockquote" }
|
|
122
|
+
}, HTML_SPAN_TAGS = {
|
|
123
|
+
span: { object: "text" }
|
|
124
|
+
}, HTML_LIST_CONTAINER_TAGS = {
|
|
125
|
+
ol: { object: null },
|
|
126
|
+
ul: { object: null }
|
|
127
|
+
}, HTML_HEADER_TAGS = {
|
|
128
|
+
h1: { ...DEFAULT_BLOCK, style: "h1" },
|
|
129
|
+
h2: { ...DEFAULT_BLOCK, style: "h2" },
|
|
130
|
+
h3: { ...DEFAULT_BLOCK, style: "h3" },
|
|
131
|
+
h4: { ...DEFAULT_BLOCK, style: "h4" },
|
|
132
|
+
h5: { ...DEFAULT_BLOCK, style: "h5" },
|
|
133
|
+
h6: { ...DEFAULT_BLOCK, style: "h6" }
|
|
134
|
+
}, HTML_MISC_TAGS = {
|
|
135
|
+
br: { ...DEFAULT_BLOCK, style: BLOCK_DEFAULT_STYLE }
|
|
136
|
+
}, HTML_DECORATOR_TAGS = {
|
|
137
|
+
b: "strong",
|
|
138
|
+
strong: "strong",
|
|
139
|
+
i: "em",
|
|
140
|
+
em: "em",
|
|
141
|
+
u: "underline",
|
|
142
|
+
s: "strike-through",
|
|
143
|
+
strike: "strike-through",
|
|
144
|
+
del: "strike-through",
|
|
145
|
+
code: "code",
|
|
146
|
+
sup: "sup",
|
|
147
|
+
sub: "sub",
|
|
148
|
+
ins: "ins",
|
|
149
|
+
mark: "mark",
|
|
150
|
+
small: "small"
|
|
151
|
+
}, HTML_LIST_ITEM_TAGS = {
|
|
152
|
+
li: {
|
|
153
|
+
...DEFAULT_BLOCK,
|
|
154
|
+
style: BLOCK_DEFAULT_STYLE,
|
|
155
|
+
level: 1,
|
|
156
|
+
listItem: "bullet"
|
|
157
|
+
}
|
|
158
|
+
}, ELEMENT_MAP = {
|
|
159
|
+
...HTML_BLOCK_TAGS,
|
|
160
|
+
...HTML_SPAN_TAGS,
|
|
161
|
+
...HTML_LIST_CONTAINER_TAGS,
|
|
162
|
+
...HTML_LIST_ITEM_TAGS,
|
|
163
|
+
...HTML_HEADER_TAGS,
|
|
164
|
+
...HTML_MISC_TAGS
|
|
165
|
+
};
|
|
166
|
+
uniq__default.default(
|
|
167
|
+
Object.values(ELEMENT_MAP).filter((tag) => "style" in tag).map((tag) => tag.style)
|
|
168
|
+
);
|
|
169
|
+
uniq__default.default(
|
|
170
|
+
Object.values(HTML_DECORATOR_TAGS)
|
|
171
|
+
);
|
|
172
|
+
const _XPathResult = {
|
|
173
|
+
BOOLEAN_TYPE: 3,
|
|
174
|
+
ORDERED_NODE_ITERATOR_TYPE: 5,
|
|
175
|
+
UNORDERED_NODE_SNAPSHOT_TYPE: 6
|
|
176
|
+
};
|
|
177
|
+
var preprocessGDocs = (_html, doc, options) => {
|
|
178
|
+
const whitespaceOnPasteMode = options?.unstable_whitespaceOnPasteMode || "preserve";
|
|
179
|
+
let gDocsRootOrSiblingNode = doc.evaluate(
|
|
180
|
+
'//*[@id and contains(@id, "docs-internal-guid")]',
|
|
181
|
+
doc,
|
|
182
|
+
null,
|
|
183
|
+
_XPathResult.ORDERED_NODE_ITERATOR_TYPE,
|
|
184
|
+
null
|
|
185
|
+
).iterateNext();
|
|
186
|
+
if (gDocsRootOrSiblingNode) {
|
|
187
|
+
const isWrappedRootTag = tagName(gDocsRootOrSiblingNode) === "b";
|
|
188
|
+
switch (isWrappedRootTag || (gDocsRootOrSiblingNode = doc.body), whitespaceOnPasteMode) {
|
|
189
|
+
case "normalize":
|
|
190
|
+
normalizeWhitespace(gDocsRootOrSiblingNode);
|
|
191
|
+
break;
|
|
192
|
+
case "remove":
|
|
193
|
+
removeAllWhitespace(gDocsRootOrSiblingNode);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
const childNodes = doc.evaluate(
|
|
197
|
+
"//*",
|
|
198
|
+
doc,
|
|
199
|
+
null,
|
|
200
|
+
_XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
|
201
|
+
null
|
|
202
|
+
);
|
|
203
|
+
for (let i = childNodes.snapshotLength - 1; i >= 0; i--) {
|
|
204
|
+
const elm = childNodes.snapshotItem(i);
|
|
205
|
+
elm?.setAttribute("data-is-google-docs", "true"), (elm?.parentElement === gDocsRootOrSiblingNode || !isWrappedRootTag && elm.parentElement === doc.body) && (elm?.setAttribute("data-is-root-node", "true"), tagName(elm)), tagName(elm) === "li" && elm.firstChild && tagName(elm?.firstChild) === "img" && elm.removeChild(elm.firstChild);
|
|
206
|
+
}
|
|
207
|
+
return isWrappedRootTag && doc.body.firstElementChild?.replaceWith(
|
|
208
|
+
...Array.from(gDocsRootOrSiblingNode.childNodes)
|
|
209
|
+
), doc;
|
|
210
|
+
}
|
|
211
|
+
return doc;
|
|
212
|
+
};
|
|
213
|
+
const unwantedWordDocumentPaths = [
|
|
214
|
+
"/html/text()",
|
|
215
|
+
"/html/head/text()",
|
|
216
|
+
"/html/body/text()",
|
|
217
|
+
"/html/body/ul/text()",
|
|
218
|
+
"/html/body/ol/text()",
|
|
219
|
+
"//comment()",
|
|
220
|
+
"//style",
|
|
221
|
+
"//xml",
|
|
222
|
+
"//script",
|
|
223
|
+
"//meta",
|
|
224
|
+
"//link"
|
|
225
|
+
];
|
|
226
|
+
var preprocessHTML = (_html, doc) => {
|
|
227
|
+
const bodyTextNodes = doc.evaluate(
|
|
228
|
+
"/html/body/text()",
|
|
229
|
+
doc,
|
|
230
|
+
null,
|
|
231
|
+
_XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
|
232
|
+
null
|
|
233
|
+
);
|
|
234
|
+
for (let i = bodyTextNodes.snapshotLength - 1; i >= 0; i--) {
|
|
235
|
+
const node = bodyTextNodes.snapshotItem(i), text = node.textContent || "";
|
|
236
|
+
if (text.replace(/[^\S\n]+$/g, "")) {
|
|
237
|
+
const newNode = doc.createElement("span");
|
|
238
|
+
newNode.appendChild(doc.createTextNode(text)), node.parentNode?.replaceChild(newNode, node);
|
|
239
|
+
} else
|
|
240
|
+
node.parentNode?.removeChild(node);
|
|
241
|
+
}
|
|
242
|
+
const unwantedNodes = doc.evaluate(
|
|
243
|
+
unwantedWordDocumentPaths.join("|"),
|
|
244
|
+
doc,
|
|
245
|
+
null,
|
|
246
|
+
_XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
|
247
|
+
null
|
|
248
|
+
);
|
|
249
|
+
for (let i = unwantedNodes.snapshotLength - 1; i >= 0; i--) {
|
|
250
|
+
const unwanted = unwantedNodes.snapshotItem(i);
|
|
251
|
+
unwanted && unwanted.parentNode?.removeChild(unwanted);
|
|
252
|
+
}
|
|
253
|
+
return doc;
|
|
254
|
+
}, preprocessNotion = (html, doc) => {
|
|
255
|
+
const NOTION_REGEX = /<!-- notionvc:.*?-->/g;
|
|
256
|
+
if (html.match(NOTION_REGEX)) {
|
|
257
|
+
const childNodes = doc.evaluate(
|
|
258
|
+
"//*",
|
|
259
|
+
doc,
|
|
260
|
+
null,
|
|
261
|
+
_XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
|
262
|
+
null
|
|
263
|
+
);
|
|
264
|
+
for (let i = childNodes.snapshotLength - 1; i >= 0; i--)
|
|
265
|
+
childNodes.snapshotItem(i)?.setAttribute("data-is-notion", "true");
|
|
266
|
+
return doc;
|
|
267
|
+
}
|
|
268
|
+
return doc;
|
|
269
|
+
}, preprocessWhitespace = (_2, doc) => {
|
|
270
|
+
function processNode(node) {
|
|
271
|
+
if (node.nodeType === _XPathResult.BOOLEAN_TYPE && !PRESERVE_WHITESPACE_TAGS.includes(
|
|
272
|
+
node.parentElement?.tagName.toLowerCase() || ""
|
|
273
|
+
))
|
|
274
|
+
node.textContent = node.textContent?.replace(/\s\s+/g, " ").replace(/[\r\n]+/g, " ") || "";
|
|
275
|
+
else
|
|
276
|
+
for (let i = 0; i < node.childNodes.length; i++)
|
|
277
|
+
processNode(node.childNodes[i]);
|
|
278
|
+
}
|
|
279
|
+
return processNode(doc.body), doc;
|
|
280
|
+
};
|
|
281
|
+
const WORD_HTML_REGEX = /(class="?Mso|style=(?:"|')[^"]*?\bmso-|w:WordDocument|<o:\w+>|<\/font>)/, unwantedPaths = [
|
|
282
|
+
"//o:p",
|
|
283
|
+
"//span[@style='mso-list:Ignore']",
|
|
284
|
+
"//span[@style='mso-list: Ignore']"
|
|
285
|
+
], mappedPaths = [
|
|
286
|
+
"//p[@class='MsoTocHeading']",
|
|
287
|
+
"//p[@class='MsoTitle']",
|
|
288
|
+
"//p[@class='MsoToaHeading']",
|
|
289
|
+
"//p[@class='MsoSubtitle']",
|
|
290
|
+
"//span[@class='MsoSubtleEmphasis']",
|
|
291
|
+
"//span[@class='MsoIntenseEmphasis']"
|
|
292
|
+
], elementMap = {
|
|
293
|
+
MsoTocHeading: ["h3"],
|
|
294
|
+
MsoTitle: ["h1"],
|
|
295
|
+
MsoToaHeading: ["h2"],
|
|
296
|
+
MsoSubtitle: ["h5"],
|
|
297
|
+
MsoSubtleEmphasis: ["span", "em"],
|
|
298
|
+
MsoIntenseEmphasis: ["span", "em", "strong"]
|
|
299
|
+
// Remove cruft
|
|
300
|
+
};
|
|
301
|
+
function isWordHtml(html) {
|
|
302
|
+
return WORD_HTML_REGEX.test(html);
|
|
303
|
+
}
|
|
304
|
+
var preprocessWord = (html, doc) => {
|
|
305
|
+
if (!isWordHtml(html))
|
|
306
|
+
return doc;
|
|
307
|
+
const unwantedNodes = doc.evaluate(
|
|
308
|
+
unwantedPaths.join("|"),
|
|
309
|
+
doc,
|
|
310
|
+
(prefix) => prefix === "o" ? "urn:schemas-microsoft-com:office:office" : null,
|
|
311
|
+
_XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
|
312
|
+
null
|
|
313
|
+
);
|
|
314
|
+
for (let i = unwantedNodes.snapshotLength - 1; i >= 0; i--) {
|
|
315
|
+
const unwanted = unwantedNodes.snapshotItem(i);
|
|
316
|
+
unwanted?.parentNode && unwanted.parentNode.removeChild(unwanted);
|
|
317
|
+
}
|
|
318
|
+
const mappedElements = doc.evaluate(
|
|
319
|
+
mappedPaths.join("|"),
|
|
320
|
+
doc,
|
|
321
|
+
null,
|
|
322
|
+
_XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
|
323
|
+
null
|
|
324
|
+
);
|
|
325
|
+
for (let i = mappedElements.snapshotLength - 1; i >= 0; i--) {
|
|
326
|
+
const mappedElm = mappedElements.snapshotItem(i), tags = elementMap[mappedElm.className], text = doc.createTextNode(mappedElm.textContent || "");
|
|
327
|
+
if (!tags)
|
|
328
|
+
continue;
|
|
329
|
+
const parentElement = doc.createElement(tags[0]);
|
|
330
|
+
let parent = parentElement, child = parentElement;
|
|
331
|
+
tags.slice(1).forEach((tag) => {
|
|
332
|
+
child = doc.createElement(tag), parent.appendChild(child), parent = child;
|
|
333
|
+
}), child.appendChild(text), mappedElm?.parentNode?.replaceChild(parentElement, mappedElm);
|
|
334
|
+
}
|
|
335
|
+
return doc;
|
|
336
|
+
}, preprocessors = [
|
|
337
|
+
preprocessWhitespace,
|
|
338
|
+
preprocessNotion,
|
|
339
|
+
preprocessWord,
|
|
340
|
+
preprocessGDocs,
|
|
341
|
+
preprocessHTML
|
|
342
|
+
];
|
|
343
|
+
function tagName(el) {
|
|
344
|
+
if (el && "tagName" in el)
|
|
345
|
+
return el.tagName.toLowerCase();
|
|
346
|
+
}
|
|
347
|
+
function preprocess(html, parseHtml, options) {
|
|
348
|
+
const cleanHTML = O(html), doc = parseHtml(normalizeHtmlBeforePreprocess(cleanHTML));
|
|
349
|
+
return preprocessors.forEach((processor) => {
|
|
350
|
+
processor(cleanHTML, doc, options);
|
|
351
|
+
}), doc;
|
|
352
|
+
}
|
|
353
|
+
function normalizeHtmlBeforePreprocess(html) {
|
|
354
|
+
return html.trim();
|
|
355
|
+
}
|
|
356
|
+
function defaultParseHtml() {
|
|
357
|
+
if (resolveJsType(DOMParser) === "undefined")
|
|
358
|
+
throw new Error(
|
|
359
|
+
"The native `DOMParser` global which the `Html` deserializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead."
|
|
360
|
+
);
|
|
361
|
+
return (html) => new DOMParser().parseFromString(html, "text/html");
|
|
362
|
+
}
|
|
363
|
+
function nextSpan(block, index) {
|
|
364
|
+
const next = block.children[index + 1];
|
|
365
|
+
return next && next._type === "span" ? next : null;
|
|
366
|
+
}
|
|
367
|
+
function prevSpan(block, index) {
|
|
368
|
+
const prev = block.children[index - 1];
|
|
369
|
+
return prev && prev._type === "span" ? prev : null;
|
|
370
|
+
}
|
|
371
|
+
function isWhiteSpaceChar(text) {
|
|
372
|
+
return ["\xA0", " "].includes(text);
|
|
373
|
+
}
|
|
374
|
+
function trimWhitespace(schema$1, blocks) {
|
|
375
|
+
return blocks.forEach((block) => {
|
|
376
|
+
schema.isTextBlock({ schema: schema$1 }, block) && block.children.forEach((child, index) => {
|
|
377
|
+
if (!isMinimalSpan(child))
|
|
378
|
+
return;
|
|
379
|
+
const nextChild = nextSpan(block, index), prevChild = prevSpan(block, index);
|
|
380
|
+
index === 0 && (child.text = child.text.replace(/^[^\S\n]+/g, "")), index === block.children.length - 1 && (child.text = child.text.replace(/[^\S\n]+$/g, "")), /\s/.test(child.text.slice(Math.max(0, child.text.length - 1))) && nextChild && isMinimalSpan(nextChild) && /\s/.test(nextChild.text.slice(0, 1)) && (child.text = child.text.replace(/[^\S\n]+$/g, "")), /\s/.test(child.text.slice(0, 1)) && prevChild && isMinimalSpan(prevChild) && /\s/.test(prevChild.text.slice(Math.max(0, prevChild.text.length - 1))) && (child.text = child.text.replace(/^[^\S\n]+/g, "")), child.text || block.children.splice(index, 1), prevChild && isEqual__default.default(prevChild.marks, child.marks) && isWhiteSpaceChar(child.text) ? (prevChild.text += " ", block.children.splice(index, 1)) : nextChild && isEqual__default.default(nextChild.marks, child.marks) && isWhiteSpaceChar(child.text) && (nextChild.text = ` ${nextChild.text}`, block.children.splice(index, 1));
|
|
381
|
+
});
|
|
382
|
+
}), blocks;
|
|
383
|
+
}
|
|
384
|
+
function ensureRootIsBlocks(schema$1, objects) {
|
|
385
|
+
return objects.reduce((blocks, node, i, original) => {
|
|
386
|
+
if (node._type === "block")
|
|
387
|
+
return blocks.push(node), blocks;
|
|
388
|
+
if (node._type === "__block")
|
|
389
|
+
return blocks.push(node.block), blocks;
|
|
390
|
+
const lastBlock = blocks[blocks.length - 1];
|
|
391
|
+
if (i > 0 && !schema.isTextBlock({ schema: schema$1 }, original[i - 1]) && schema.isTextBlock({ schema: schema$1 }, lastBlock))
|
|
392
|
+
return lastBlock.children.push(node), blocks;
|
|
393
|
+
const block = {
|
|
394
|
+
...DEFAULT_BLOCK,
|
|
395
|
+
children: [node]
|
|
396
|
+
};
|
|
397
|
+
return blocks.push(block), blocks;
|
|
398
|
+
}, []);
|
|
399
|
+
}
|
|
400
|
+
function isNodeList(node) {
|
|
401
|
+
return Object.prototype.toString.call(node) === "[object NodeList]";
|
|
402
|
+
}
|
|
403
|
+
function isMinimalSpan(node) {
|
|
404
|
+
return node._type === "span";
|
|
405
|
+
}
|
|
406
|
+
function isMinimalBlock(node) {
|
|
407
|
+
return node._type === "block";
|
|
408
|
+
}
|
|
409
|
+
function isPlaceholderDecorator(node) {
|
|
410
|
+
return node._type === "__decorator";
|
|
411
|
+
}
|
|
412
|
+
function isPlaceholderAnnotation(node) {
|
|
413
|
+
return node._type === "__annotation";
|
|
414
|
+
}
|
|
415
|
+
function isElement(node) {
|
|
416
|
+
return node.nodeType === 1;
|
|
417
|
+
}
|
|
418
|
+
function normalizeWhitespace(rootNode) {
|
|
419
|
+
let emptyBlockCount = 0, lastParent = null;
|
|
420
|
+
const nodesToRemove = [];
|
|
421
|
+
for (let child = rootNode.firstChild; child; child = child.nextSibling) {
|
|
422
|
+
if (!isElement(child)) {
|
|
423
|
+
normalizeWhitespace(child), emptyBlockCount = 0;
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
const elm = child;
|
|
427
|
+
isWhitespaceBlock(elm) ? (lastParent && elm.parentElement === lastParent ? (emptyBlockCount++, emptyBlockCount > 1 && nodesToRemove.push(elm)) : emptyBlockCount = 1, lastParent = elm.parentElement) : (normalizeWhitespace(child), emptyBlockCount = 0);
|
|
428
|
+
}
|
|
429
|
+
nodesToRemove.forEach((node) => {
|
|
430
|
+
node.parentElement?.removeChild(node);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
function removeAllWhitespace(rootNode) {
|
|
434
|
+
const nodesToRemove = [];
|
|
435
|
+
function collectNodesToRemove(currentNode) {
|
|
436
|
+
if (isElement(currentNode)) {
|
|
437
|
+
const elm = currentNode;
|
|
438
|
+
if (tagName(elm) === "br" && (tagName(elm.nextElementSibling) === "p" || tagName(elm.previousElementSibling) === "p")) {
|
|
439
|
+
nodesToRemove.push(elm);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if ((tagName(elm) === "p" || tagName(elm) === "br") && elm?.firstChild?.textContent?.trim() === "") {
|
|
443
|
+
nodesToRemove.push(elm);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
for (let child = elm.firstChild; child; child = child.nextSibling)
|
|
447
|
+
collectNodesToRemove(child);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
collectNodesToRemove(rootNode), nodesToRemove.forEach((node) => {
|
|
451
|
+
node.parentElement?.removeChild(node);
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
function isWhitespaceBlock(elm) {
|
|
455
|
+
return ["p", "br"].includes(tagName(elm) || "") && !elm.textContent?.trim();
|
|
456
|
+
}
|
|
457
|
+
exports.BLOCK_DEFAULT_STYLE = BLOCK_DEFAULT_STYLE;
|
|
458
|
+
exports.DEFAULT_BLOCK = DEFAULT_BLOCK;
|
|
459
|
+
exports.DEFAULT_SPAN = DEFAULT_SPAN;
|
|
460
|
+
exports.HTML_BLOCK_TAGS = HTML_BLOCK_TAGS;
|
|
461
|
+
exports.HTML_DECORATOR_TAGS = HTML_DECORATOR_TAGS;
|
|
462
|
+
exports.HTML_HEADER_TAGS = HTML_HEADER_TAGS;
|
|
463
|
+
exports.HTML_LIST_CONTAINER_TAGS = HTML_LIST_CONTAINER_TAGS;
|
|
464
|
+
exports.HTML_LIST_ITEM_TAGS = HTML_LIST_ITEM_TAGS;
|
|
465
|
+
exports.HTML_SPAN_TAGS = HTML_SPAN_TAGS;
|
|
466
|
+
exports.defaultParseHtml = defaultParseHtml;
|
|
467
|
+
exports.ensureRootIsBlocks = ensureRootIsBlocks;
|
|
468
|
+
exports.flattenNestedBlocks = flattenNestedBlocks;
|
|
469
|
+
exports.isElement = isElement;
|
|
470
|
+
exports.isMinimalBlock = isMinimalBlock;
|
|
471
|
+
exports.isMinimalSpan = isMinimalSpan;
|
|
472
|
+
exports.isNodeList = isNodeList;
|
|
473
|
+
exports.isPlaceholderAnnotation = isPlaceholderAnnotation;
|
|
474
|
+
exports.isPlaceholderDecorator = isPlaceholderDecorator;
|
|
475
|
+
exports.preprocess = preprocess;
|
|
476
|
+
exports.resolveJsType = resolveJsType;
|
|
477
|
+
exports.tagName = tagName;
|
|
478
|
+
exports.trimWhitespace = trimWhitespace;
|
|
479
|
+
//# sourceMappingURL=helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.cjs","sources":["../../src/util/resolveJsType.ts","../../src/types.ts","../../src/HtmlDeserializer/flatten-nested-blocks.ts","../../../../node_modules/.pnpm/@vercel+stega@0.1.2/node_modules/@vercel/stega/dist/index.mjs","../../src/constants.ts","../../src/HtmlDeserializer/preprocessors/xpathResult.ts","../../src/HtmlDeserializer/preprocessors/gdocs.ts","../../src/HtmlDeserializer/preprocessors/html.ts","../../src/HtmlDeserializer/preprocessors/notion.ts","../../src/HtmlDeserializer/preprocessors/whitespace.ts","../../src/HtmlDeserializer/preprocessors/word.ts","../../src/HtmlDeserializer/preprocessors/index.ts","../../src/HtmlDeserializer/helpers.ts"],"sourcesContent":["const objectToString = Object.prototype.toString\n\n// Copied from https://github.com/ForbesLindesay/type-of\n// but inlined to have fine grained control\nexport function resolveJsType(val: unknown) {\n switch (objectToString.call(val)) {\n case '[object Function]':\n return 'function'\n case '[object Date]':\n return 'date'\n case '[object RegExp]':\n return 'regexp'\n case '[object Arguments]':\n return 'arguments'\n case '[object Array]':\n return 'array'\n case '[object String]':\n return 'string'\n default:\n }\n\n if (val === null) {\n return 'null'\n }\n\n if (val === undefined) {\n return 'undefined'\n }\n\n if (\n val &&\n typeof val === 'object' &&\n 'nodeType' in val &&\n (val as {nodeType: unknown}).nodeType === 1\n ) {\n return 'element'\n }\n\n if (val === Object(val)) {\n return 'object'\n }\n\n return typeof val\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {SchemaMatchers} from './schema-matchers'\n\n/**\n * @public\n */\nexport interface TypedObject {\n _type: string\n _key?: string\n}\n\n/**\n * @public\n */\nexport interface ArbitraryTypedObject extends TypedObject {\n [key: string]: unknown\n}\n\nexport function isArbitraryTypedObject(\n object: unknown,\n): object is ArbitraryTypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n\nexport interface MinimalSpan {\n _type: 'span'\n _key?: string\n text: string\n marks?: string[]\n}\n\nexport interface MinimalBlock extends TypedObject {\n _type: 'block'\n children: TypedObject[]\n markDefs?: TypedObject[]\n style?: string\n level?: number\n listItem?: string\n}\n\nexport interface PlaceholderDecorator {\n _type: '__decorator'\n name: string\n children: TypedObject[]\n}\n\nexport interface PlaceholderAnnotation {\n _type: '__annotation'\n markDef: PortableTextObject\n children: TypedObject[]\n}\n\n/**\n * @public\n */\nexport type HtmlParser = (html: string) => Document\n\n/**\n * @public\n */\nexport type WhiteSpacePasteMode = 'preserve' | 'remove' | 'normalize'\n\n/**\n * @public\n */\nexport interface HtmlDeserializerOptions {\n keyGenerator?: () => string\n rules?: DeserializerRule[]\n parseHtml?: HtmlParser\n unstable_whitespaceOnPasteMode?: WhiteSpacePasteMode\n /**\n * Custom schema matchers to use when deserializing HTML to Portable Text.\n * @beta\n */\n matchers?: SchemaMatchers\n}\n\nexport interface HtmlPreprocessorOptions {\n unstable_whitespaceOnPasteMode?: WhiteSpacePasteMode\n}\n\n/**\n * @public\n */\nexport interface DeserializerRule {\n deserialize: (\n el: Node,\n next: (\n elements: Node | Node[] | NodeList,\n ) => TypedObject | TypedObject[] | undefined,\n createBlock: (props: ArbitraryTypedObject) => {\n _type: string\n block: ArbitraryTypedObject\n },\n ) => TypedObject | TypedObject[] | undefined\n}\n","import type {Schema} from '@portabletext/schema'\nimport {\n isSpan,\n isTextBlock,\n type PortableTextBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@portabletext/schema'\nimport {isEqual} from 'lodash'\nimport {\n isArbitraryTypedObject,\n type ArbitraryTypedObject,\n type TypedObject,\n} from '../types'\n\nexport function flattenNestedBlocks(\n context: {\n schema: Schema\n },\n blocks: Array<ArbitraryTypedObject>,\n): TypedObject[] {\n const flattened = blocks.flatMap((block) => {\n if (isBlockContainer(block)) {\n return flattenNestedBlocks(context, [block.block])\n }\n\n if (isTextBlock(context, block)) {\n const hasBlockObjects = block.children.some((child) => {\n const knownBlockObject = context.schema.blockObjects.some(\n (blockObject) => blockObject.name === child._type,\n )\n return knownBlockObject\n })\n const hasBlocks = block.children.some(\n (child) => child._type === '__block' || child._type === 'block',\n )\n\n if (hasBlockObjects || hasBlocks) {\n const splitChildren = getSplitChildren(context, block)\n\n if (\n splitChildren.length === 1 &&\n splitChildren[0].type === 'children' &&\n isEqual(splitChildren[0].children, block.children)\n ) {\n return [block]\n }\n\n return splitChildren.flatMap((slice) => {\n if (slice.type === 'block object') {\n return [slice.block]\n }\n\n if (slice.type === 'block') {\n return flattenNestedBlocks(context, [\n slice.block as ArbitraryTypedObject,\n ])\n }\n\n if (slice.children.length > 0) {\n if (\n slice.children.every(\n (child) => isSpan(context, child) && child.text.trim() === '',\n )\n ) {\n return []\n }\n\n return flattenNestedBlocks(context, [\n {\n ...block,\n children: slice.children,\n },\n ])\n }\n\n return []\n })\n }\n\n return [block]\n }\n\n return [block]\n })\n\n return flattened\n}\n\nfunction isBlockContainer(\n block: ArbitraryTypedObject,\n): block is BlockContainer {\n return block._type === '__block' && isArbitraryTypedObject(block.block)\n}\n\ntype BlockContainer = {\n _type: '__block'\n block: ArbitraryTypedObject\n}\n\nfunction getSplitChildren(\n context: {schema: Schema},\n block: PortableTextTextBlock,\n) {\n return block.children.reduce(\n (slices, child) => {\n const knownInlineObject = context.schema.inlineObjects.some(\n (inlineObject) => inlineObject.name === child._type,\n )\n const knownBlockObject = context.schema.blockObjects.some(\n (blockObject) => blockObject.name === child._type,\n )\n\n const lastSlice = slices.pop()\n\n if (!isSpan(context, child) && !knownInlineObject) {\n if (knownBlockObject) {\n return [\n ...slices,\n ...(lastSlice ? [lastSlice] : []),\n {type: 'block object' as const, block: child},\n ]\n }\n }\n\n if (child._type === '__block') {\n return [\n ...slices,\n ...(lastSlice ? [lastSlice] : []),\n {\n type: 'block object' as const,\n block: (child as any).block,\n },\n ]\n }\n\n if (child._type === 'block') {\n return [\n ...slices,\n ...(lastSlice ? [lastSlice] : []),\n {type: 'block' as const, block: child},\n ]\n }\n\n if (lastSlice) {\n if (lastSlice.type === 'children') {\n return [\n ...slices,\n {\n type: 'children' as const,\n children: [...lastSlice.children, child],\n },\n ]\n }\n }\n\n return [\n ...slices,\n ...(lastSlice ? [lastSlice] : []),\n {type: 'children' as const, children: [child]},\n ]\n },\n [] as Array<\n | {\n type: 'children'\n children: Array<PortableTextSpan | PortableTextObject>\n }\n | {type: 'block object'; block: PortableTextObject}\n | {type: 'block'; block: PortableTextBlock}\n >,\n )\n}\n","var s={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},c={0:8203,1:8204,2:8205,3:65279},u=new Array(4).fill(String.fromCodePoint(c[0])).join(\"\"),m=String.fromCharCode(0);function E(t){let e=JSON.stringify(t);return`${u}${Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(4).padStart(4,\"0\")).map(o=>String.fromCodePoint(c[o])).join(\"\")}).join(\"\")}`}function y(t){let e=JSON.stringify(t);return Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(16).padStart(2,\"0\")).map(o=>String.fromCodePoint(s[o])).join(\"\")}).join(\"\")}function I(t){return!Number.isNaN(Number(t))||/[a-z]/i.test(t)&&!/\\d+(?:[-:\\/]\\d+){2}(?:T\\d+(?:[-:\\/]\\d+){1,2}(\\.\\d+)?Z?)?/.test(t)?!1:Boolean(Date.parse(t))}function T(t){try{new URL(t,t.startsWith(\"/\")?\"https://acme.com\":void 0)}catch{return!1}return!0}function C(t,e,r=\"auto\"){return r===!0||r===\"auto\"&&(I(t)||T(t))?t:`${t}${E(e)}`}var x=Object.fromEntries(Object.entries(c).map(t=>t.reverse())),g=Object.fromEntries(Object.entries(s).map(t=>t.reverse())),S=`${Object.values(s).map(t=>`\\\\u{${t.toString(16)}}`).join(\"\")}`,f=new RegExp(`[${S}]{4,}`,\"gu\");function G(t){let e=t.match(f);if(!!e)return h(e[0],!0)[0]}function $(t){let e=t.match(f);if(!!e)return e.map(r=>h(r)).flat()}function h(t,e=!1){let r=Array.from(t);if(r.length%2===0){if(r.length%4||!t.startsWith(u))return A(r,e)}else throw new Error(\"Encoded data has invalid length\");let n=[];for(let o=r.length*.25;o--;){let p=r.slice(o*4,o*4+4).map(d=>x[d.codePointAt(0)]).join(\"\");n.unshift(String.fromCharCode(parseInt(p,4)))}if(e){n.shift();let o=n.indexOf(m);return o===-1&&(o=n.length),[JSON.parse(n.slice(0,o).join(\"\"))]}return n.join(\"\").split(m).filter(Boolean).map(o=>JSON.parse(o))}function A(t,e){var d;let r=[];for(let i=t.length*.5;i--;){let a=`${g[t[i*2].codePointAt(0)]}${g[t[i*2+1].codePointAt(0)]}`;r.unshift(String.fromCharCode(parseInt(a,16)))}let n=[],o=[r.join(\"\")],p=10;for(;o.length;){let i=o.shift();try{if(n.push(JSON.parse(i)),e)return n}catch(a){if(!p--)throw a;let l=+((d=a.message.match(/\\sposition\\s(\\d+)$/))==null?void 0:d[1]);if(!l)throw a;o.unshift(i.substring(0,l),i.substring(l))}}return n}function _(t){var e;return{cleaned:t.replace(f,\"\"),encoded:((e=t.match(f))==null?void 0:e[0])||\"\"}}function O(t){return t&&JSON.parse(_(JSON.stringify(t)).cleaned)}export{f as VERCEL_STEGA_REGEX,y as legacyStegaEncode,O as vercelStegaClean,C as vercelStegaCombine,G as vercelStegaDecode,$ as vercelStegaDecodeAll,E as vercelStegaEncode,_ as vercelStegaSplit};\n","import {uniq} from 'lodash'\n\nexport interface PartialBlock {\n _type: string\n markDefs: string[]\n style: string\n level?: number\n listItem?: string\n}\n\nexport const PRESERVE_WHITESPACE_TAGS = ['pre', 'textarea', 'code']\n\nexport const BLOCK_DEFAULT_STYLE = 'normal'\n\nexport const DEFAULT_BLOCK: PartialBlock = Object.freeze({\n _type: 'block',\n markDefs: [],\n style: BLOCK_DEFAULT_STYLE,\n})\n\nexport const DEFAULT_SPAN = Object.freeze({\n _type: 'span',\n marks: [] as string[],\n})\n\nexport const HTML_BLOCK_TAGS = {\n p: DEFAULT_BLOCK,\n blockquote: {...DEFAULT_BLOCK, style: 'blockquote'} as PartialBlock,\n}\n\nexport const HTML_SPAN_TAGS = {\n span: {object: 'text'},\n}\n\nexport const HTML_LIST_CONTAINER_TAGS: Record<\n string,\n {object: null} | undefined\n> = {\n ol: {object: null},\n ul: {object: null},\n}\n\nexport const HTML_HEADER_TAGS: Record<string, PartialBlock | undefined> = {\n h1: {...DEFAULT_BLOCK, style: 'h1'},\n h2: {...DEFAULT_BLOCK, style: 'h2'},\n h3: {...DEFAULT_BLOCK, style: 'h3'},\n h4: {...DEFAULT_BLOCK, style: 'h4'},\n h5: {...DEFAULT_BLOCK, style: 'h5'},\n h6: {...DEFAULT_BLOCK, style: 'h6'},\n}\n\nexport const HTML_MISC_TAGS = {\n br: {...DEFAULT_BLOCK, style: BLOCK_DEFAULT_STYLE} as PartialBlock,\n}\n\nexport const HTML_DECORATOR_TAGS: Record<string, string | undefined> = {\n b: 'strong',\n strong: 'strong',\n\n i: 'em',\n em: 'em',\n\n u: 'underline',\n s: 'strike-through',\n strike: 'strike-through',\n del: 'strike-through',\n\n code: 'code',\n sup: 'sup',\n sub: 'sub',\n ins: 'ins',\n mark: 'mark',\n small: 'small',\n}\n\nexport const HTML_LIST_ITEM_TAGS: Record<string, PartialBlock | undefined> = {\n li: {\n ...DEFAULT_BLOCK,\n style: BLOCK_DEFAULT_STYLE,\n level: 1,\n listItem: 'bullet',\n },\n}\n\nexport const ELEMENT_MAP = {\n ...HTML_BLOCK_TAGS,\n ...HTML_SPAN_TAGS,\n ...HTML_LIST_CONTAINER_TAGS,\n ...HTML_LIST_ITEM_TAGS,\n ...HTML_HEADER_TAGS,\n ...HTML_MISC_TAGS,\n}\n\nexport const DEFAULT_SUPPORTED_STYLES = uniq(\n Object.values(ELEMENT_MAP)\n .filter((tag): tag is PartialBlock => 'style' in tag)\n .map((tag) => tag.style),\n)\n\nexport const DEFAULT_SUPPORTED_DECORATORS = uniq(\n Object.values(HTML_DECORATOR_TAGS),\n)\n\nexport const DEFAULT_SUPPORTED_ANNOTATIONS = ['link']\n","// We need this here if run server side\nexport const _XPathResult = {\n ANY_TYPE: 0,\n NUMBER_TYPE: 1,\n STRING_TYPE: 2,\n BOOLEAN_TYPE: 3,\n UNORDERED_NODE_ITERATOR_TYPE: 4,\n ORDERED_NODE_ITERATOR_TYPE: 5,\n UNORDERED_NODE_SNAPSHOT_TYPE: 6,\n ORDERED_NODE_SNAPSHOT_TYPE: 7,\n ANY_UNORDERED_NODE_TYPE: 8,\n FIRST_ORDERED_NODE_TYPE: 9,\n}\n","import type {HtmlPreprocessorOptions} from '../../types'\nimport {normalizeWhitespace, removeAllWhitespace, tagName} from '../helpers'\nimport {_XPathResult} from './xpathResult'\n\nexport default (\n _html: string,\n doc: Document,\n options: HtmlPreprocessorOptions,\n): Document => {\n const whitespaceOnPasteMode =\n options?.unstable_whitespaceOnPasteMode || 'preserve'\n let gDocsRootOrSiblingNode = doc\n .evaluate(\n '//*[@id and contains(@id, \"docs-internal-guid\")]',\n doc,\n null,\n _XPathResult.ORDERED_NODE_ITERATOR_TYPE,\n null,\n )\n .iterateNext()\n\n if (gDocsRootOrSiblingNode) {\n const isWrappedRootTag = tagName(gDocsRootOrSiblingNode) === 'b'\n\n // If this document isn't wrapped in a 'b' tag, then assume all siblings live on the root level\n if (!isWrappedRootTag) {\n gDocsRootOrSiblingNode = doc.body\n }\n\n switch (whitespaceOnPasteMode) {\n case 'normalize':\n // Keep only 1 empty block between content nodes\n normalizeWhitespace(gDocsRootOrSiblingNode)\n break\n case 'remove':\n // Remove all whitespace nodes\n removeAllWhitespace(gDocsRootOrSiblingNode)\n break\n default:\n break\n }\n\n // Tag every child with attribute 'is-google-docs' so that the GDocs rule-set can\n // work exclusivly on these children\n const childNodes = doc.evaluate(\n '//*',\n doc,\n null,\n _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,\n null,\n )\n\n for (let i = childNodes.snapshotLength - 1; i >= 0; i--) {\n const elm = childNodes.snapshotItem(i) as HTMLElement\n elm?.setAttribute('data-is-google-docs', 'true')\n\n if (\n elm?.parentElement === gDocsRootOrSiblingNode ||\n (!isWrappedRootTag && elm.parentElement === doc.body)\n ) {\n elm?.setAttribute('data-is-root-node', 'true')\n tagName(elm)\n }\n\n // Handle checkmark lists - The first child of a list item is an image with a checkmark, and the serializer\n // expects the first child to be the text node\n if (\n tagName(elm) === 'li' &&\n elm.firstChild &&\n tagName(elm?.firstChild) === 'img'\n ) {\n elm.removeChild(elm.firstChild)\n }\n }\n\n // Remove that 'b' which Google Docs wraps the HTML content in\n if (isWrappedRootTag) {\n doc.body.firstElementChild?.replaceWith(\n ...Array.from(gDocsRootOrSiblingNode.childNodes),\n )\n }\n\n return doc\n }\n return doc\n}\n","import {_XPathResult} from './xpathResult'\n\n// Remove this cruft from the document\nconst unwantedWordDocumentPaths = [\n '/html/text()',\n '/html/head/text()',\n '/html/body/text()',\n '/html/body/ul/text()',\n '/html/body/ol/text()',\n '//comment()',\n '//style',\n '//xml',\n '//script',\n '//meta',\n '//link',\n]\n\nexport default (_html: string, doc: Document): Document => {\n // Make sure text directly on the body is wrapped in spans.\n // This mimics what the browser does before putting html on the clipboard,\n // when used in a script context with JSDOM\n const bodyTextNodes = doc.evaluate(\n '/html/body/text()',\n doc,\n null,\n _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,\n null,\n )\n\n for (let i = bodyTextNodes.snapshotLength - 1; i >= 0; i--) {\n const node = bodyTextNodes.snapshotItem(i) as HTMLElement\n const text = node.textContent || ''\n if (text.replace(/[^\\S\\n]+$/g, '')) {\n const newNode = doc.createElement('span')\n newNode.appendChild(doc.createTextNode(text))\n node.parentNode?.replaceChild(newNode, node)\n } else {\n node.parentNode?.removeChild(node)\n }\n }\n\n const unwantedNodes = doc.evaluate(\n unwantedWordDocumentPaths.join('|'),\n doc,\n null,\n _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,\n null,\n )\n for (let i = unwantedNodes.snapshotLength - 1; i >= 0; i--) {\n const unwanted = unwantedNodes.snapshotItem(i)\n if (!unwanted) {\n continue\n }\n unwanted.parentNode?.removeChild(unwanted)\n }\n return doc\n}\n","import {_XPathResult} from './xpathResult'\n\nexport default (html: string, doc: Document): Document => {\n const NOTION_REGEX = /<!-- notionvc:.*?-->/g\n\n if (html.match(NOTION_REGEX)) {\n // Tag every child with attribute 'is-notion' so that the Notion rule-set can\n // work exclusivly on these children\n const childNodes = doc.evaluate(\n '//*',\n doc,\n null,\n _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,\n null,\n )\n\n for (let i = childNodes.snapshotLength - 1; i >= 0; i--) {\n const elm = childNodes.snapshotItem(i) as HTMLElement\n elm?.setAttribute('data-is-notion', 'true')\n }\n\n return doc\n }\n return doc\n}\n","import {PRESERVE_WHITESPACE_TAGS} from '../../constants'\nimport {_XPathResult} from './xpathResult'\n\nexport default (_: string, doc: Document): Document => {\n // Recursively process all nodes.\n function processNode(node: Node) {\n // If this is a text node and not inside a tag where whitespace should be preserved, process it.\n if (\n node.nodeType === _XPathResult.BOOLEAN_TYPE &&\n !PRESERVE_WHITESPACE_TAGS.includes(\n node.parentElement?.tagName.toLowerCase() || '',\n )\n ) {\n node.textContent =\n node.textContent\n ?.replace(/\\s\\s+/g, ' ') // Remove multiple whitespace\n .replace(/[\\r\\n]+/g, ' ') || '' // Replace newlines with spaces\n }\n // Otherwise, if this node has children, process them.\n else {\n for (let i = 0; i < node.childNodes.length; i++) {\n processNode(node.childNodes[i])\n }\n }\n }\n\n // Process all nodes starting from the root.\n processNode(doc.body)\n\n return doc\n}\n","import {_XPathResult} from './xpathResult'\n\nconst WORD_HTML_REGEX =\n /(class=\"?Mso|style=(?:\"|')[^\"]*?\\bmso-|w:WordDocument|<o:\\w+>|<\\/font>)/\n\n// xPaths for elements that will be removed from the document\nconst unwantedPaths = [\n '//o:p',\n \"//span[@style='mso-list:Ignore']\",\n \"//span[@style='mso-list: Ignore']\",\n]\n\n// xPaths for elements that needs to be remapped into other tags\nconst mappedPaths = [\n \"//p[@class='MsoTocHeading']\",\n \"//p[@class='MsoTitle']\",\n \"//p[@class='MsoToaHeading']\",\n \"//p[@class='MsoSubtitle']\",\n \"//span[@class='MsoSubtleEmphasis']\",\n \"//span[@class='MsoIntenseEmphasis']\",\n]\n\n// Which HTML element(s) to map the elements matching mappedPaths into\nconst elementMap: Record<string, string[] | undefined> = {\n MsoTocHeading: ['h3'],\n MsoTitle: ['h1'],\n MsoToaHeading: ['h2'],\n MsoSubtitle: ['h5'],\n MsoSubtleEmphasis: ['span', 'em'],\n MsoIntenseEmphasis: ['span', 'em', 'strong'],\n // Remove cruft\n}\n\nfunction isWordHtml(html: string) {\n return WORD_HTML_REGEX.test(html)\n}\n\nexport default (html: string, doc: Document): Document => {\n if (!isWordHtml(html)) {\n return doc\n }\n\n const unwantedNodes = doc.evaluate(\n unwantedPaths.join('|'),\n doc,\n (prefix) => {\n if (prefix === 'o') {\n return 'urn:schemas-microsoft-com:office:office'\n }\n return null\n },\n _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,\n null,\n )\n\n for (let i = unwantedNodes.snapshotLength - 1; i >= 0; i--) {\n const unwanted = unwantedNodes.snapshotItem(i)\n if (unwanted?.parentNode) {\n unwanted.parentNode.removeChild(unwanted)\n }\n }\n\n // Transform mapped elements into what they should be mapped to\n const mappedElements = doc.evaluate(\n mappedPaths.join('|'),\n doc,\n null,\n _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,\n null,\n )\n for (let i = mappedElements.snapshotLength - 1; i >= 0; i--) {\n const mappedElm = mappedElements.snapshotItem(i) as HTMLElement\n const tags = elementMap[mappedElm.className]\n const text = doc.createTextNode(mappedElm.textContent || '')\n if (!tags) {\n continue\n }\n\n const parentElement = doc.createElement(tags[0])\n let parent = parentElement\n let child = parentElement\n tags.slice(1).forEach((tag) => {\n child = doc.createElement(tag)\n parent.appendChild(child)\n parent = child\n })\n child.appendChild(text)\n mappedElm?.parentNode?.replaceChild(parentElement, mappedElm)\n }\n\n return doc\n}\n","import preprocessGDocs from './gdocs'\nimport preprocessHTML from './html'\nimport preprocessNotion from './notion'\nimport preprocessWhitespace from './whitespace'\nimport preprocessWord from './word'\n\nexport default [\n preprocessWhitespace,\n preprocessNotion,\n preprocessWord,\n preprocessGDocs,\n preprocessHTML,\n]\n","import type {Schema} from '@portabletext/schema'\nimport {\n isTextBlock,\n type PortableTextObject,\n type PortableTextTextBlock,\n} from '@portabletext/schema'\nimport {vercelStegaClean} from '@vercel/stega'\nimport {isEqual} from 'lodash'\nimport {DEFAULT_BLOCK} from '../constants'\nimport type {\n ArbitraryTypedObject,\n HtmlParser,\n HtmlPreprocessorOptions,\n MinimalBlock,\n MinimalSpan,\n PlaceholderAnnotation,\n PlaceholderDecorator,\n TypedObject,\n} from '../types'\nimport {resolveJsType} from '../util/resolveJsType'\nimport preprocessors from './preprocessors'\n\n/**\n * Utility function that always return a lowerCase version of the element.tagName\n *\n * @param el - Element to get tag name for\n * @returns Lowercase tagName for that element, or undefined if not an element\n */\nexport function tagName(el: HTMLElement | Node | null): string | undefined {\n if (el && 'tagName' in el) {\n return el.tagName.toLowerCase()\n }\n\n return undefined\n}\n\n// TODO: make this plugin-style\nexport function preprocess(\n html: string,\n parseHtml: HtmlParser,\n options: HtmlPreprocessorOptions,\n): Document {\n const cleanHTML = vercelStegaClean(html)\n const doc = parseHtml(normalizeHtmlBeforePreprocess(cleanHTML))\n preprocessors.forEach((processor) => {\n processor(cleanHTML, doc, options)\n })\n return doc\n}\n\nfunction normalizeHtmlBeforePreprocess(html: string): string {\n return html.trim()\n}\n\n/**\n * A default `parseHtml` function that returns the html using `DOMParser`.\n *\n * @returns HTML Parser based on `DOMParser`\n */\nexport function defaultParseHtml(): HtmlParser {\n if (resolveJsType(DOMParser) === 'undefined') {\n throw new Error(\n 'The native `DOMParser` global which the `Html` deserializer uses by ' +\n 'default is not present in this environment. ' +\n 'You must supply the `options.parseHtml` function instead.',\n )\n }\n return (html) => {\n return new DOMParser().parseFromString(html, 'text/html')\n }\n}\n\nfunction nextSpan(block: PortableTextTextBlock, index: number) {\n const next = block.children[index + 1]\n return next && next._type === 'span' ? next : null\n}\n\nfunction prevSpan(block: PortableTextTextBlock, index: number) {\n const prev = block.children[index - 1]\n return prev && prev._type === 'span' ? prev : null\n}\n\nfunction isWhiteSpaceChar(text: string) {\n return ['\\xa0', ' '].includes(text)\n}\n\n/**\n * NOTE: _mutates_ passed blocks!\n *\n * @param blocks - Array of blocks to trim whitespace for\n * @returns\n */\nexport function trimWhitespace(\n schema: Schema,\n blocks: TypedObject[],\n): TypedObject[] {\n blocks.forEach((block) => {\n if (!isTextBlock({schema}, block)) {\n return\n }\n\n // eslint-disable-next-line complexity\n block.children.forEach((child, index) => {\n if (!isMinimalSpan(child)) {\n return\n }\n const nextChild = nextSpan(block, index)\n const prevChild = prevSpan(block, index)\n if (index === 0) {\n child.text = child.text.replace(/^[^\\S\\n]+/g, '')\n }\n if (index === block.children.length - 1) {\n child.text = child.text.replace(/[^\\S\\n]+$/g, '')\n }\n if (\n /\\s/.test(child.text.slice(Math.max(0, child.text.length - 1))) &&\n nextChild &&\n isMinimalSpan(nextChild) &&\n /\\s/.test(nextChild.text.slice(0, 1))\n ) {\n child.text = child.text.replace(/[^\\S\\n]+$/g, '')\n }\n if (\n /\\s/.test(child.text.slice(0, 1)) &&\n prevChild &&\n isMinimalSpan(prevChild) &&\n /\\s/.test(prevChild.text.slice(Math.max(0, prevChild.text.length - 1)))\n ) {\n child.text = child.text.replace(/^[^\\S\\n]+/g, '')\n }\n if (!child.text) {\n block.children.splice(index, 1)\n }\n if (\n prevChild &&\n isEqual(prevChild.marks, child.marks) &&\n isWhiteSpaceChar(child.text)\n ) {\n prevChild.text += ' '\n block.children.splice(index, 1)\n } else if (\n nextChild &&\n isEqual(nextChild.marks, child.marks) &&\n isWhiteSpaceChar(child.text)\n ) {\n nextChild.text = ` ${nextChild.text}`\n block.children.splice(index, 1)\n }\n })\n })\n\n return blocks\n}\n\nexport function ensureRootIsBlocks(\n schema: Schema,\n objects: Array<ArbitraryTypedObject>,\n): ArbitraryTypedObject[] {\n return objects.reduce((blocks, node, i, original) => {\n if (node._type === 'block') {\n blocks.push(node)\n return blocks\n }\n\n if (node._type === '__block') {\n blocks.push((node as any).block)\n return blocks\n }\n\n const lastBlock = blocks[blocks.length - 1]\n if (\n i > 0 &&\n !isTextBlock({schema}, original[i - 1]) &&\n isTextBlock({schema}, lastBlock)\n ) {\n lastBlock.children.push(node as PortableTextObject)\n return blocks\n }\n\n const block = {\n ...DEFAULT_BLOCK,\n children: [node],\n }\n\n blocks.push(block)\n return blocks\n }, [] as ArbitraryTypedObject[])\n}\n\nexport function isNodeList(node: unknown): node is NodeList {\n return Object.prototype.toString.call(node) === '[object NodeList]'\n}\n\nexport function isMinimalSpan(node: TypedObject): node is MinimalSpan {\n return node._type === 'span'\n}\n\nexport function isMinimalBlock(node: TypedObject): node is MinimalBlock {\n return node._type === 'block'\n}\n\nexport function isPlaceholderDecorator(\n node: TypedObject,\n): node is PlaceholderDecorator {\n return node._type === '__decorator'\n}\n\nexport function isPlaceholderAnnotation(\n node: TypedObject,\n): node is PlaceholderAnnotation {\n return node._type === '__annotation'\n}\n\nexport function isElement(node: Node): node is Element {\n return node.nodeType === 1\n}\n\n/**\n * Helper to normalize whitespace to only 1 empty block between content nodes\n * @param node - Root node to process\n */\nexport function normalizeWhitespace(rootNode: Node) {\n let emptyBlockCount = 0\n let lastParent = null\n const nodesToRemove: Node[] = []\n\n for (let child = rootNode.firstChild; child; child = child.nextSibling) {\n if (!isElement(child)) {\n normalizeWhitespace(child)\n emptyBlockCount = 0\n continue\n }\n\n const elm = child as HTMLElement\n\n if (isWhitespaceBlock(elm)) {\n if (lastParent && elm.parentElement === lastParent) {\n emptyBlockCount++\n if (emptyBlockCount > 1) {\n nodesToRemove.push(elm)\n }\n } else {\n // Different parent, reset counter\n emptyBlockCount = 1\n }\n\n lastParent = elm.parentElement\n } else {\n // Recurse into child nodes\n normalizeWhitespace(child)\n // Reset counter for siblings\n emptyBlockCount = 0\n }\n }\n\n // Remove marked nodes\n nodesToRemove.forEach((node) => {\n node.parentElement?.removeChild(node)\n })\n}\n\n/**\n * Helper to remove all whitespace nodes\n * @param node - Root node to process\n */\nexport function removeAllWhitespace(rootNode: Node) {\n const nodesToRemove: Node[] = []\n\n function collectNodesToRemove(currentNode: Node) {\n if (isElement(currentNode)) {\n const elm = currentNode as HTMLElement\n\n // Handle <br> tags that is between <p> tags\n if (\n tagName(elm) === 'br' &&\n (tagName(elm.nextElementSibling) === 'p' ||\n tagName(elm.previousElementSibling) === 'p')\n ) {\n nodesToRemove.push(elm)\n\n return\n }\n\n // Handle empty blocks\n if (\n (tagName(elm) === 'p' || tagName(elm) === 'br') &&\n elm?.firstChild?.textContent?.trim() === ''\n ) {\n nodesToRemove.push(elm)\n\n return\n }\n\n // Recursively process child nodes\n for (let child = elm.firstChild; child; child = child.nextSibling) {\n collectNodesToRemove(child)\n }\n }\n }\n\n collectNodesToRemove(rootNode)\n\n // Remove the collected nodes\n nodesToRemove.forEach((node) => {\n node.parentElement?.removeChild(node)\n })\n}\n\nfunction isWhitespaceBlock(elm: HTMLElement): boolean {\n return ['p', 'br'].includes(tagName(elm) || '') && !elm.textContent?.trim()\n}\n"],"names":["isTextBlock","isEqual","isSpan","uniq","_","vercelStegaClean","schema"],"mappings":";;;;;;AAAA,MAAM,iBAAiB,OAAO,UAAU;AAIjC,SAAS,cAAc,KAAc;AAC1C,UAAQ,eAAe,KAAK,GAAG,GAAA;AAAA,IAC7B,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACT;AAGF,SAAI,QAAQ,OACH,SAGL,QAAQ,SACH,cAIP,OACA,OAAO,OAAQ,YACf,cAAc,OACb,IAA4B,aAAa,IAEnC,YAGL,QAAQ,OAAO,GAAG,IACb,WAGF,OAAO;AAChB;ACzBO,SAAS,uBACd,QACgC;AAChC,SAAO,SAAS,MAAM,KAAK,OAAO,OAAO,SAAU;AACrD;AAEA,SAAS,SAAS,OAAkD;AAClE,SAAO,CAAC,CAAC,UAAU,OAAO,SAAU,YAAY,OAAO,SAAU;AACnE;ACVO,SAAS,oBACd,SAGA,QACe;AAkEf,SAjEkB,OAAO,QAAQ,CAAC,UAAU;AAC1C,QAAI,iBAAiB,KAAK;AACxB,aAAO,oBAAoB,SAAS,CAAC,MAAM,KAAK,CAAC;AAGnD,QAAIA,OAAAA,YAAY,SAAS,KAAK,GAAG;AAC/B,YAAM,kBAAkB,MAAM,SAAS,KAAK,CAAC,UAClB,QAAQ,OAAO,aAAa;AAAA,QACnD,CAAC,gBAAgB,YAAY,SAAS,MAAM;AAAA,MAAA,CAG/C,GACK,YAAY,MAAM,SAAS;AAAA,QAC/B,CAAC,UAAU,MAAM,UAAU,aAAa,MAAM,UA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AG,MAAM,SAChB,QAAQ,IAAI,kBAAkB,MAAM,OACnC,QAAQ,IAAI,sBAAsB,MAAM,MAC1C;AACA,sBAAc,KAAK,GAAG;AAEtB;AAAA,MACF;AAGA,WACG,QAAQ,GAAG,MAAM,OAAO,QAAQ,GAAG,MAAM,SAC1C,KAAK,YAAY,aAAa,KAAA,MAAW,IACzC;AACA,sBAAc,KAAK,GAAG;AAEtB;AAAA,MACF;AAGA,eAAS,QAAQ,IAAI,YAAY,OAAO,QAAQ,MAAM;AACpD,6BAAqB,KAAK;AAAA,IAE9B;AAAA,EACF;AAEA,uBAAqB,QAAQ,GAG7B,cAAc,QAAQ,CAAC,SAAS;AAC9B,SAAK,eAAe,YAAY,IAAI;AAAA,EACtC,CAAC;AACH;AAEA,SAAS,kBAAkB,KAA2B;AACpD,SAAO,CAAC,KAAK,IAAI,EAAE,SAAS,QAAQ,GAAG,KAAK,EAAE,KAAK,CAAC,IAAI,aAAa,KAAA;AACvE;;;;;;;;;;;;;;;;;;;;;;;","x_google_ignoreList":[3]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { PortableTextObject, Schema } from "@portabletext/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Use the current `Schema` as well as the potential element props to determine
|
|
4
|
+
* what Portable Text Object to use to represent the element.
|
|
5
|
+
*/
|
|
6
|
+
type ObjectSchemaMatcher<TProps extends Record<string, unknown>> = ({
|
|
7
|
+
context,
|
|
8
|
+
props
|
|
9
|
+
}: {
|
|
10
|
+
context: {
|
|
11
|
+
schema: Schema;
|
|
12
|
+
keyGenerator: () => string;
|
|
13
|
+
};
|
|
14
|
+
props: TProps;
|
|
15
|
+
}) => ArbitraryTypedObject | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Use the current `Schema` as well as the potential img element props to
|
|
18
|
+
* determine what Portable Text Object to use to represent the image.
|
|
19
|
+
* @beta
|
|
20
|
+
*/
|
|
21
|
+
type ImageSchemaMatcher = ObjectSchemaMatcher<{
|
|
22
|
+
src?: string;
|
|
23
|
+
alt?: string;
|
|
24
|
+
[key: string]: string | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* @beta
|
|
28
|
+
*/
|
|
29
|
+
type SchemaMatchers = {
|
|
30
|
+
/**
|
|
31
|
+
* Called whenever the HTML parsing encounters an `<img>` element that is
|
|
32
|
+
* inferred to be a block element.
|
|
33
|
+
*/
|
|
34
|
+
image?: ImageSchemaMatcher;
|
|
35
|
+
/**
|
|
36
|
+
* Called whenever the HTML parsing encounters an `<img>` element that is
|
|
37
|
+
* inferred to be an inline element.
|
|
38
|
+
*/
|
|
39
|
+
inlineImage?: ImageSchemaMatcher;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
interface TypedObject {
|
|
45
|
+
_type: string;
|
|
46
|
+
_key?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
interface ArbitraryTypedObject extends TypedObject {
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
type HtmlParser = (html: string) => Document;
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
type WhiteSpacePasteMode = 'preserve' | 'remove' | 'normalize';
|
|
62
|
+
/**
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
interface HtmlDeserializerOptions {
|
|
66
|
+
keyGenerator?: () => string;
|
|
67
|
+
rules?: DeserializerRule[];
|
|
68
|
+
parseHtml?: HtmlParser;
|
|
69
|
+
unstable_whitespaceOnPasteMode?: WhiteSpacePasteMode;
|
|
70
|
+
/**
|
|
71
|
+
* Custom schema matchers to use when deserializing HTML to Portable Text.
|
|
72
|
+
* @beta
|
|
73
|
+
*/
|
|
74
|
+
matchers?: SchemaMatchers;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
interface DeserializerRule {
|
|
80
|
+
deserialize: (el: Node, next: (elements: Node | Node[] | NodeList) => TypedObject | TypedObject[] | undefined, createBlock: (props: ArbitraryTypedObject) => {
|
|
81
|
+
_type: string;
|
|
82
|
+
block: ArbitraryTypedObject;
|
|
83
|
+
}) => TypedObject | TypedObject[] | undefined;
|
|
84
|
+
}
|
|
85
|
+
export { ArbitraryTypedObject, DeserializerRule, HtmlDeserializerOptions, HtmlParser, ImageSchemaMatcher, SchemaMatchers, TypedObject };
|