@tensor_1/react 2.17.0 → 2.19.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/README.md +131 -1
- package/dist/components/Comments.d.ts +18 -2
- package/dist/components/Comments.js +37 -12
- package/dist/components/EditorIcons.d.ts +39 -0
- package/dist/components/EditorIcons.js +51 -0
- package/dist/components/EmojiGlyph.d.ts +10 -0
- package/dist/components/EmojiGlyph.js +18 -0
- package/dist/components/EmojiPicker.d.ts +60 -0
- package/dist/components/EmojiPicker.js +277 -0
- package/dist/components/Markdown.d.ts +36 -0
- package/dist/components/Markdown.js +104 -0
- package/dist/components/ReactionBar.d.ts +57 -0
- package/dist/components/ReactionBar.js +81 -0
- package/dist/components/RelationshipGraph.d.ts +81 -3
- package/dist/components/RelationshipGraph.js +102 -59
- package/dist/components/RelationshipGraphLayered.d.ts +8 -0
- package/dist/components/RelationshipGraphLayered.js +420 -0
- package/dist/components/RelationshipGraphList.d.ts +16 -0
- package/dist/components/RelationshipGraphList.js +33 -0
- package/dist/components/RichTextEditor.d.ts +128 -0
- package/dist/components/RichTextEditor.js +954 -0
- package/dist/components/SaveStatus.d.ts +32 -0
- package/dist/components/SaveStatus.js +21 -0
- package/dist/components/Tabs.d.ts +10 -3
- package/dist/components/Tabs.js +5 -3
- package/dist/emoji-image-WQLh8ZQP.d.cts +128 -0
- package/dist/emoji-image.d.ts +25 -0
- package/dist/emoji-image.js +80 -0
- package/dist/emoji-model.d.ts +66 -0
- package/dist/emoji-model.js +108 -0
- package/dist/emoji.cjs +871 -0
- package/dist/emoji.d.cts +57 -0
- package/dist/emoji.d.ts +6 -0
- package/dist/emoji.js +18 -0
- package/dist/index.cjs +1503 -540
- package/dist/index.d.cts +245 -65
- package/dist/index.d.ts +3 -2
- package/dist/index.js +11 -2
- package/dist/markdown-model.d.ts +75 -0
- package/dist/markdown-model.js +438 -0
- package/dist/markdown.cjs +585 -0
- package/dist/markdown.d.cts +115 -0
- package/dist/markdown.d.ts +4 -0
- package/dist/markdown.js +9 -0
- package/dist/overlay-position-CEGSz6Z2.d.cts +59 -0
- package/dist/relationship-graph-model.d.ts +112 -1
- package/dist/relationship-graph-model.js +420 -1
- package/dist/rich-text/emoji-items.d.ts +14 -0
- package/dist/rich-text/emoji-items.js +7 -0
- package/dist/rich-text/pipeline.d.ts +91 -0
- package/dist/rich-text/pipeline.js +379 -0
- package/dist/rich-text/round-trip.d.ts +24 -0
- package/dist/rich-text/round-trip.js +11 -0
- package/dist/rich-text.cjs +2578 -0
- package/dist/rich-text.d.cts +148 -0
- package/dist/rich-text.d.ts +8 -0
- package/dist/rich-text.js +10 -0
- package/dist/url-policy.d.ts +9 -0
- package/dist/url-policy.js +11 -0
- package/package.json +82 -1
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
const ASCII_PUNCT = /[!-/:-@[-`{-~]/;
|
|
2
|
+
const WORD = /[\p{L}\p{N}]/u;
|
|
3
|
+
const NAMED_ENTITIES = {
|
|
4
|
+
amp: "&",
|
|
5
|
+
lt: "<",
|
|
6
|
+
gt: ">",
|
|
7
|
+
quot: '"',
|
|
8
|
+
apos: "'",
|
|
9
|
+
nbsp: "\xA0",
|
|
10
|
+
copy: "\xA9",
|
|
11
|
+
reg: "\xAE",
|
|
12
|
+
hellip: "\u2026",
|
|
13
|
+
mdash: "\u2014",
|
|
14
|
+
ndash: "\u2013"
|
|
15
|
+
};
|
|
16
|
+
const ENTITY_RE = /^&(?:#(\d{1,7})|#[xX]([\da-fA-F]{1,6})|([a-zA-Z][a-zA-Z\d]{1,31}));/;
|
|
17
|
+
const ENTITY_GLOBAL = /&(?:#\d{1,7}|#[xX][\da-fA-F]{1,6}|[a-zA-Z][a-zA-Z\d]{1,31});/g;
|
|
18
|
+
const BARE_URL_RE = /^https?:\/\/[^\s<>()]+/;
|
|
19
|
+
const BR_RE = /^<br\s*\/?>/i;
|
|
20
|
+
const AUTOLINK_RE = /^<((?:https?:|mailto:)[^\s<>]*)>/i;
|
|
21
|
+
const decodeEntity = (match) => {
|
|
22
|
+
const [, dec, hex, name] = match;
|
|
23
|
+
const code = dec ? Number(dec) : hex ? parseInt(hex, 16) : void 0;
|
|
24
|
+
if (code !== void 0) return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : "\uFFFD";
|
|
25
|
+
return name && Object.prototype.hasOwnProperty.call(NAMED_ENTITIES, name) ? NAMED_ENTITIES[name] : null;
|
|
26
|
+
};
|
|
27
|
+
const MAX_SCAN = 2e3;
|
|
28
|
+
const MAX_DEPTH = 12;
|
|
29
|
+
const findBracketEnd = (text, open) => {
|
|
30
|
+
let depth = 0;
|
|
31
|
+
const stop = Math.min(text.length, open + MAX_SCAN);
|
|
32
|
+
for (let i = open; i < stop; i += 1) {
|
|
33
|
+
const ch = text[i];
|
|
34
|
+
if (ch === "\\") {
|
|
35
|
+
i += 1;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (ch === "`") {
|
|
39
|
+
const close = text.indexOf("`", i + 1);
|
|
40
|
+
if (close > 0) {
|
|
41
|
+
i = close;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (ch === "[") depth += 1;
|
|
46
|
+
else if (ch === "]") {
|
|
47
|
+
depth -= 1;
|
|
48
|
+
if (depth === 0) return i;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return -1;
|
|
52
|
+
};
|
|
53
|
+
const readDestination = (text, open) => {
|
|
54
|
+
if (text[open] !== "(") return null;
|
|
55
|
+
let depth = 0;
|
|
56
|
+
let end = -1;
|
|
57
|
+
const stop = Math.min(text.length, open + MAX_SCAN);
|
|
58
|
+
for (let i = open; i < stop; i += 1) {
|
|
59
|
+
const ch = text[i];
|
|
60
|
+
if (ch === "\\") {
|
|
61
|
+
i += 1;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ch === "(") depth += 1;
|
|
65
|
+
else if (ch === ")") {
|
|
66
|
+
depth -= 1;
|
|
67
|
+
if (depth === 0) {
|
|
68
|
+
end = i;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (end < 0) return null;
|
|
74
|
+
const inner = text.slice(open + 1, end).trim();
|
|
75
|
+
const titled = /^(\S+)\s+(?:"([^"]*)"|'([^']*)')$/.exec(inner);
|
|
76
|
+
const rawUrl = titled ? titled[1] : inner;
|
|
77
|
+
const url = rawUrl.replace(/^<(.*)>$/, "$1").replace(/\\([!-/:-@[-`{-~])/g, "$1").replace(ENTITY_GLOBAL, (match) => decodeEntity(ENTITY_RE.exec(match)) ?? match);
|
|
78
|
+
const title = titled ? titled[2] ?? titled[3] : void 0;
|
|
79
|
+
return title === void 0 ? { url, end } : { url, title, end };
|
|
80
|
+
};
|
|
81
|
+
const backtickRun = (text, at) => {
|
|
82
|
+
let end = at;
|
|
83
|
+
while (text[end] === "`") end += 1;
|
|
84
|
+
return text.slice(at, end);
|
|
85
|
+
};
|
|
86
|
+
const findCloser = (text, from, delim, misses) => {
|
|
87
|
+
if (from >= (misses.get(delim) ?? Infinity)) return -1;
|
|
88
|
+
for (let i = from; i < text.length; i += 1) {
|
|
89
|
+
const ch = text[i];
|
|
90
|
+
if (ch === "\\") {
|
|
91
|
+
i += 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (ch === "`") {
|
|
95
|
+
const run = backtickRun(text, i);
|
|
96
|
+
const close = text.indexOf(run, i + run.length);
|
|
97
|
+
if (close > 0) {
|
|
98
|
+
i = close + run.length - 1;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (text.startsWith(delim, i) && i > from && !/\s/u.test(text[i - 1])) {
|
|
103
|
+
if (delim[0] === "_" && WORD.test(text[i + delim.length] ?? "")) continue;
|
|
104
|
+
if (delim.length === 1 && text[i + 1] === delim) {
|
|
105
|
+
i += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
return i;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
misses.set(delim, Math.min(from, misses.get(delim) ?? Infinity));
|
|
112
|
+
return -1;
|
|
113
|
+
};
|
|
114
|
+
const pushText = (out, value) => {
|
|
115
|
+
if (!value) return;
|
|
116
|
+
const last = out[out.length - 1];
|
|
117
|
+
if (last?.type === "text") last.value += value;
|
|
118
|
+
else out.push({ type: "text", value });
|
|
119
|
+
};
|
|
120
|
+
function parseInline(text, depth = 0) {
|
|
121
|
+
const out = [];
|
|
122
|
+
if (depth > MAX_DEPTH) {
|
|
123
|
+
pushText(out, text);
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
const misses = /* @__PURE__ */ new Map();
|
|
127
|
+
let i = 0;
|
|
128
|
+
while (i < text.length) {
|
|
129
|
+
const ch = text[i];
|
|
130
|
+
const rest = text.slice(i);
|
|
131
|
+
if (ch === "\\" && ASCII_PUNCT.test(text[i + 1] ?? "")) {
|
|
132
|
+
pushText(out, text[i + 1]);
|
|
133
|
+
i += 2;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (ch === "\n") {
|
|
137
|
+
out.push({ type: "br" });
|
|
138
|
+
i += 1;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (ch === "`") {
|
|
142
|
+
const run = backtickRun(text, i);
|
|
143
|
+
const close = text.indexOf(run, i + run.length);
|
|
144
|
+
if (close > 0 && text[close + run.length] !== "`") {
|
|
145
|
+
let value = text.slice(i + run.length, close).replace(/\n/g, " ");
|
|
146
|
+
if (/^ .* $/.test(value) && value.trim()) value = value.slice(1, -1);
|
|
147
|
+
out.push({ type: "code", value });
|
|
148
|
+
i = close + run.length;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
pushText(out, run);
|
|
152
|
+
i += run.length;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (ch === "!" && text[i + 1] === "[") {
|
|
156
|
+
const end = findBracketEnd(text, i + 1);
|
|
157
|
+
const dest = end > 0 ? readDestination(text, end + 1) : null;
|
|
158
|
+
if (dest) {
|
|
159
|
+
const alt = plainText(parseInline(text.slice(i + 2, end), depth + 1));
|
|
160
|
+
out.push(dest.title === void 0 ? { type: "image", src: dest.url, alt } : { type: "image", src: dest.url, alt, title: dest.title });
|
|
161
|
+
i = dest.end + 1;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (ch === "[") {
|
|
166
|
+
const end = findBracketEnd(text, i);
|
|
167
|
+
const dest = end > 0 ? readDestination(text, end + 1) : null;
|
|
168
|
+
if (dest) {
|
|
169
|
+
const children = parseInline(text.slice(i + 1, end), depth + 1);
|
|
170
|
+
out.push(dest.title === void 0 ? { type: "link", href: dest.url, children } : { type: "link", href: dest.url, title: dest.title, children });
|
|
171
|
+
i = dest.end + 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (ch === "<") {
|
|
176
|
+
const br = BR_RE.exec(rest);
|
|
177
|
+
if (br) {
|
|
178
|
+
out.push({ type: "br" });
|
|
179
|
+
i += br[0].length;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const auto = AUTOLINK_RE.exec(rest);
|
|
183
|
+
if (auto) {
|
|
184
|
+
out.push({ type: "link", href: auto[1], children: [{ type: "text", value: auto[1].replace(/^mailto:/i, "") }], bare: true });
|
|
185
|
+
i += auto[0].length;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (ch === "&") {
|
|
190
|
+
const entity = ENTITY_RE.exec(rest);
|
|
191
|
+
const decoded = entity ? decodeEntity(entity) : null;
|
|
192
|
+
if (entity && decoded !== null) {
|
|
193
|
+
pushText(out, decoded);
|
|
194
|
+
i += entity[0].length;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (ch === "~" && text[i + 1] === "~" && text[i + 2] && !/\s/u.test(text[i + 2])) {
|
|
199
|
+
const close = findCloser(text, i + 2, "~~", misses);
|
|
200
|
+
if (close > 0) {
|
|
201
|
+
out.push({ type: "del", children: parseInline(text.slice(i + 2, close), depth + 1) });
|
|
202
|
+
i = close + 2;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (ch === "*" || ch === "_") {
|
|
207
|
+
const leftOk = ch === "*" || !WORD.test(text[i - 1] ?? "");
|
|
208
|
+
const double = text[i + 1] === ch;
|
|
209
|
+
const delim = double ? ch + ch : ch;
|
|
210
|
+
const after = text[i + delim.length];
|
|
211
|
+
if (leftOk && after && !/\s/u.test(after)) {
|
|
212
|
+
const close = findCloser(text, i + delim.length, delim, misses);
|
|
213
|
+
if (close > 0) {
|
|
214
|
+
const children = parseInline(text.slice(i + delim.length, close), depth + 1);
|
|
215
|
+
out.push(double ? { type: "strong", children } : { type: "em", children });
|
|
216
|
+
i = close + delim.length;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const run = new RegExp(`^\\${ch}+`).exec(rest)[0];
|
|
221
|
+
pushText(out, run);
|
|
222
|
+
i += run.length;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (ch === "h" && !WORD.test(text[i - 1] ?? "")) {
|
|
226
|
+
const bare = BARE_URL_RE.exec(rest);
|
|
227
|
+
if (bare) {
|
|
228
|
+
const url = bare[0].replace(/[.,;:!?'"]+$/, "");
|
|
229
|
+
out.push({ type: "link", href: url, children: [{ type: "text", value: url }], bare: true });
|
|
230
|
+
i += url.length;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
pushText(out, ch);
|
|
235
|
+
i += 1;
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
function plainText(nodes) {
|
|
240
|
+
return nodes.map((n) => {
|
|
241
|
+
switch (n.type) {
|
|
242
|
+
case "text":
|
|
243
|
+
case "code":
|
|
244
|
+
return n.value;
|
|
245
|
+
case "br":
|
|
246
|
+
return " ";
|
|
247
|
+
case "image":
|
|
248
|
+
return n.alt;
|
|
249
|
+
default:
|
|
250
|
+
return plainText(n.children);
|
|
251
|
+
}
|
|
252
|
+
}).join("");
|
|
253
|
+
}
|
|
254
|
+
const FENCE_RE = /^(`{3,}|~{3,})\s*([^`\s]*)/;
|
|
255
|
+
const HEADING_RE = /^(#{1,6})\s+(.*?)(?:\s+#+)?$/;
|
|
256
|
+
const RULE_RE = /^(?:(?:\*\s*){3,}|(?:-\s*){3,}|(?:_\s*){3,})$/;
|
|
257
|
+
const BULLET_RE = /^(\s*)([-*+])\s+(.*)$/;
|
|
258
|
+
const ORDERED_RE = /^(\s*)(\d{1,9})[.)]\s+(.*)$/;
|
|
259
|
+
const TASK_RE = /^\[([ xX])\]\s+(.*)$/;
|
|
260
|
+
const DELIMITER_ROW_RE = /^\s*\|?\s*:?-+:?\s*(?:\|\s*:?-+:?\s*)*\|?\s*$/;
|
|
261
|
+
const indentOf = (s) => s.replace(/\t/g, " ").length;
|
|
262
|
+
function splitTableRow(line) {
|
|
263
|
+
let row = line.trim();
|
|
264
|
+
if (row.startsWith("|")) row = row.slice(1);
|
|
265
|
+
if (row.endsWith("|") && !row.endsWith("\\|")) row = row.slice(0, -1);
|
|
266
|
+
const cells = [];
|
|
267
|
+
let cell = "";
|
|
268
|
+
let inCode = false;
|
|
269
|
+
for (let i = 0; i < row.length; i += 1) {
|
|
270
|
+
const ch = row[i];
|
|
271
|
+
if (ch === "\\" && row[i + 1] === "|") {
|
|
272
|
+
cell += "|";
|
|
273
|
+
i += 1;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (ch === "`") inCode = !inCode;
|
|
277
|
+
if (ch === "|" && !inCode) {
|
|
278
|
+
cells.push(cell.trim());
|
|
279
|
+
cell = "";
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
cell += ch;
|
|
283
|
+
}
|
|
284
|
+
cells.push(cell.trim());
|
|
285
|
+
return cells;
|
|
286
|
+
}
|
|
287
|
+
const alignOf = (cell) => {
|
|
288
|
+
const c = cell.trim();
|
|
289
|
+
const left = c.startsWith(":");
|
|
290
|
+
const right = c.endsWith(":");
|
|
291
|
+
return left && right ? "center" : right ? "right" : left ? "left" : null;
|
|
292
|
+
};
|
|
293
|
+
const matchListLine = (line) => {
|
|
294
|
+
const bullet = BULLET_RE.exec(line);
|
|
295
|
+
if (bullet && !RULE_RE.test(line.trim())) return { indent: indentOf(bullet[1]), ordered: false, number: 1, text: bullet[3] };
|
|
296
|
+
const ordered = ORDERED_RE.exec(line);
|
|
297
|
+
if (ordered) return { indent: indentOf(ordered[1]), ordered: true, number: Number(ordered[2]), text: ordered[3] };
|
|
298
|
+
return null;
|
|
299
|
+
};
|
|
300
|
+
const toItem = (text) => {
|
|
301
|
+
const task = TASK_RE.exec(text);
|
|
302
|
+
return task ? { checked: task[1] !== " ", children: parseInline(task[2]), lists: [] } : { checked: null, children: parseInline(text), lists: [] };
|
|
303
|
+
};
|
|
304
|
+
const buildList = (lines) => {
|
|
305
|
+
const lists = [];
|
|
306
|
+
const stack = [];
|
|
307
|
+
for (const line of lines) {
|
|
308
|
+
while (stack.length && line.indent < stack[stack.length - 1].indent) stack.pop();
|
|
309
|
+
let top = stack[stack.length - 1];
|
|
310
|
+
if (top && line.indent > top.indent) {
|
|
311
|
+
const parentItem = top.list.items[top.list.items.length - 1];
|
|
312
|
+
const nested = { type: "list", ordered: line.ordered, start: line.number, items: [] };
|
|
313
|
+
parentItem.lists.push(nested);
|
|
314
|
+
stack.push({ list: nested, indent: line.indent });
|
|
315
|
+
top = stack[stack.length - 1];
|
|
316
|
+
} else if (!top || top.list.ordered !== line.ordered) {
|
|
317
|
+
const list = { type: "list", ordered: line.ordered, start: line.number, items: [] };
|
|
318
|
+
if (stack.length <= 1) {
|
|
319
|
+
lists.push(list);
|
|
320
|
+
stack.length = 0;
|
|
321
|
+
} else {
|
|
322
|
+
stack.pop();
|
|
323
|
+
const parent = stack[stack.length - 1].list;
|
|
324
|
+
parent.items[parent.items.length - 1].lists.push(list);
|
|
325
|
+
}
|
|
326
|
+
stack.push({ list, indent: line.indent });
|
|
327
|
+
top = stack[stack.length - 1];
|
|
328
|
+
}
|
|
329
|
+
top.list.items.push(toItem(line.text));
|
|
330
|
+
}
|
|
331
|
+
return lists;
|
|
332
|
+
};
|
|
333
|
+
function parseMarkdown(source) {
|
|
334
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
335
|
+
const blocks = [];
|
|
336
|
+
let paragraph = [];
|
|
337
|
+
let i = 0;
|
|
338
|
+
const flush = () => {
|
|
339
|
+
if (paragraph.length) {
|
|
340
|
+
blocks.push({ type: "paragraph", children: parseInline(paragraph.join("\n")) });
|
|
341
|
+
paragraph = [];
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
while (i < lines.length) {
|
|
345
|
+
const line = lines[i];
|
|
346
|
+
const trimmed = line.trim();
|
|
347
|
+
if (trimmed === "") {
|
|
348
|
+
flush();
|
|
349
|
+
i += 1;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const fence = FENCE_RE.exec(trimmed);
|
|
353
|
+
if (fence) {
|
|
354
|
+
flush();
|
|
355
|
+
const marker = fence[1];
|
|
356
|
+
const body = [];
|
|
357
|
+
i += 1;
|
|
358
|
+
while (i < lines.length && !lines[i].trim().startsWith(marker)) {
|
|
359
|
+
body.push(lines[i]);
|
|
360
|
+
i += 1;
|
|
361
|
+
}
|
|
362
|
+
i += 1;
|
|
363
|
+
blocks.push({ type: "code", lang: fence[2] ?? "", value: body.join("\n") });
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
const heading = HEADING_RE.exec(trimmed);
|
|
367
|
+
if (heading) {
|
|
368
|
+
flush();
|
|
369
|
+
blocks.push({ type: "heading", level: heading[1].length, children: parseInline(heading[2]) });
|
|
370
|
+
i += 1;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (RULE_RE.test(trimmed)) {
|
|
374
|
+
flush();
|
|
375
|
+
blocks.push({ type: "rule" });
|
|
376
|
+
i += 1;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (trimmed.startsWith(">")) {
|
|
380
|
+
flush();
|
|
381
|
+
const quote = [];
|
|
382
|
+
while (i < lines.length && lines[i].trim().startsWith(">")) {
|
|
383
|
+
quote.push(lines[i].trim().replace(/^>\s?/, ""));
|
|
384
|
+
i += 1;
|
|
385
|
+
}
|
|
386
|
+
blocks.push({ type: "quote", children: parseInline(quote.join(" ")) });
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (trimmed.includes("|") && i + 1 < lines.length && DELIMITER_ROW_RE.test(lines[i + 1]) && lines[i + 1].includes("-")) {
|
|
390
|
+
const head = splitTableRow(line);
|
|
391
|
+
const delimiters = splitTableRow(lines[i + 1]);
|
|
392
|
+
if (delimiters.length === head.length) {
|
|
393
|
+
flush();
|
|
394
|
+
const rows = [];
|
|
395
|
+
i += 2;
|
|
396
|
+
while (i < lines.length && lines[i].trim() !== "" && lines[i].includes("|")) {
|
|
397
|
+
const cells = splitTableRow(lines[i]);
|
|
398
|
+
rows.push(head.map((_, c) => parseInline(cells[c] ?? "")));
|
|
399
|
+
i += 1;
|
|
400
|
+
}
|
|
401
|
+
blocks.push({ type: "table", align: delimiters.map(alignOf), head: head.map((c) => parseInline(c)), rows });
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const first = matchListLine(line);
|
|
406
|
+
if (first) {
|
|
407
|
+
flush();
|
|
408
|
+
const listLines = [];
|
|
409
|
+
while (i < lines.length) {
|
|
410
|
+
const current = lines[i];
|
|
411
|
+
const item = matchListLine(current);
|
|
412
|
+
if (item) {
|
|
413
|
+
if (listLines.length && item.indent <= listLines[0].indent && item.ordered !== listLines[0].ordered) break;
|
|
414
|
+
listLines.push(item);
|
|
415
|
+
} else if (current.trim() !== "" && indentOf(current) > listLines[0].indent && listLines.length) {
|
|
416
|
+
listLines[listLines.length - 1].text += `
|
|
417
|
+
${current.trim()}`;
|
|
418
|
+
} else {
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
i += 1;
|
|
422
|
+
}
|
|
423
|
+
const base = Math.min(...listLines.map((l) => l.indent));
|
|
424
|
+
blocks.push(...buildList(listLines.map((l) => ({ ...l, indent: l.indent - base }))));
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
paragraph.push(trimmed);
|
|
428
|
+
i += 1;
|
|
429
|
+
}
|
|
430
|
+
flush();
|
|
431
|
+
return blocks;
|
|
432
|
+
}
|
|
433
|
+
export {
|
|
434
|
+
parseInline,
|
|
435
|
+
parseMarkdown,
|
|
436
|
+
plainText,
|
|
437
|
+
splitTableRow
|
|
438
|
+
};
|