@meandr/chat-sdk 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -16
- package/dist/api.d.ts +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +547 -359
- package/dist/index.js.map +3 -3
- package/dist/markdown.js +90 -90
- package/dist/markdown.js.map +1 -1
- package/dist/meandr-chat.js +9 -9
- package/dist/meandr-chat.js.map +3 -3
- package/dist/types.d.ts +47 -0
- package/package.json +1 -1
package/dist/markdown.js
CHANGED
|
@@ -31,7 +31,7 @@ var CODE = 4;
|
|
|
31
31
|
var NOTE = 5;
|
|
32
32
|
function parseMarkdown(text) {
|
|
33
33
|
const lines = String(text == null ? "" : text).replace(/\r\n?/g, "\n").split("\n").map(detab);
|
|
34
|
-
return blockTree(parseBlocks(lines, 0).
|
|
34
|
+
return blockTree(parseBlocks(lines, 0).va, false);
|
|
35
35
|
}
|
|
36
36
|
function renderMarkdown(text, doc = document) {
|
|
37
37
|
const frag = doc.createDocumentFragment();
|
|
@@ -55,12 +55,12 @@ function parseBlocks(lines, depth) {
|
|
|
55
55
|
let f, h, li, align;
|
|
56
56
|
if (f = fenceOpen(line)) {
|
|
57
57
|
const code = [];
|
|
58
|
-
for (i++; i < n && !fenceClose(lines[i], f); i++) code.push(dedent(lines[i], f.
|
|
58
|
+
for (i++; i < n && !fenceClose(lines[i], f); i++) code.push(dedent(lines[i], f.nb));
|
|
59
59
|
i++;
|
|
60
|
-
const lang = f.
|
|
61
|
-
out.push({ t: "pre", s: code.join("\n"),
|
|
60
|
+
const lang = f.ob.split(/\s/)[0];
|
|
61
|
+
out.push({ t: "pre", s: code.join("\n"), Ya: LANG.test(lang) ? lang : "" });
|
|
62
62
|
} else if (h = heading(line)) {
|
|
63
|
-
out.push({ t: "h" + h
|
|
63
|
+
out.push({ t: "h" + h.pb, s: h.fa });
|
|
64
64
|
i++;
|
|
65
65
|
} else if (isHr(line)) {
|
|
66
66
|
out.push({ t: "hr", s: "" });
|
|
@@ -76,23 +76,23 @@ function parseBlocks(lines, depth) {
|
|
|
76
76
|
fs = fenceStep(fs, l);
|
|
77
77
|
i++;
|
|
78
78
|
}
|
|
79
|
-
out.push({ t: "blockquote", s: "",
|
|
79
|
+
out.push({ t: "blockquote", s: "", qb: parseBlocks(inner, depth + 1).va });
|
|
80
80
|
} else if (nest && (li = listItem(line))) {
|
|
81
81
|
const first = li, items = [];
|
|
82
82
|
let cur = li, lz = false;
|
|
83
83
|
for (; ; ) {
|
|
84
|
-
const body = [cur.
|
|
85
|
-
let fs = fenceStep(null, cur.
|
|
84
|
+
const body = [cur.Za];
|
|
85
|
+
let fs = fenceStep(null, cur.Za), blank = -1;
|
|
86
86
|
for (i++; i < n; i++) {
|
|
87
87
|
const l = lines[i];
|
|
88
88
|
if (isBlank(l)) {
|
|
89
89
|
if (blank < 0) blank = i;
|
|
90
90
|
continue;
|
|
91
91
|
}
|
|
92
|
-
if (indentOf(l) >= cur.
|
|
92
|
+
if (indentOf(l) >= cur._a) {
|
|
93
93
|
for (; blank >= 0 && blank < i; blank++) body.push("");
|
|
94
94
|
blank = -1;
|
|
95
|
-
const d = dedent(l, cur.
|
|
95
|
+
const d = dedent(l, cur._a);
|
|
96
96
|
body.push(d);
|
|
97
97
|
fs = fenceStep(fs, d);
|
|
98
98
|
continue;
|
|
@@ -102,28 +102,28 @@ function parseBlocks(lines, depth) {
|
|
|
102
102
|
}
|
|
103
103
|
if (blank >= 0) i = blank;
|
|
104
104
|
const r = parseBlocks(body, depth + 1);
|
|
105
|
-
items.push(r.
|
|
106
|
-
if (r.
|
|
105
|
+
items.push(r.va);
|
|
106
|
+
if (r.rb) lz = true;
|
|
107
107
|
let j = i;
|
|
108
108
|
while (j < n && isBlank(lines[j])) j++;
|
|
109
109
|
const next = j < n ? listItem(lines[j]) : null;
|
|
110
|
-
if (!next || next.
|
|
110
|
+
if (!next || next.ga !== first.ga || next.$a !== first.$a) break;
|
|
111
111
|
if (j > i) lz = true;
|
|
112
112
|
i = j;
|
|
113
113
|
cur = next;
|
|
114
114
|
}
|
|
115
|
-
out.push({ t: first.
|
|
115
|
+
out.push({ t: first.ga ? "ol" : "ul", s: "", W: first.W, sb: !lz, tb: items });
|
|
116
116
|
} else if (align = tableAt(lines, i)) {
|
|
117
117
|
const rows = [cells(line, MAX_COLS)];
|
|
118
118
|
for (i += 2; i < n && !isBlank(lines[i]) && !startsBlock(lines[i], nest); i++) rows.push(cells(lines[i], MAX_COLS));
|
|
119
|
-
out.push({ t: "table", s: "",
|
|
119
|
+
out.push({ t: "table", s: "", ub: rows, vb: align.slice(0, MAX_COLS) });
|
|
120
120
|
} else {
|
|
121
121
|
const buf = [line.trim()];
|
|
122
122
|
for (i++; i < n && !isBlank(lines[i]) && !startsBlock(lines[i], nest) && !tableAt(lines, i); i++) buf.push(lines[i].trim());
|
|
123
123
|
out.push({ t: "p", s: buf.join("\n") });
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
return {
|
|
126
|
+
return { va: out, rb: loose };
|
|
127
127
|
}
|
|
128
128
|
function isBlank(l) {
|
|
129
129
|
if (l === void 0) return true;
|
|
@@ -166,13 +166,13 @@ function fenceOpen(l) {
|
|
|
166
166
|
let e = ind;
|
|
167
167
|
while (l.charAt(e) === ch) e++;
|
|
168
168
|
const info = l.slice(e).trim();
|
|
169
|
-
return e - ind >= 3 && !(ch === "`" && info.indexOf("`") >= 0) ? { ch,
|
|
169
|
+
return e - ind >= 3 && !(ch === "`" && info.indexOf("`") >= 0) ? { ch, wb: e - ind, nb: ind, ob: info } : null;
|
|
170
170
|
}
|
|
171
171
|
function fenceClose(l, f) {
|
|
172
172
|
const s = lead(l);
|
|
173
173
|
let e = s;
|
|
174
174
|
while (l.charAt(e) === f.ch) e++;
|
|
175
|
-
return e - s >= f.
|
|
175
|
+
return e - s >= f.wb && isBlank(l.slice(e));
|
|
176
176
|
}
|
|
177
177
|
function fenceStep(f, l) {
|
|
178
178
|
return f ? fenceClose(l, f) ? null : f : fenceOpen(l);
|
|
@@ -186,7 +186,7 @@ function heading(l) {
|
|
|
186
186
|
let t = l.slice(e).trim(), k = t.length;
|
|
187
187
|
while (k > 0 && t.charAt(k - 1) === "#") k--;
|
|
188
188
|
if (k === 0 || t.charAt(k - 1) === " " || t.charAt(k - 1) === " ") t = t.slice(0, k).trim();
|
|
189
|
-
return {
|
|
189
|
+
return { pb: level, fa: t };
|
|
190
190
|
}
|
|
191
191
|
function isHr(l) {
|
|
192
192
|
const s = lead(l), ch = l.charAt(s);
|
|
@@ -223,14 +223,14 @@ function listItem(l) {
|
|
|
223
223
|
while (l.charAt(e) === " " || l.charAt(e) === " ") e++;
|
|
224
224
|
if (e === p && e < l.length) return null;
|
|
225
225
|
const empty = e >= l.length, wide = e - p > 4;
|
|
226
|
-
return {
|
|
226
|
+
return { ga: ordered, $a: mark, W: start, _a: empty || wide ? p + 1 : e, Za: empty ? "" : l.slice(wide ? p + 1 : e), xb: empty };
|
|
227
227
|
}
|
|
228
228
|
function startsBlock(l, nest) {
|
|
229
229
|
if (fenceOpen(l) || heading(l) || isHr(l)) return true;
|
|
230
230
|
if (!nest) return false;
|
|
231
231
|
if (quoteStrip(l) !== null) return true;
|
|
232
232
|
const m = listItem(l);
|
|
233
|
-
return m !== null && !m.
|
|
233
|
+
return m !== null && !m.xb && (!m.ga || m.W === 1);
|
|
234
234
|
}
|
|
235
235
|
function cells(l, max) {
|
|
236
236
|
const s = l.trim(), out = [];
|
|
@@ -268,12 +268,12 @@ function tableAt(lines, i) {
|
|
|
268
268
|
return align && lines[i].indexOf("|") >= 0 && cells(lines[i], Infinity).length === align.length ? align : null;
|
|
269
269
|
}
|
|
270
270
|
function mk(k, s) {
|
|
271
|
-
return { k, s,
|
|
271
|
+
return { k, s, G: "", y: "", P: null, d: null, c: null };
|
|
272
272
|
}
|
|
273
273
|
function anchor(href, kid) {
|
|
274
274
|
const a = mk(EL, "a");
|
|
275
|
-
a.
|
|
276
|
-
a.
|
|
275
|
+
a.G = href;
|
|
276
|
+
a.P = kid;
|
|
277
277
|
return a;
|
|
278
278
|
}
|
|
279
279
|
function isAsciiPunct(ch) {
|
|
@@ -302,7 +302,7 @@ function parseInline(src) {
|
|
|
302
302
|
const head = mk(EL, ""), len = src.length;
|
|
303
303
|
let tail = head, dtop = null, btop = null, ids = 0, i = 0, rp = 0, url = -1;
|
|
304
304
|
const push = (x) => {
|
|
305
|
-
tail.
|
|
305
|
+
tail.c = x;
|
|
306
306
|
x.d = tail;
|
|
307
307
|
tail = x;
|
|
308
308
|
};
|
|
@@ -311,14 +311,14 @@ function parseInline(src) {
|
|
|
311
311
|
else push(mk(TEXT, s));
|
|
312
312
|
};
|
|
313
313
|
const unlink = (x) => {
|
|
314
|
-
x.d.
|
|
315
|
-
if (x.
|
|
314
|
+
x.d.c = x.c;
|
|
315
|
+
if (x.c) x.c.d = x.d;
|
|
316
316
|
else tail = x.d;
|
|
317
317
|
};
|
|
318
318
|
const drop = (d) => {
|
|
319
319
|
d.f.s = d.f.s.slice(0, d.n);
|
|
320
|
-
if (d.d) d.d.
|
|
321
|
-
if (d.
|
|
320
|
+
if (d.d) d.d.c = d.c;
|
|
321
|
+
if (d.c) d.c.d = d.d;
|
|
322
322
|
else dtop = d.d;
|
|
323
323
|
};
|
|
324
324
|
const emphasis = (bottom) => {
|
|
@@ -327,31 +327,31 @@ function parseInline(src) {
|
|
|
327
327
|
if (!c || c.id <= bid) return;
|
|
328
328
|
while (c.d && c.d.id > bid) c = c.d;
|
|
329
329
|
while (c) {
|
|
330
|
-
if (!c.
|
|
331
|
-
c = c.
|
|
330
|
+
if (!c.ab) {
|
|
331
|
+
c = c.c;
|
|
332
332
|
continue;
|
|
333
333
|
}
|
|
334
|
-
const key = c.ch + (c.
|
|
334
|
+
const key = c.ch + (c.ha ? "1" : "0") + c.X % 3;
|
|
335
335
|
const lim = Math.max(bid, key in floor ? floor[key] : -1);
|
|
336
336
|
let o = c.d;
|
|
337
|
-
while (o && o.id > lim && !(o.ch === c.ch && o.
|
|
337
|
+
while (o && o.id > lim && !(o.ch === c.ch && o.ha && pairs(o, c))) o = o.d;
|
|
338
338
|
if (o && o.id > lim) {
|
|
339
339
|
const use = c.ch === "~" || c.n > 1 && o.n > 1 ? 2 : 1;
|
|
340
340
|
o.n -= use;
|
|
341
341
|
c.n -= use;
|
|
342
342
|
const el = mk(EL, c.ch === "~" ? "del" : use === 2 ? "strong" : "em");
|
|
343
|
-
if (o.f.
|
|
344
|
-
const first = o.f.
|
|
343
|
+
if (o.f.c !== c.f) {
|
|
344
|
+
const first = o.f.c, last = c.f.d;
|
|
345
345
|
first.d = null;
|
|
346
|
-
last.
|
|
347
|
-
el.
|
|
346
|
+
last.c = null;
|
|
347
|
+
el.P = first;
|
|
348
348
|
}
|
|
349
|
-
o.f.
|
|
349
|
+
o.f.c = el;
|
|
350
350
|
el.d = o.f;
|
|
351
|
-
el.
|
|
351
|
+
el.c = c.f;
|
|
352
352
|
c.f.d = el;
|
|
353
|
-
for (let d = o.
|
|
354
|
-
o.
|
|
353
|
+
for (let d = o.c; d && d !== c; d = d.c) d.f.s = d.f.s.slice(0, d.n);
|
|
354
|
+
o.c = c;
|
|
355
355
|
c.d = o;
|
|
356
356
|
if (!o.n) {
|
|
357
357
|
unlink(o.f);
|
|
@@ -359,14 +359,14 @@ function parseInline(src) {
|
|
|
359
359
|
}
|
|
360
360
|
if (!c.n) {
|
|
361
361
|
unlink(c.f);
|
|
362
|
-
const nx = c.
|
|
362
|
+
const nx = c.c;
|
|
363
363
|
drop(c);
|
|
364
364
|
c = nx;
|
|
365
365
|
}
|
|
366
366
|
} else {
|
|
367
367
|
floor[key] = c.d ? c.d.id : -1;
|
|
368
|
-
const nx = c.
|
|
369
|
-
if (!c.
|
|
368
|
+
const nx = c.c;
|
|
369
|
+
if (!c.ha) drop(c);
|
|
370
370
|
c = nx;
|
|
371
371
|
}
|
|
372
372
|
}
|
|
@@ -435,45 +435,45 @@ function parseInline(src) {
|
|
|
435
435
|
const x = mk(DELIM, src.slice(i, e));
|
|
436
436
|
push(x);
|
|
437
437
|
if ((open || close) && (c !== 126 || e - i === 2)) {
|
|
438
|
-
const d = { f: x, ch: src.charAt(i), n: e - i,
|
|
439
|
-
if (dtop) dtop.
|
|
438
|
+
const d = { f: x, ch: src.charAt(i), n: e - i, X: e - i, ha: open, ab: close, id: ids++, d: dtop, c: null };
|
|
439
|
+
if (dtop) dtop.c = d;
|
|
440
440
|
dtop = d;
|
|
441
441
|
}
|
|
442
442
|
i = e;
|
|
443
443
|
} else if (c === 91 || c === 33 && src.charCodeAt(i + 1) === 91) {
|
|
444
444
|
const img = c === 33, x = mk(DELIM, img ? "![" : "[");
|
|
445
445
|
push(x);
|
|
446
|
-
btop = { f: x,
|
|
446
|
+
btop = { f: x, Y: img, wa: true, H: false, yb: dtop, d: btop };
|
|
447
447
|
i += img ? 2 : 1;
|
|
448
448
|
} else if (c === 93) {
|
|
449
|
-
const b = btop, L = b && b.
|
|
449
|
+
const b = btop, L = b && b.wa ? linkTail(src, i + 1) : null;
|
|
450
450
|
if (b) btop = b.d;
|
|
451
451
|
if (!b || !L) {
|
|
452
|
-
if (b && b.
|
|
452
|
+
if (b && b.H && btop) btop.H = true;
|
|
453
453
|
text("]");
|
|
454
454
|
i++;
|
|
455
455
|
continue;
|
|
456
456
|
}
|
|
457
|
-
emphasis(b.
|
|
458
|
-
const kids = b.f.
|
|
459
|
-
if (b.
|
|
460
|
-
let label = !b.
|
|
457
|
+
emphasis(b.yb);
|
|
458
|
+
const kids = b.f.c, href = safeHref(L.y);
|
|
459
|
+
if (b.Y || href) {
|
|
460
|
+
let label = !b.Y && kids ? kids : mk(TEXT, b.Y && !(href && b.H) ? plain(kids) : "");
|
|
461
461
|
if (href) tidy(label);
|
|
462
|
-
if (!plain(label)) label = mk(TEXT, href ? shown(href) : L.
|
|
462
|
+
if (!plain(label)) label = mk(TEXT, href ? shown(href) : L.y);
|
|
463
463
|
label.d = null;
|
|
464
|
-
b.f.
|
|
464
|
+
b.f.c = null;
|
|
465
465
|
tail = b.f;
|
|
466
466
|
if (href) {
|
|
467
467
|
const a = anchor(href, label);
|
|
468
468
|
let p = b.f.d;
|
|
469
|
-
a.
|
|
470
|
-
if (a.
|
|
471
|
-
const n = mk(NOTE, "[" + a.
|
|
472
|
-
p.
|
|
469
|
+
a.y = note(plain(label), href);
|
|
470
|
+
if (a.y) {
|
|
471
|
+
const n = mk(NOTE, "[" + a.y + "] ");
|
|
472
|
+
p.c = n;
|
|
473
473
|
n.d = p;
|
|
474
474
|
p = n;
|
|
475
475
|
}
|
|
476
|
-
p.
|
|
476
|
+
p.c = a;
|
|
477
477
|
a.d = p;
|
|
478
478
|
tail = a;
|
|
479
479
|
} else {
|
|
@@ -481,9 +481,9 @@ function parseInline(src) {
|
|
|
481
481
|
b.f.s = label.s;
|
|
482
482
|
}
|
|
483
483
|
} else unlink(b.f);
|
|
484
|
-
if (!b.
|
|
485
|
-
if (btop && (b.
|
|
486
|
-
i = L.
|
|
484
|
+
if (!b.Y) for (let x = btop; x && x.wa; x = x.d) x.wa = false;
|
|
485
|
+
if (btop && (b.Y || href || b.H)) btop.H = true;
|
|
486
|
+
i = L.M;
|
|
487
487
|
} else if (c === 60) {
|
|
488
488
|
const al = autolink(src, i);
|
|
489
489
|
if (!al) {
|
|
@@ -491,11 +491,11 @@ function parseInline(src) {
|
|
|
491
491
|
i++;
|
|
492
492
|
continue;
|
|
493
493
|
}
|
|
494
|
-
if (al.
|
|
495
|
-
push(anchor(al.
|
|
496
|
-
if (btop) btop.
|
|
497
|
-
} else text(al.
|
|
498
|
-
i = al.
|
|
494
|
+
if (al.G) {
|
|
495
|
+
push(anchor(al.G, mk(TEXT, shown(al.G))));
|
|
496
|
+
if (btop) btop.H = true;
|
|
497
|
+
} else text(al.fa);
|
|
498
|
+
i = al.M;
|
|
499
499
|
} else if (c === 38) {
|
|
500
500
|
const en = entity(src, i);
|
|
501
501
|
if (en) {
|
|
@@ -513,7 +513,7 @@ function parseInline(src) {
|
|
|
513
513
|
const u = src.slice(i, url), href = safeHref(u);
|
|
514
514
|
if (href) {
|
|
515
515
|
push(anchor(href, mk(TEXT, shown(href))));
|
|
516
|
-
if (btop) btop.
|
|
516
|
+
if (btop) btop.H = true;
|
|
517
517
|
} else text(u);
|
|
518
518
|
i = url;
|
|
519
519
|
} else {
|
|
@@ -524,10 +524,10 @@ function parseInline(src) {
|
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
emphasis(null);
|
|
527
|
-
return head.
|
|
527
|
+
return head.c;
|
|
528
528
|
}
|
|
529
529
|
function pairs(o, c) {
|
|
530
|
-
return c.ch === "~" || !((o.
|
|
530
|
+
return c.ch === "~" || !((o.ab || c.ha) && (o.X + c.X) % 3 === 0 && (o.X % 3 !== 0 || c.X % 3 !== 0));
|
|
531
531
|
}
|
|
532
532
|
function plain(n) {
|
|
533
533
|
let s = "";
|
|
@@ -539,12 +539,12 @@ function plain(n) {
|
|
|
539
539
|
continue;
|
|
540
540
|
}
|
|
541
541
|
if (n.k === EL) {
|
|
542
|
-
resume.push(n.
|
|
543
|
-
n = n.
|
|
542
|
+
resume.push(n.c);
|
|
543
|
+
n = n.P;
|
|
544
544
|
continue;
|
|
545
545
|
}
|
|
546
546
|
if (n.k !== NOTE) s += n.k === BR ? " " : n.s;
|
|
547
|
-
n = n.
|
|
547
|
+
n = n.c;
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
function skipWs(s, p, lim) {
|
|
@@ -597,7 +597,7 @@ function linkTail(s, p) {
|
|
|
597
597
|
p = skipWs(s, p + 1, lim);
|
|
598
598
|
}
|
|
599
599
|
if (s.charAt(p) !== ")") return null;
|
|
600
|
-
return {
|
|
600
|
+
return { y: decode(dest), M: p + 1 };
|
|
601
601
|
}
|
|
602
602
|
function autolink(s, p) {
|
|
603
603
|
const lim = Math.min(s.length, p + 2048);
|
|
@@ -609,8 +609,8 @@ function autolink(s, p) {
|
|
|
609
609
|
}
|
|
610
610
|
if (s.charAt(q) !== ">" || q === p + 1) return null;
|
|
611
611
|
const t = s.slice(p + 1, q);
|
|
612
|
-
if (/^[A-Za-z][A-Za-z0-9+.-]{1,31}:/.test(t)) return {
|
|
613
|
-
if (/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/.test(t)) return {
|
|
612
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]{1,31}:/.test(t)) return { fa: t, G: safeHref(t), M: q + 1 };
|
|
613
|
+
if (/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/.test(t)) return { fa: t, G: safeHref("mailto:" + t), M: q + 1 };
|
|
614
614
|
return null;
|
|
615
615
|
}
|
|
616
616
|
function bareUrl(s, p, inBracket) {
|
|
@@ -790,12 +790,12 @@ function eachText(n, fn) {
|
|
|
790
790
|
continue;
|
|
791
791
|
}
|
|
792
792
|
if (n.k === EL) {
|
|
793
|
-
resume.push(n.
|
|
794
|
-
n = n.
|
|
793
|
+
resume.push(n.c);
|
|
794
|
+
n = n.P;
|
|
795
795
|
continue;
|
|
796
796
|
}
|
|
797
797
|
if (n.k !== NOTE && !fn(n)) return;
|
|
798
|
-
n = n.
|
|
798
|
+
n = n.c;
|
|
799
799
|
}
|
|
800
800
|
}
|
|
801
801
|
function unscheme(s) {
|
|
@@ -813,21 +813,21 @@ function blockTree(bs, tight) {
|
|
|
813
813
|
else out.push({ tag: "p", children: inlineTree(parseInline(b.s), [], 0, false) });
|
|
814
814
|
break;
|
|
815
815
|
case "pre":
|
|
816
|
-
out.push(b.
|
|
816
|
+
out.push(b.Ya ? { tag: "pre", language: b.Ya, children: [clean(b.s)] } : { tag: "pre", children: [clean(b.s)] });
|
|
817
817
|
break;
|
|
818
818
|
case "blockquote":
|
|
819
|
-
out.push({ tag: "blockquote", children: blockTree(b.
|
|
819
|
+
out.push({ tag: "blockquote", children: blockTree(b.qb || [], false) });
|
|
820
820
|
break;
|
|
821
821
|
case "ul":
|
|
822
822
|
case "ol": {
|
|
823
|
-
const items = (b.
|
|
823
|
+
const items = (b.tb || []).map((item) => ({ tag: "li", children: blockTree(item, !!b.sb) }));
|
|
824
824
|
const list = { tag: b.t, children: items };
|
|
825
|
-
if (b.t === "ol" && b.
|
|
825
|
+
if (b.t === "ol" && b.W !== 1) list.start = b.W;
|
|
826
826
|
out.push(list);
|
|
827
827
|
break;
|
|
828
828
|
}
|
|
829
829
|
case "table":
|
|
830
|
-
out.push(tableTree(b.
|
|
830
|
+
out.push(tableTree(b.ub || [], b.vb || []));
|
|
831
831
|
break;
|
|
832
832
|
case "hr":
|
|
833
833
|
out.push({ tag: "hr" });
|
|
@@ -865,24 +865,24 @@ function tableTree(rows, align) {
|
|
|
865
865
|
}
|
|
866
866
|
function inlineTree(n, out, depth, inA) {
|
|
867
867
|
let run = "";
|
|
868
|
-
for (; n; n = n.
|
|
868
|
+
for (; n; n = n.c) {
|
|
869
869
|
if (n.k === TEXT || n.k === DELIM) run += n.s;
|
|
870
870
|
else if (n.k === NOTE) {
|
|
871
871
|
if (inA || depth >= MAX_INLINE) continue;
|
|
872
872
|
pushText(out, run);
|
|
873
873
|
pushText(out, n.s);
|
|
874
874
|
run = "";
|
|
875
|
-
} else if (n.k === EL && (n.s === "a" && inA || depth >= MAX_INLINE)) run += plain(n.
|
|
875
|
+
} else if (n.k === EL && (n.s === "a" && inA || depth >= MAX_INLINE)) run += plain(n.P);
|
|
876
876
|
else {
|
|
877
877
|
pushText(out, run);
|
|
878
878
|
run = "";
|
|
879
879
|
if (n.k === BR) out.push({ tag: "br" });
|
|
880
880
|
else if (n.k === CODE) out.push({ tag: "code", children: [clean(n.s)] });
|
|
881
881
|
else {
|
|
882
|
-
const el = { tag: n.s, children: inlineTree(n.
|
|
882
|
+
const el = { tag: n.s, children: inlineTree(n.P, [], depth + 1, inA || n.s === "a") };
|
|
883
883
|
if (n.s === "a") {
|
|
884
|
-
el.href = n.
|
|
885
|
-
if (n.
|
|
884
|
+
el.href = n.G;
|
|
885
|
+
if (n.y) el.dest = n.y;
|
|
886
886
|
}
|
|
887
887
|
out.push(el);
|
|
888
888
|
}
|