@quickbuilder.io/rich-text 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +122 -2
- package/adapters.d.ts +1 -0
- package/adapters.js +1 -0
- package/collaboration.d.ts +1 -0
- package/collaboration.js +1 -0
- package/commands.d.ts +1 -0
- package/commands.js +1 -0
- package/content.d.ts +1 -0
- package/content.js +1 -0
- package/contracts.d.ts +1 -0
- package/contracts.js +1 -0
- package/dist/adapters.d.mts +11 -0
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +564 -0
- package/dist/adapters.js.map +1 -0
- package/dist/adapters.mjs +557 -0
- package/dist/adapters.mjs.map +1 -0
- package/dist/collaboration.d.mts +29 -0
- package/dist/collaboration.d.ts +29 -0
- package/dist/collaboration.js +758 -0
- package/dist/collaboration.js.map +1 -0
- package/dist/collaboration.mjs +733 -0
- package/dist/collaboration.mjs.map +1 -0
- package/dist/commands.d.mts +8 -0
- package/dist/commands.d.ts +8 -0
- package/dist/commands.js +42 -0
- package/dist/commands.js.map +1 -0
- package/dist/commands.mjs +38 -0
- package/dist/commands.mjs.map +1 -0
- package/dist/content-types-CYHsrMrs.d.mts +27 -0
- package/dist/content-types-CYHsrMrs.d.ts +27 -0
- package/dist/content.d.mts +19 -0
- package/dist/content.d.ts +19 -0
- package/dist/content.js +785 -0
- package/dist/content.js.map +1 -0
- package/dist/content.mjs +775 -0
- package/dist/content.mjs.map +1 -0
- package/dist/contracts.d.mts +199 -0
- package/dist/contracts.d.ts +199 -0
- package/dist/contracts.js +4 -0
- package/dist/contracts.js.map +1 -0
- package/dist/contracts.mjs +3 -0
- package/dist/contracts.mjs.map +1 -0
- package/dist/extensions.d.mts +363 -0
- package/dist/extensions.d.ts +363 -0
- package/dist/extensions.js +153 -0
- package/dist/extensions.js.map +1 -0
- package/dist/extensions.mjs +142 -0
- package/dist/extensions.mjs.map +1 -0
- package/dist/history.d.mts +12 -0
- package/dist/history.d.ts +12 -0
- package/dist/history.js +464 -0
- package/dist/history.js.map +1 -0
- package/dist/history.mjs +459 -0
- package/dist/history.mjs.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1438 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1372 -0
- package/dist/index.mjs.map +1 -0
- package/dist/markdown.d.mts +32 -0
- package/dist/markdown.d.ts +32 -0
- package/dist/markdown.js +739 -0
- package/dist/markdown.js.map +1 -0
- package/dist/markdown.mjs +735 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/runtime/dom.d.mts +148 -0
- package/dist/runtime/dom.d.ts +148 -0
- package/dist/runtime/dom.js +2145 -0
- package/dist/runtime/dom.js.map +1 -0
- package/dist/runtime/dom.mjs +2084 -0
- package/dist/runtime/dom.mjs.map +1 -0
- package/dist/schema.d.mts +23 -0
- package/dist/schema.d.ts +23 -0
- package/dist/schema.js +157 -0
- package/dist/schema.js.map +1 -0
- package/dist/schema.mjs +137 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/serializer.d.mts +38 -0
- package/dist/serializer.d.ts +38 -0
- package/dist/serializer.js +504 -0
- package/dist/serializer.js.map +1 -0
- package/dist/serializer.mjs +491 -0
- package/dist/serializer.mjs.map +1 -0
- package/dist/svg-export-BtI8x_mG.d.mts +15 -0
- package/dist/svg-export-BtI8x_mG.d.ts +15 -0
- package/dist/transactions.d.mts +16 -0
- package/dist/transactions.d.ts +16 -0
- package/dist/transactions.js +637 -0
- package/dist/transactions.js.map +1 -0
- package/dist/transactions.mjs +631 -0
- package/dist/transactions.mjs.map +1 -0
- package/extensions.d.ts +1 -0
- package/extensions.js +1 -0
- package/history.d.ts +1 -0
- package/history.js +1 -0
- package/package.json +352 -4
- package/schema.d.ts +1 -0
- package/schema.js +1 -0
- package/serializer.d.ts +1 -0
- package/serializer.js +1 -0
- package/transactions.d.ts +1 -0
- package/transactions.js +1 -0
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,739 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/schema.ts
|
|
4
|
+
var QUICK_BUILDER_RICH_TEXT_SCHEMA_VERSION = 2;
|
|
5
|
+
var richTextAllowedTags = [
|
|
6
|
+
"a",
|
|
7
|
+
"b",
|
|
8
|
+
"blockquote",
|
|
9
|
+
"br",
|
|
10
|
+
"code",
|
|
11
|
+
"em",
|
|
12
|
+
"h1",
|
|
13
|
+
"h2",
|
|
14
|
+
"h3",
|
|
15
|
+
"h4",
|
|
16
|
+
"h5",
|
|
17
|
+
"h6",
|
|
18
|
+
"hr",
|
|
19
|
+
"i",
|
|
20
|
+
"img",
|
|
21
|
+
"input",
|
|
22
|
+
"label",
|
|
23
|
+
"li",
|
|
24
|
+
"mark",
|
|
25
|
+
"ol",
|
|
26
|
+
"p",
|
|
27
|
+
"pre",
|
|
28
|
+
"qb-video",
|
|
29
|
+
"s",
|
|
30
|
+
"span",
|
|
31
|
+
"sub",
|
|
32
|
+
"sup",
|
|
33
|
+
"strong",
|
|
34
|
+
"table",
|
|
35
|
+
"tbody",
|
|
36
|
+
"td",
|
|
37
|
+
"tfoot",
|
|
38
|
+
"th",
|
|
39
|
+
"thead",
|
|
40
|
+
"tr",
|
|
41
|
+
"u",
|
|
42
|
+
"ul"
|
|
43
|
+
];
|
|
44
|
+
var richTextVoidTags = ["br", "hr", "img", "input"];
|
|
45
|
+
var richTextAllowedTargets = ["_blank", "_self", "_parent", "_top"];
|
|
46
|
+
var richTextAlignmentTags = [
|
|
47
|
+
"blockquote",
|
|
48
|
+
"h1",
|
|
49
|
+
"h2",
|
|
50
|
+
"h3",
|
|
51
|
+
"h4",
|
|
52
|
+
"h5",
|
|
53
|
+
"h6",
|
|
54
|
+
"li",
|
|
55
|
+
"ol",
|
|
56
|
+
"p",
|
|
57
|
+
"pre",
|
|
58
|
+
"td",
|
|
59
|
+
"th",
|
|
60
|
+
"ul"
|
|
61
|
+
];
|
|
62
|
+
var richTextAllowedAlignments = ["left", "center", "right", "justify"];
|
|
63
|
+
var richTextAllowedFontFamilies = [
|
|
64
|
+
"default",
|
|
65
|
+
"carlito",
|
|
66
|
+
"source-sans-3",
|
|
67
|
+
"noto-sans",
|
|
68
|
+
"arimo",
|
|
69
|
+
"tinos",
|
|
70
|
+
"cousine"
|
|
71
|
+
];
|
|
72
|
+
var richTextAllowedFontSizes = [
|
|
73
|
+
"default",
|
|
74
|
+
"8",
|
|
75
|
+
"9",
|
|
76
|
+
"10",
|
|
77
|
+
"11",
|
|
78
|
+
"12",
|
|
79
|
+
"14",
|
|
80
|
+
"16",
|
|
81
|
+
"18",
|
|
82
|
+
"24",
|
|
83
|
+
"30",
|
|
84
|
+
"36",
|
|
85
|
+
"48",
|
|
86
|
+
"60",
|
|
87
|
+
"72",
|
|
88
|
+
"96"
|
|
89
|
+
];
|
|
90
|
+
var richTextAllowedLineHeights = ["1", "1.15", "1.5", "2"];
|
|
91
|
+
var richTextAllowedColors = [
|
|
92
|
+
"default",
|
|
93
|
+
"gray",
|
|
94
|
+
"brown",
|
|
95
|
+
"orange",
|
|
96
|
+
"yellow",
|
|
97
|
+
"green",
|
|
98
|
+
"blue",
|
|
99
|
+
"purple",
|
|
100
|
+
"pink",
|
|
101
|
+
"red"
|
|
102
|
+
];
|
|
103
|
+
function isRichTextAlignment(value) {
|
|
104
|
+
return richTextAllowedAlignments.includes(value);
|
|
105
|
+
}
|
|
106
|
+
function isRichTextFontFamily(value) {
|
|
107
|
+
return richTextAllowedFontFamilies.includes(value);
|
|
108
|
+
}
|
|
109
|
+
function isRichTextFontSize(value) {
|
|
110
|
+
return richTextAllowedFontSizes.includes(value);
|
|
111
|
+
}
|
|
112
|
+
function isRichTextLineHeight(value) {
|
|
113
|
+
return richTextAllowedLineHeights.includes(value);
|
|
114
|
+
}
|
|
115
|
+
function isRichTextColor(value) {
|
|
116
|
+
return richTextAllowedColors.includes(value);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/entities.ts
|
|
120
|
+
var entities = {
|
|
121
|
+
amp: "&",
|
|
122
|
+
lt: "<",
|
|
123
|
+
gt: ">",
|
|
124
|
+
quot: '"',
|
|
125
|
+
apos: "'",
|
|
126
|
+
nbsp: "\xA0",
|
|
127
|
+
copy: "\xA9",
|
|
128
|
+
reg: "\xAE",
|
|
129
|
+
trade: "\u2122",
|
|
130
|
+
mdash: "\u2014",
|
|
131
|
+
ndash: "\u2013",
|
|
132
|
+
hellip: "\u2026",
|
|
133
|
+
lsquo: "\u2018",
|
|
134
|
+
rsquo: "\u2019",
|
|
135
|
+
ldquo: "\u201C",
|
|
136
|
+
rdquo: "\u201D",
|
|
137
|
+
bull: "\u2022",
|
|
138
|
+
middot: "\xB7"
|
|
139
|
+
};
|
|
140
|
+
function decodeRichTextEntities(value) {
|
|
141
|
+
return value.replace(
|
|
142
|
+
/&(#x[\da-f]+|#\d+|[a-z][a-z\d]+);/gi,
|
|
143
|
+
(original, entity) => {
|
|
144
|
+
if (!entity.startsWith("#")) {
|
|
145
|
+
const decoded = entities[entity];
|
|
146
|
+
if (decoded === void 0)
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Unsupported named rich-text entity ${original}; use Unicode or a numeric entity`
|
|
149
|
+
);
|
|
150
|
+
return decoded;
|
|
151
|
+
}
|
|
152
|
+
const point = entity[1]?.toLowerCase() === "x" ? Number.parseInt(entity.slice(2), 16) : Number(entity.slice(1));
|
|
153
|
+
if (point < 1 || point > 1114111 || point >= 55296 && point <= 57343)
|
|
154
|
+
throw new Error("Invalid rich-text character entity");
|
|
155
|
+
return String.fromCodePoint(point);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/serializer.ts
|
|
161
|
+
var ACTIVE_CONTENT_TAG_PATTERN = /<\s*(script|style|iframe|object|embed|form)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi;
|
|
162
|
+
var ACTIVE_VOID_TAG_PATTERN = /<\s*(?:script|style|iframe|object|embed|link|meta|base)\b[^>]*\/?\s*>/gi;
|
|
163
|
+
var RICH_TEXT_VIDEO_PATTERN = /<qb-video\b((?:"[^"]*"|'[^']*'|[^'">])*)>[\s\S]*?<\/qb-video>/gi;
|
|
164
|
+
var RICH_TEXT_TAG_PATTERN = /<qb-video\b((?:"[^"]*"|'[^']*'|[^'">])*)>[\s\S]*?<\/qb-video>|<\/?([a-z][a-z0-9-]*)\b((?:"[^"]*"|'[^']*'|[^'">])*)>/gi;
|
|
165
|
+
var ATTRIBUTE_VALUE_PATTERN = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g;
|
|
166
|
+
var allowedTagSet = new Set(richTextAllowedTags);
|
|
167
|
+
var voidTagSet = new Set(richTextVoidTags);
|
|
168
|
+
var allowedTargetSet = new Set(richTextAllowedTargets);
|
|
169
|
+
var alignmentTagSet = new Set(richTextAlignmentTags);
|
|
170
|
+
var richTextMaximumUrlLength = 4096;
|
|
171
|
+
function validateRichTextVideo(src, title) {
|
|
172
|
+
src = src.trim();
|
|
173
|
+
title = title.trim();
|
|
174
|
+
if (!src || src.length > 2048 || !title || title.length > 200 || /[\u0000-\u0020\u007f\\]/u.test(src)) return;
|
|
175
|
+
const relative = /^\/(?!\/)/u.test(src);
|
|
176
|
+
if (!relative && !src.startsWith("https://")) return;
|
|
177
|
+
try {
|
|
178
|
+
const url = new URL(src, "https://rich-text.invalid");
|
|
179
|
+
if (url.protocol !== "https:" || url.username || url.password) return;
|
|
180
|
+
return { src, title };
|
|
181
|
+
} catch {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function readVideoAttributes(raw) {
|
|
186
|
+
const attributes = readHtmlAttributes(raw);
|
|
187
|
+
return validateRichTextVideo(attributes.get("data-src") ?? "", attributes.get("data-title") ?? "");
|
|
188
|
+
}
|
|
189
|
+
function sanitizeRichTextMarkup(value, options = {}) {
|
|
190
|
+
if (options.resolveImageSource !== void 0 && typeof options.resolveImageSource !== "function")
|
|
191
|
+
throw new TypeError("Invalid rich text image resolver.");
|
|
192
|
+
if (options.allowVideos !== void 0 && typeof options.allowVideos !== "boolean")
|
|
193
|
+
throw new TypeError("Invalid rich text video policy.");
|
|
194
|
+
if (options.videoPresentation !== void 0 && !["embed", "link"].includes(options.videoPresentation))
|
|
195
|
+
throw new TypeError("Invalid rich text video presentation.");
|
|
196
|
+
if (options.allowContentIdImages !== void 0 && typeof options.allowContentIdImages !== "boolean")
|
|
197
|
+
throw new TypeError("Invalid rich text Content-ID image policy.");
|
|
198
|
+
if (options.imageCrossOrigin !== void 0 && options.imageCrossOrigin !== "anonymous" && typeof options.imageCrossOrigin !== "function")
|
|
199
|
+
throw new TypeError("Invalid rich text image credentials policy.");
|
|
200
|
+
return sanitizeMarkup(value, options);
|
|
201
|
+
}
|
|
202
|
+
function sanitizeMarkup(value, options = {}) {
|
|
203
|
+
return value.replace(ACTIVE_CONTENT_TAG_PATTERN, "").replace(ACTIVE_VOID_TAG_PATTERN, "").replace(RICH_TEXT_TAG_PATTERN, (match, rawVideo, rawTagName, rawAttributes) => {
|
|
204
|
+
if (rawVideo !== void 0) {
|
|
205
|
+
if (options.allowVideos === false) return "";
|
|
206
|
+
const video = readVideoAttributes(rawVideo);
|
|
207
|
+
if (!video) return "";
|
|
208
|
+
if (options.videoPresentation === "link") {
|
|
209
|
+
return withBlockIdentity("<p>", rawVideo) + `<br><a href="${escapeHtmlAttribute(video.src)}">${escapeHtmlAttribute(video.title)}</a></p>`;
|
|
210
|
+
}
|
|
211
|
+
return withBlockIdentity(`<qb-video data-src="${escapeHtmlAttribute(video.src)}" data-title="${escapeHtmlAttribute(video.title)}" contenteditable="false">`, rawVideo) + "</qb-video>";
|
|
212
|
+
}
|
|
213
|
+
const tagName = rawTagName.toLowerCase();
|
|
214
|
+
if (tagName === "qb-video") return "";
|
|
215
|
+
if (!allowedTagSet.has(tagName)) {
|
|
216
|
+
return "";
|
|
217
|
+
}
|
|
218
|
+
if (match.startsWith("</")) {
|
|
219
|
+
return voidTagSet.has(tagName) ? "" : `</${tagName}>`;
|
|
220
|
+
}
|
|
221
|
+
if (voidTagSet.has(tagName)) {
|
|
222
|
+
if (tagName === "img") {
|
|
223
|
+
return withBlockIdentity(renderSafeImageTag(rawAttributes, options), rawAttributes);
|
|
224
|
+
}
|
|
225
|
+
if (tagName === "input") {
|
|
226
|
+
return withBlockIdentity(renderSafeTaskCheckbox(rawAttributes), rawAttributes);
|
|
227
|
+
}
|
|
228
|
+
return withBlockIdentity(`<${tagName}>`, rawAttributes);
|
|
229
|
+
}
|
|
230
|
+
if (tagName !== "a") {
|
|
231
|
+
return withBlockIdentity(renderSafeRichTextTag(tagName, rawAttributes), rawAttributes);
|
|
232
|
+
}
|
|
233
|
+
return renderSafeAnchorTag(rawAttributes);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function richTextHtmlToPlainText(html) {
|
|
237
|
+
if (html.length > 1e6) throw new RangeError("Rich text exceeds the serialization limit");
|
|
238
|
+
const text = sanitizeRichTextMarkup(html).replace(RICH_TEXT_VIDEO_PATTERN, (_element, raw) => `
|
|
239
|
+
${escapeHtmlAttribute(readVideoAttributes(raw)?.title ?? "")}
|
|
240
|
+
`).replace(/<!--[\s\S]*?-->/g, "").replace(/<(?:br|hr)\b[^>]*>/gi, "\n").replace(/<\/(?:p|h[1-6]|li|blockquote|pre|tr|table)>/gi, "\n").replace(/<\/(?:td|th)>/gi, " ").replace(/<[^>]*>/g, "");
|
|
241
|
+
return decodeRichTextEntities(text).replace(/\t+\n/g, "\n").trim();
|
|
242
|
+
}
|
|
243
|
+
function withBlockIdentity(tag, rawAttributes) {
|
|
244
|
+
const id = readHtmlAttributes(rawAttributes).get("data-qb-block-id");
|
|
245
|
+
if (!tag || tag.startsWith("<span") || !id || !/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(id)) return tag;
|
|
246
|
+
return tag.replace(/>$/, ` data-qb-block-id="${id}">`);
|
|
247
|
+
}
|
|
248
|
+
function renderSafeRichTextTag(tagName, rawAttributes) {
|
|
249
|
+
if (tagName === "span") {
|
|
250
|
+
return renderSafeSpanTag(rawAttributes);
|
|
251
|
+
}
|
|
252
|
+
if (tagName === "td" || tagName === "th") {
|
|
253
|
+
return renderSafeTableCellTag(tagName, rawAttributes);
|
|
254
|
+
}
|
|
255
|
+
if (tagName === "ul") {
|
|
256
|
+
const attributes2 = readHtmlAttributes(rawAttributes);
|
|
257
|
+
return attributes2.get("data-task-list") === "true" ? '<ul data-task-list="true">' : "<ul>";
|
|
258
|
+
}
|
|
259
|
+
if (tagName === "li") {
|
|
260
|
+
const attributes2 = readHtmlAttributes(rawAttributes);
|
|
261
|
+
const checked = attributes2.get("data-checked");
|
|
262
|
+
return checked === "true" || checked === "false" ? `<li data-checked="${checked}">` : "<li>";
|
|
263
|
+
}
|
|
264
|
+
if (!alignmentTagSet.has(tagName)) {
|
|
265
|
+
return `<${tagName}>`;
|
|
266
|
+
}
|
|
267
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
268
|
+
const renderedAttributes = [];
|
|
269
|
+
const alignment = attributes.get("data-align");
|
|
270
|
+
const lineHeight = attributes.get("data-line-height");
|
|
271
|
+
if (isRichTextAlignment(alignment)) renderedAttributes.push(`data-align="${alignment}"`);
|
|
272
|
+
if (isRichTextLineHeight(lineHeight)) renderedAttributes.push(`data-line-height="${lineHeight}"`);
|
|
273
|
+
return renderedAttributes.length > 0 ? `<${tagName} ${renderedAttributes.join(" ")}>` : `<${tagName}>`;
|
|
274
|
+
}
|
|
275
|
+
function renderSafeSpanTag(rawAttributes) {
|
|
276
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
277
|
+
const renderedAttributes = [];
|
|
278
|
+
const id = normalizeMentionAttribute(attributes.get("data-mention-id"), 128);
|
|
279
|
+
const label = normalizeMentionAttribute(attributes.get("data-mention-label"), 160);
|
|
280
|
+
const fontFamily = attributes.get("data-font-family");
|
|
281
|
+
const fontSize = attributes.get("data-font-size");
|
|
282
|
+
const textColor = attributes.get("data-text-color");
|
|
283
|
+
const highlightColor = attributes.get("data-highlight-color");
|
|
284
|
+
if (id && label) {
|
|
285
|
+
renderedAttributes.push(
|
|
286
|
+
`data-mention-id="${escapeHtmlAttribute(id)}"`,
|
|
287
|
+
`data-mention-label="${escapeHtmlAttribute(label)}"`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
if (isRichTextFontFamily(fontFamily) && fontFamily !== "default") renderedAttributes.push(`data-font-family="${fontFamily}"`);
|
|
291
|
+
if (isRichTextFontSize(fontSize) && fontSize !== "default") renderedAttributes.push(`data-font-size="${fontSize}"`);
|
|
292
|
+
if (isRichTextColor(textColor) && textColor !== "default") renderedAttributes.push(`data-text-color="${textColor}"`);
|
|
293
|
+
if (isRichTextColor(highlightColor) && highlightColor !== "default") renderedAttributes.push(`data-highlight-color="${highlightColor}"`);
|
|
294
|
+
return renderedAttributes.length > 0 ? `<span ${renderedAttributes.join(" ")}>` : "<span>";
|
|
295
|
+
}
|
|
296
|
+
function renderSafeTableCellTag(tagName, rawAttributes) {
|
|
297
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
298
|
+
const renderedAttributes = [];
|
|
299
|
+
const alignment = attributes.get("data-align");
|
|
300
|
+
const colSpan = normalizeTableSpan(attributes.get("colspan"));
|
|
301
|
+
const rowSpan = normalizeTableSpan(attributes.get("rowspan"));
|
|
302
|
+
const scope = attributes.get("scope");
|
|
303
|
+
if (isRichTextAlignment(alignment)) {
|
|
304
|
+
renderedAttributes.push(`data-align="${alignment}"`);
|
|
305
|
+
}
|
|
306
|
+
if (colSpan) {
|
|
307
|
+
renderedAttributes.push(`colspan="${colSpan}"`);
|
|
308
|
+
}
|
|
309
|
+
if (rowSpan) {
|
|
310
|
+
renderedAttributes.push(`rowspan="${rowSpan}"`);
|
|
311
|
+
}
|
|
312
|
+
if (tagName === "th" && scope && ["col", "row", "colgroup", "rowgroup"].includes(scope)) {
|
|
313
|
+
renderedAttributes.push(`scope="${scope}"`);
|
|
314
|
+
}
|
|
315
|
+
return renderedAttributes.length > 0 ? `<${tagName} ${renderedAttributes.join(" ")}>` : `<${tagName}>`;
|
|
316
|
+
}
|
|
317
|
+
function renderSafeAnchorTag(rawAttributes) {
|
|
318
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
319
|
+
const renderedAttributes = [];
|
|
320
|
+
const href = attributes.get("href");
|
|
321
|
+
const target = attributes.get("target");
|
|
322
|
+
if (href && isSafeRichTextHref(href)) {
|
|
323
|
+
renderedAttributes.push(`href="${escapeHtmlAttribute(href)}"`);
|
|
324
|
+
}
|
|
325
|
+
if (target && allowedTargetSet.has(target)) {
|
|
326
|
+
renderedAttributes.push(`target="${target}"`);
|
|
327
|
+
if (target === "_blank") {
|
|
328
|
+
renderedAttributes.push('rel="noopener noreferrer"');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return renderedAttributes.length > 0 ? `<a ${renderedAttributes.join(" ")}>` : "<a>";
|
|
332
|
+
}
|
|
333
|
+
function renderSafeImageTag(rawAttributes, options) {
|
|
334
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
335
|
+
const source = attributes.get("src");
|
|
336
|
+
const resolveSource = options.resolveImageSource;
|
|
337
|
+
if (!source || !resolveSource && !isAllowedImageSource(source, options)) return "";
|
|
338
|
+
const src = resolveSource ? resolveSource(source) : source;
|
|
339
|
+
if (src === null) return "";
|
|
340
|
+
if (!isAllowedImageSource(src, options)) throw new TypeError("Invalid replacement image URL.");
|
|
341
|
+
const renderedAttributes = [
|
|
342
|
+
`src="${escapeHtmlAttribute(src)}"`,
|
|
343
|
+
`alt="${escapeHtmlAttribute(normalizeTextAttribute(attributes.get("alt"), 512) ?? "")}"`
|
|
344
|
+
];
|
|
345
|
+
const title = normalizeTextAttribute(attributes.get("title"), 512);
|
|
346
|
+
const width = normalizeImageDimension(attributes.get("width"));
|
|
347
|
+
const height = normalizeImageDimension(attributes.get("height"));
|
|
348
|
+
if (title) renderedAttributes.push(`title="${escapeHtmlAttribute(title)}"`);
|
|
349
|
+
if (width) renderedAttributes.push(`width="${width}"`);
|
|
350
|
+
if (height) renderedAttributes.push(`height="${height}"`);
|
|
351
|
+
const credentials = typeof options.imageCrossOrigin === "function" ? options.imageCrossOrigin(src) : options.imageCrossOrigin;
|
|
352
|
+
if (credentials !== void 0 && credentials !== "anonymous") throw new TypeError("Invalid resolved image credentials policy.");
|
|
353
|
+
if ((credentials ?? attributes.get("crossorigin")) === "anonymous") renderedAttributes.push('crossorigin="anonymous"');
|
|
354
|
+
renderedAttributes.push('loading="lazy"', 'decoding="async"');
|
|
355
|
+
return `<img ${renderedAttributes.join(" ")}>`;
|
|
356
|
+
}
|
|
357
|
+
function isAllowedImageSource(value, options) {
|
|
358
|
+
if (isSafeRichTextImageSrc(value)) return true;
|
|
359
|
+
if (!options.allowContentIdImages || value.length > richTextMaximumUrlLength || !/^cid:/iu.test(value)) return false;
|
|
360
|
+
try {
|
|
361
|
+
const identity = decodeURIComponent(value.slice(4));
|
|
362
|
+
return identity.length > 0 && identity.length <= 200 && !/[^\u0021-\u007e]|[<>"]/u.test(identity);
|
|
363
|
+
} catch {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function renderSafeTaskCheckbox(rawAttributes) {
|
|
368
|
+
const attributes = readHtmlAttributes(rawAttributes);
|
|
369
|
+
if (attributes.get("type")?.toLowerCase() !== "checkbox") return "";
|
|
370
|
+
const checked = attributes.get("checked") !== void 0 || /(?:^|\s)checked(?:\s|=|$)/i.test(rawAttributes);
|
|
371
|
+
return `<input type="checkbox"${checked ? ' checked=""' : ""} contenteditable="false">`;
|
|
372
|
+
}
|
|
373
|
+
function readHtmlAttributes(rawAttributes) {
|
|
374
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
375
|
+
for (const match of rawAttributes.matchAll(ATTRIBUTE_VALUE_PATTERN)) {
|
|
376
|
+
const name = match[1]?.toLowerCase();
|
|
377
|
+
const value = match[2] ?? match[3] ?? match[4] ?? "";
|
|
378
|
+
if (name) {
|
|
379
|
+
attributes.set(name, decodeHtmlAttribute(value.trim()));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return attributes;
|
|
383
|
+
}
|
|
384
|
+
function isSafeRichTextHref(value) {
|
|
385
|
+
const trimmed = value.trim();
|
|
386
|
+
if (!trimmed || trimmed.length > richTextMaximumUrlLength || /[\u0000-\u001f\u007f]/.test(trimmed)) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
if (trimmed.startsWith("//")) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
if (/^(?:#|\/|\.\/|\.\.\/|\?)/.test(trimmed)) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
try {
|
|
396
|
+
const url = new URL(trimmed);
|
|
397
|
+
return ["http:", "https:", "mailto:", "tel:"].includes(url.protocol.toLowerCase());
|
|
398
|
+
} catch {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function isSafeRichTextImageSrc(value) {
|
|
403
|
+
const trimmed = value.trim();
|
|
404
|
+
if (!trimmed || trimmed.length > richTextMaximumUrlLength || /[\u0000-\u001f\u007f]/.test(trimmed) || trimmed.startsWith("//")) return false;
|
|
405
|
+
if (/^(?:\/|\.\/|\.\.\/)/.test(trimmed)) return true;
|
|
406
|
+
try {
|
|
407
|
+
const url = new URL(trimmed);
|
|
408
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
409
|
+
} catch {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function normalizeTableSpan(value) {
|
|
414
|
+
if (!value || !/^\d{1,3}$/.test(value)) {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
const numericValue = Number(value);
|
|
418
|
+
return numericValue >= 1 && numericValue <= 100 ? String(numericValue) : null;
|
|
419
|
+
}
|
|
420
|
+
function normalizeMentionAttribute(value, maxLength) {
|
|
421
|
+
const normalized = value?.trim();
|
|
422
|
+
if (!normalized || normalized.length > maxLength || /[<>"'`]/.test(normalized)) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
return normalized;
|
|
426
|
+
}
|
|
427
|
+
function normalizeTextAttribute(value, maxLength) {
|
|
428
|
+
const normalized = value?.trim();
|
|
429
|
+
if (!normalized || normalized.length > maxLength) return null;
|
|
430
|
+
return normalized;
|
|
431
|
+
}
|
|
432
|
+
function normalizeImageDimension(value) {
|
|
433
|
+
if (!value || !/^\d{1,5}$/.test(value)) return null;
|
|
434
|
+
const numericValue = Number(value);
|
|
435
|
+
return numericValue >= 1 && numericValue <= 1e4 ? String(numericValue) : null;
|
|
436
|
+
}
|
|
437
|
+
function escapeHtmlAttribute(value) {
|
|
438
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
439
|
+
}
|
|
440
|
+
function decodeHtmlAttribute(value) {
|
|
441
|
+
return value.replace(/&(?:#(\d+)|#x([0-9a-f]+)|(amp|quot|apos|lt|gt));/gi, (entity, decimal, hexadecimal, named) => {
|
|
442
|
+
if (decimal || hexadecimal) {
|
|
443
|
+
const codePoint = decimal ? Number(decimal) : Number.parseInt(hexadecimal, 16);
|
|
444
|
+
if (!Number.isSafeInteger(codePoint) || codePoint <= 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) {
|
|
445
|
+
return "\uFFFD";
|
|
446
|
+
}
|
|
447
|
+
return String.fromCodePoint(codePoint);
|
|
448
|
+
}
|
|
449
|
+
const namedEntity = {
|
|
450
|
+
amp: "&",
|
|
451
|
+
apos: "'",
|
|
452
|
+
gt: ">",
|
|
453
|
+
lt: "<",
|
|
454
|
+
quot: '"'
|
|
455
|
+
};
|
|
456
|
+
return namedEntity[String(named).toLowerCase()] ?? entity;
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// src/markdown.ts
|
|
461
|
+
var DEFAULT_MAX_MARKDOWN_LENGTH = 1e6;
|
|
462
|
+
var MAX_MARKDOWN_LENGTH = 5e6;
|
|
463
|
+
var INLINE_TOKEN_PREFIX = "\0qb-markdown-inline-";
|
|
464
|
+
var HARD_BREAK_TOKEN = "\0qb-markdown-hard-break\0";
|
|
465
|
+
function assertMarkdownOptions(options) {
|
|
466
|
+
const maxLength = options.maxLength ?? DEFAULT_MAX_MARKDOWN_LENGTH;
|
|
467
|
+
const limitBehavior = options.limitBehavior ?? "throw";
|
|
468
|
+
if (!Number.isInteger(maxLength) || maxLength < 1 || maxLength > MAX_MARKDOWN_LENGTH) {
|
|
469
|
+
throw new Error(
|
|
470
|
+
`Unsupported markdown maxLength "${String(maxLength)}". Use an integer from 1 to ${MAX_MARKDOWN_LENGTH}.`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
if (limitBehavior !== "throw" && limitBehavior !== "truncate") {
|
|
474
|
+
throw new Error(
|
|
475
|
+
`Unsupported markdown limitBehavior "${String(limitBehavior)}". Use "throw" or "truncate".`
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
return { limitBehavior, maxLength };
|
|
479
|
+
}
|
|
480
|
+
function normalizeMarkdown(markdown, options) {
|
|
481
|
+
if (typeof markdown !== "string") {
|
|
482
|
+
throw new Error("Markdown content must be a string.");
|
|
483
|
+
}
|
|
484
|
+
const { limitBehavior, maxLength } = assertMarkdownOptions(options);
|
|
485
|
+
const normalized = markdown.replace(/\u0000/g, "").replace(/\r\n?/g, "\n");
|
|
486
|
+
if (normalized.length <= maxLength) return normalized;
|
|
487
|
+
if (limitBehavior === "truncate") return normalized.slice(0, maxLength);
|
|
488
|
+
throw new Error(
|
|
489
|
+
`Markdown content exceeds the configured ${maxLength} character limit.`
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
function escapeHtml(value) {
|
|
493
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
494
|
+
}
|
|
495
|
+
function renderInlineMarkdown(value) {
|
|
496
|
+
const tokens = [];
|
|
497
|
+
const protect = (html, text = html) => {
|
|
498
|
+
const token = `${INLINE_TOKEN_PREFIX}${tokens.length}\0`;
|
|
499
|
+
tokens.push({ html, text });
|
|
500
|
+
return token;
|
|
501
|
+
};
|
|
502
|
+
const restore = (source2, format) => source2.replace(
|
|
503
|
+
/\u0000qb-markdown-inline-(\d+)\u0000/g,
|
|
504
|
+
(_match, index) => tokens[Number(index)]?.[format] ?? ""
|
|
505
|
+
);
|
|
506
|
+
let source = value.replace(
|
|
507
|
+
/\\([\\`*_[\]{}()#+\-.!|>~])|(`+)([\s\S]*?[^`])\2(?!`)/g,
|
|
508
|
+
(_match, character, _ticks, code) => {
|
|
509
|
+
if (character !== void 0) return protect(escapeHtml(character), character);
|
|
510
|
+
const text = code.trim();
|
|
511
|
+
return protect(`<code>${escapeHtml(text)}</code>`, text);
|
|
512
|
+
}
|
|
513
|
+
).replace(
|
|
514
|
+
/(!?)\[([^\]\n]*)\]\(\s*(<[^>\n]+>|(?:[^\s()]|\([^()]*\))+)(?:\s+["']([^"']*)["'])?\s*\)/g,
|
|
515
|
+
(_match, image, label, destination, title) => {
|
|
516
|
+
const url = restore(destination.replace(/^<|>$/g, ""), "text");
|
|
517
|
+
if (image) {
|
|
518
|
+
const alt = escapeHtml(restore(label, "text"));
|
|
519
|
+
const description = title && escapeHtml(restore(title, "text"));
|
|
520
|
+
return protect(
|
|
521
|
+
isSafeRichTextImageSrc(url) ? `<img src="${escapeHtml(url)}" alt="${alt}"${description ? ` title="${description}"` : ""}>` : alt
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
const labelHtml = restore(escapeHtml(label), "html");
|
|
525
|
+
return protect(
|
|
526
|
+
isSafeRichTextHref(url) ? `<a href="${escapeHtml(url)}" target="_blank">${labelHtml}</a>` : labelHtml
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
).replace(
|
|
530
|
+
/<(https?:\/\/[^<>\s]+|mailto:[^<>\s]+)>/gi,
|
|
531
|
+
(_match, url) => protect(
|
|
532
|
+
isSafeRichTextHref(url) ? `<a href="${escapeHtml(url)}" target="_blank">${escapeHtml(url)}</a>` : escapeHtml(url)
|
|
533
|
+
)
|
|
534
|
+
).replace(/https?:\/\/[^\s<>\u0000]+/gi, (candidate) => {
|
|
535
|
+
const url = candidate.replace(/[.,!?;:)]+$/, "");
|
|
536
|
+
return isSafeRichTextHref(url) ? protect(
|
|
537
|
+
`<a href="${escapeHtml(url)}" target="_blank">${escapeHtml(url)}</a>`
|
|
538
|
+
) + candidate.slice(url.length) : candidate;
|
|
539
|
+
});
|
|
540
|
+
source = escapeHtml(source).replace(/\*\*([^*\n]+)\*\*/g, "<strong>$1</strong>").replace(/__([^_\n]+)__/g, "<strong>$1</strong>").replace(/~~([^~\n]+)~~/g, "<s>$1</s>").replace(/(^|[^\w])\*([^*\n]+)\*(?!\*)/g, "$1<em>$2</em>").replace(/(^|[^\w])_([^_\n]+)_(?!_)/g, "$1<em>$2</em>");
|
|
541
|
+
return restore(source, "html");
|
|
542
|
+
}
|
|
543
|
+
function splitTableRow(line) {
|
|
544
|
+
const trimmed = line.trim().replace(/^\|/, "");
|
|
545
|
+
const cells = [];
|
|
546
|
+
let current = "";
|
|
547
|
+
for (let index = 0; index < trimmed.length; index += 1) {
|
|
548
|
+
const character = trimmed[index];
|
|
549
|
+
const next = trimmed[index + 1];
|
|
550
|
+
if (character === "\\" && (next === "\\" || next === "|")) {
|
|
551
|
+
current += next === "|" ? next : "\\\\";
|
|
552
|
+
index += 1;
|
|
553
|
+
} else if (character === "|") {
|
|
554
|
+
cells.push(current.trim());
|
|
555
|
+
if (index === trimmed.length - 1) return cells;
|
|
556
|
+
current = "";
|
|
557
|
+
} else {
|
|
558
|
+
current += character;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
cells.push(current.trim());
|
|
562
|
+
return cells;
|
|
563
|
+
}
|
|
564
|
+
function isTableSeparator(line) {
|
|
565
|
+
const cells = splitTableRow(line);
|
|
566
|
+
return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell.replace(/\s+/g, "")));
|
|
567
|
+
}
|
|
568
|
+
function renderTable(lines, startIndex) {
|
|
569
|
+
const header = lines[startIndex];
|
|
570
|
+
const separator = lines[startIndex + 1];
|
|
571
|
+
if (header === void 0 || separator === void 0 || !header.includes("|") || !isTableSeparator(separator)) {
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
const headerCells = splitTableRow(header);
|
|
575
|
+
const bodyRows = [];
|
|
576
|
+
let width = headerCells.length;
|
|
577
|
+
let nextIndex = startIndex + 2;
|
|
578
|
+
while (nextIndex < lines.length && lines[nextIndex]?.trim() && lines[nextIndex]?.includes("|")) {
|
|
579
|
+
const row = splitTableRow(lines[nextIndex]);
|
|
580
|
+
bodyRows.push(row);
|
|
581
|
+
width = Math.max(width, row.length);
|
|
582
|
+
nextIndex += 1;
|
|
583
|
+
}
|
|
584
|
+
const normalizeRow = (row) => Array.from({ length: width }, (_unused, index) => row[index] ?? "");
|
|
585
|
+
const head = normalizeRow(headerCells).map((cell) => `<th scope="col">${renderInlineMarkdown(cell)}</th>`).join("");
|
|
586
|
+
const body = bodyRows.map(
|
|
587
|
+
(row) => `<tr>${normalizeRow(row).map((cell) => `<td>${renderInlineMarkdown(cell)}</td>`).join("")}</tr>`
|
|
588
|
+
).join("");
|
|
589
|
+
return {
|
|
590
|
+
html: `<table><thead><tr>${head}</tr></thead>${body ? `<tbody>${body}</tbody>` : ""}</table>`,
|
|
591
|
+
nextIndex
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
var listPattern = /^( *)(?:(\d+)[.)]|[-+*]) +(.*)$/;
|
|
595
|
+
function serializeBlocks(blocks) {
|
|
596
|
+
return blocks.map(
|
|
597
|
+
(block) => block.type === "html" ? block.html : `<pre><code>${escapeHtml(block.value)}</code></pre>`
|
|
598
|
+
).join("");
|
|
599
|
+
}
|
|
600
|
+
function parseBlocks(lines, depth = 0) {
|
|
601
|
+
if (depth > 48)
|
|
602
|
+
throw new Error("Markdown nesting exceeds the supported 48 levels.");
|
|
603
|
+
const blocks = [];
|
|
604
|
+
const paragraph = [];
|
|
605
|
+
const pushHtml = (html) => blocks.push({ type: "html", html: sanitizeRichTextMarkup(html) });
|
|
606
|
+
const flush = () => {
|
|
607
|
+
if (!paragraph.length) return;
|
|
608
|
+
pushHtml(
|
|
609
|
+
`<p>${paragraph.map((line) => renderInlineMarkdown(line.trim())).join(" ").split(HARD_BREAK_TOKEN).join("<br>")}</p>`
|
|
610
|
+
);
|
|
611
|
+
paragraph.length = 0;
|
|
612
|
+
};
|
|
613
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
614
|
+
const line = lines[index] ?? "";
|
|
615
|
+
const trimmed = line.trim();
|
|
616
|
+
if (!trimmed) {
|
|
617
|
+
flush();
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
const fence = /^ {0,3}(`{3,}|~{3,})([^\n]*)$/.exec(line);
|
|
621
|
+
if (fence && !(fence[1].startsWith("`") && fence[2].includes("`"))) {
|
|
622
|
+
flush();
|
|
623
|
+
const marker = fence[1];
|
|
624
|
+
const language = fence[2].trim().split(/\s+/)[0];
|
|
625
|
+
const code = [];
|
|
626
|
+
const closing = new RegExp(`^ {0,3}${marker[0]}{${marker.length},} *$`);
|
|
627
|
+
index += 1;
|
|
628
|
+
for (; index < lines.length && !closing.test(lines[index]); index += 1)
|
|
629
|
+
code.push(lines[index]);
|
|
630
|
+
blocks.push({
|
|
631
|
+
type: "code",
|
|
632
|
+
value: code.join("\n"),
|
|
633
|
+
language: language || void 0
|
|
634
|
+
});
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
const table = renderTable(lines, index);
|
|
638
|
+
if (table) {
|
|
639
|
+
flush();
|
|
640
|
+
pushHtml(table.html);
|
|
641
|
+
index = table.nextIndex - 1;
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
const heading = /^(#{1,6})\s+(.+?)\s*#*$/.exec(trimmed);
|
|
645
|
+
if (heading) {
|
|
646
|
+
flush();
|
|
647
|
+
const level = heading[1].length;
|
|
648
|
+
pushHtml(`<h${level}>${renderInlineMarkdown(heading[2])}</h${level}>`);
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (/^(?:-{3,}|\*{3,}|_{3,})$/.test(trimmed.replace(/\s+/g, ""))) {
|
|
652
|
+
flush();
|
|
653
|
+
pushHtml("<hr>");
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
if (/^>/.test(trimmed)) {
|
|
657
|
+
flush();
|
|
658
|
+
const quote = [];
|
|
659
|
+
while (index < lines.length && /^\s*>/.test(lines[index])) {
|
|
660
|
+
quote.push(lines[index].replace(/^\s*> ?/, ""));
|
|
661
|
+
index += 1;
|
|
662
|
+
}
|
|
663
|
+
index -= 1;
|
|
664
|
+
pushHtml(
|
|
665
|
+
`<blockquote>${serializeBlocks(parseBlocks(quote, depth + 1))}</blockquote>`
|
|
666
|
+
);
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
const firstItem = listPattern.exec(line);
|
|
670
|
+
if (firstItem) {
|
|
671
|
+
flush();
|
|
672
|
+
const indent = firstItem[1].length;
|
|
673
|
+
const ordered = firstItem[2] !== void 0;
|
|
674
|
+
const items = [];
|
|
675
|
+
let hasTasks = false;
|
|
676
|
+
while (index < lines.length) {
|
|
677
|
+
const item = listPattern.exec(lines[index]);
|
|
678
|
+
if (!item || item[1].length !== indent || item[2] !== void 0 !== ordered)
|
|
679
|
+
break;
|
|
680
|
+
const contentIndent = lines[index].length - item[3].length;
|
|
681
|
+
const task = /^\[([ xX])\] +(.*)$/.exec(item[3]);
|
|
682
|
+
const content = task ? task[2] : item[3];
|
|
683
|
+
if (task) hasTasks = true;
|
|
684
|
+
const continuation = [];
|
|
685
|
+
index += 1;
|
|
686
|
+
for (; index < lines.length; index += 1) {
|
|
687
|
+
const next = lines[index];
|
|
688
|
+
if (!next.trim()) {
|
|
689
|
+
if ((/^ */.exec(lines[index + 1] ?? "")?.[0].length ?? 0) >= contentIndent) {
|
|
690
|
+
continuation.push("");
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
const spaces = /^ */.exec(next)[0].length;
|
|
696
|
+
if (spaces < contentIndent) break;
|
|
697
|
+
continuation.push(next.slice(contentIndent));
|
|
698
|
+
}
|
|
699
|
+
const nested = continuation.length ? serializeBlocks(parseBlocks(continuation, depth + 1)) : "";
|
|
700
|
+
const checked = task?.[1]?.toLowerCase() === "x";
|
|
701
|
+
const label = task ? `<label><input type="checkbox"${checked ? ' checked=""' : ""}>${renderInlineMarkdown(content)}</label>` : renderInlineMarkdown(content);
|
|
702
|
+
items.push(
|
|
703
|
+
`<li${task ? ` data-checked="${checked}"` : ""}>${label}${nested}</li>`
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
index -= 1;
|
|
707
|
+
const tag = ordered ? "ol" : "ul";
|
|
708
|
+
pushHtml(
|
|
709
|
+
`<${tag}${hasTasks && !ordered ? ' data-task-list="true"' : ""}>${items.join("")}</${tag}>`
|
|
710
|
+
);
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
paragraph.push(
|
|
714
|
+
/ {2,}$/.test(line) ? `${line.trimEnd()}${HARD_BREAK_TOKEN}` : line
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
flush();
|
|
718
|
+
return blocks;
|
|
719
|
+
}
|
|
720
|
+
function markdownToRichTextBlocks(markdown, options = {}) {
|
|
721
|
+
return parseBlocks(normalizeMarkdown(markdown, options).split("\n"));
|
|
722
|
+
}
|
|
723
|
+
function markdownToRichTextHtml(markdown, options = {}) {
|
|
724
|
+
return serializeBlocks(markdownToRichTextBlocks(markdown, options));
|
|
725
|
+
}
|
|
726
|
+
function createRichTextDocumentFromMarkdown(markdown, options = {}) {
|
|
727
|
+
const html = markdownToRichTextHtml(markdown, options);
|
|
728
|
+
return {
|
|
729
|
+
html,
|
|
730
|
+
plainText: richTextHtmlToPlainText(html),
|
|
731
|
+
schemaVersion: QUICK_BUILDER_RICH_TEXT_SCHEMA_VERSION
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
exports.createRichTextDocumentFromMarkdown = createRichTextDocumentFromMarkdown;
|
|
736
|
+
exports.markdownToRichTextBlocks = markdownToRichTextBlocks;
|
|
737
|
+
exports.markdownToRichTextHtml = markdownToRichTextHtml;
|
|
738
|
+
//# sourceMappingURL=markdown.js.map
|
|
739
|
+
//# sourceMappingURL=markdown.js.map
|