turnish 1.0.0 → 1.2.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 +34 -21
- package/dist/index.cjs +22 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +22 -21
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +157 -137
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +20 -19
- package/dist/index.umd.js.map +1 -1
- package/dist/types/index.d.ts +17 -14
- package/package.json +9 -4
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
function
|
|
1
|
+
function H(t, e) {
|
|
2
2
|
const n = t;
|
|
3
|
-
return n.isBlock = E(n), n.isCode = n.nodeName === "CODE" || n.parentNode?.isCode, n.isBlank =
|
|
3
|
+
return n.isBlock = E(n), n.isCode = n.nodeName === "CODE" || n.parentNode?.isCode, n.isBlank = v(n), n.flankingWhitespace = _(n, e), n;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
return !
|
|
5
|
+
function v(t) {
|
|
6
|
+
return !L(t) && !V(t) && /^\s*$/i.test(t.textContent || "") && !U(t) && !W(t);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function _(t, e) {
|
|
9
9
|
const n = t;
|
|
10
10
|
if (n.isBlock || e.preformattedCode && n.isCode)
|
|
11
11
|
return { leading: "", trailing: "" };
|
|
12
|
-
const r =
|
|
13
|
-
return r.leadingAscii &&
|
|
12
|
+
const r = $(t.textContent || "");
|
|
13
|
+
return r.leadingAscii && b("left", t, e) && (r.leading = r.leadingNonAscii), r.trailingAscii && b("right", t, e) && (r.trailing = r.trailingNonAscii), { leading: r.leading, trailing: r.trailing };
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function $(t) {
|
|
16
16
|
const e = t.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);
|
|
17
17
|
return e ? {
|
|
18
18
|
leading: e[1],
|
|
@@ -32,31 +32,31 @@ function _(t) {
|
|
|
32
32
|
trailingAscii: ""
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function b(t, e, n) {
|
|
36
36
|
let r, i, l;
|
|
37
|
-
return t === "left" ? (r = e.
|
|
37
|
+
return t === "left" ? (r = e.previousSibling, i = / $/) : (r = e.nextSibling, i = /^ /), r && (r.nodeType === 3 ? l = i.test(r.nodeValue || "") : n.preformattedCode && r.nodeName === "CODE" ? l = !1 : r.nodeType === 1 && !E(r) && (l = i.test(r.textContent || ""))), l || !1;
|
|
38
38
|
}
|
|
39
|
-
const
|
|
39
|
+
const p = {
|
|
40
40
|
Element: 1,
|
|
41
41
|
Text: 3,
|
|
42
42
|
CDATASection: 4
|
|
43
43
|
};
|
|
44
|
-
function
|
|
44
|
+
function T(t, e) {
|
|
45
45
|
return Array(e + 1).join(t);
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function I(t) {
|
|
48
48
|
return t.replace(/^\n*/, "");
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function O(t) {
|
|
51
51
|
let e = t.length;
|
|
52
52
|
for (; e > 0 && t[e - 1] === `
|
|
53
53
|
`; ) e--;
|
|
54
54
|
return t.substring(0, e);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
56
|
+
function w(t) {
|
|
57
|
+
return O(I(t));
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const F = [
|
|
60
60
|
"ADDRESS",
|
|
61
61
|
"ARTICLE",
|
|
62
62
|
"ASIDE",
|
|
@@ -108,9 +108,9 @@ const v = [
|
|
|
108
108
|
"UL"
|
|
109
109
|
];
|
|
110
110
|
function E(t) {
|
|
111
|
-
return
|
|
111
|
+
return A(t, F);
|
|
112
112
|
}
|
|
113
|
-
const
|
|
113
|
+
const D = [
|
|
114
114
|
"AREA",
|
|
115
115
|
"BASE",
|
|
116
116
|
"BR",
|
|
@@ -128,13 +128,13 @@ const O = [
|
|
|
128
128
|
"TRACK",
|
|
129
129
|
"WBR"
|
|
130
130
|
];
|
|
131
|
-
function
|
|
132
|
-
return
|
|
131
|
+
function L(t) {
|
|
132
|
+
return A(t, D);
|
|
133
133
|
}
|
|
134
|
-
function
|
|
135
|
-
return
|
|
134
|
+
function U(t) {
|
|
135
|
+
return B(t, D);
|
|
136
136
|
}
|
|
137
|
-
const
|
|
137
|
+
const M = [
|
|
138
138
|
"A",
|
|
139
139
|
"TABLE",
|
|
140
140
|
"THEAD",
|
|
@@ -146,7 +146,7 @@ const L = [
|
|
|
146
146
|
"SCRIPT",
|
|
147
147
|
"AUDIO",
|
|
148
148
|
"VIDEO"
|
|
149
|
-
],
|
|
149
|
+
], z = [
|
|
150
150
|
"P",
|
|
151
151
|
"BR",
|
|
152
152
|
"H1",
|
|
@@ -177,29 +177,29 @@ const L = [
|
|
|
177
177
|
"TH",
|
|
178
178
|
"TD"
|
|
179
179
|
];
|
|
180
|
-
function
|
|
181
|
-
return
|
|
180
|
+
function V(t) {
|
|
181
|
+
return A(t, M);
|
|
182
182
|
}
|
|
183
|
-
function
|
|
184
|
-
return
|
|
183
|
+
function W(t) {
|
|
184
|
+
return B(t, M);
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function A(t, e) {
|
|
187
187
|
return e.indexOf(t.nodeName) >= 0;
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function B(t, e) {
|
|
190
190
|
return e.some(function(n) {
|
|
191
|
-
return t.nodeType !==
|
|
191
|
+
return t.nodeType !== p.Element ? !1 : t.getElementsByTagName(n).length;
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function P(t) {
|
|
195
195
|
return t ? t.replace(/(\n+\s*)+/g, `
|
|
196
196
|
`) : "";
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
return
|
|
198
|
+
function G(t) {
|
|
199
|
+
return P(t).replace(/[\t\r\n]+/g, " ").replace(/ {2,}/g, " ").replace(/([()])/g, "\\$1").trim();
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
return
|
|
201
|
+
function h(t) {
|
|
202
|
+
return P(t).replace(/[\t\r\n]+/g, " ");
|
|
203
203
|
}
|
|
204
204
|
const f = {};
|
|
205
205
|
f.paragraph = {
|
|
@@ -224,7 +224,7 @@ f.heading = {
|
|
|
224
224
|
replacement: function(t, e, n) {
|
|
225
225
|
const r = Number(e.nodeName.charAt(1));
|
|
226
226
|
if (n.headingStyle === "setext" && r < 3) {
|
|
227
|
-
const i =
|
|
227
|
+
const i = T(r === 1 ? "=" : "-", t.length);
|
|
228
228
|
return `
|
|
229
229
|
|
|
230
230
|
` + t + `
|
|
@@ -234,7 +234,7 @@ f.heading = {
|
|
|
234
234
|
} else
|
|
235
235
|
return `
|
|
236
236
|
|
|
237
|
-
` +
|
|
237
|
+
` + T("#", r) + " " + t + `
|
|
238
238
|
|
|
239
239
|
`;
|
|
240
240
|
}
|
|
@@ -242,7 +242,7 @@ f.heading = {
|
|
|
242
242
|
f.blockquote = {
|
|
243
243
|
filter: "blockquote",
|
|
244
244
|
replacement: function(t) {
|
|
245
|
-
return t =
|
|
245
|
+
return t = w(t).replace(/^/gm, "> "), `
|
|
246
246
|
|
|
247
247
|
` + t + `
|
|
248
248
|
|
|
@@ -264,16 +264,29 @@ f.list = {
|
|
|
264
264
|
f.listItem = {
|
|
265
265
|
filter: "li",
|
|
266
266
|
replacement: function(t, e, n) {
|
|
267
|
-
let r = n.bulletListMarker + "
|
|
267
|
+
let r = n.bulletListMarker + " ".repeat(n.listMarkerSpaceCount);
|
|
268
268
|
const i = e.parentNode;
|
|
269
269
|
if (i.nodeName === "OL") {
|
|
270
|
-
const
|
|
271
|
-
r = (
|
|
270
|
+
const m = i.getAttribute("start"), y = Array.prototype.indexOf.call(i.children, e);
|
|
271
|
+
r = (m ? Number(m) + y : y + 1) + "." + " ".repeat(n.listMarkerSpaceCount);
|
|
272
272
|
}
|
|
273
273
|
const l = /\n$/.test(t);
|
|
274
|
-
|
|
275
|
-
` : ""),
|
|
276
|
-
|
|
274
|
+
if (t = w(t) + (l ? `
|
|
275
|
+
` : ""), e.childNodes.length > 0 && Array.from(e.childNodes).every((m) => m.nodeType === p.Text && /^\s*$/.test(m.nodeValue || "") || m.nodeType === p.Element && ["UL", "OL"].includes(m.nodeName)) && t.trim() !== "")
|
|
276
|
+
return t + (e.nextSibling ? `
|
|
277
|
+
` : "");
|
|
278
|
+
let a = 0, s = i;
|
|
279
|
+
for (; s; ) {
|
|
280
|
+
if (s.nodeName === "UL" || s.nodeName === "OL") {
|
|
281
|
+
const m = s.parentNode;
|
|
282
|
+
m && m.nodeName === "LI" && a++;
|
|
283
|
+
}
|
|
284
|
+
s = s.parentNode;
|
|
285
|
+
}
|
|
286
|
+
let c = n.listItemIndent === "tab" ? " " : " ".repeat(n.listItemIndentSpaceCount), u = c.repeat(a);
|
|
287
|
+
const d = /\n(?!\s*(?:\d+\.\s|[-+*]\s))/gm;
|
|
288
|
+
return t = t.replace(d, `
|
|
289
|
+
` + c), u + r + t + (e.nextSibling ? `
|
|
277
290
|
` : "");
|
|
278
291
|
}
|
|
279
292
|
};
|
|
@@ -297,17 +310,17 @@ f.fencedCodeBlock = {
|
|
|
297
310
|
replacement: function(t, e, n) {
|
|
298
311
|
if (!e.firstChild)
|
|
299
312
|
return "";
|
|
300
|
-
const r = e.firstChild, l = ((r.getAttribute("class") || "").match(/language-(\S+)/) || [null, ""])[1],
|
|
313
|
+
const r = e.firstChild, l = ((r.getAttribute("class") || "").match(/language-(\S+)/) || [null, ""])[1], o = r.textContent || "", a = n.fence?.charAt(0) || "`";
|
|
301
314
|
let s = 3;
|
|
302
|
-
const
|
|
303
|
-
let
|
|
304
|
-
for (;
|
|
305
|
-
|
|
306
|
-
const d =
|
|
315
|
+
const c = new RegExp("^" + a + "{3,}", "gm");
|
|
316
|
+
let u;
|
|
317
|
+
for (; u = c.exec(o); )
|
|
318
|
+
u[0].length >= s && (s = u[0].length + 1);
|
|
319
|
+
const d = T(a, s);
|
|
307
320
|
return `
|
|
308
321
|
|
|
309
322
|
` + d + l + `
|
|
310
|
-
` +
|
|
323
|
+
` + o.replace(/\n$/, "") + `
|
|
311
324
|
` + d + `
|
|
312
325
|
|
|
313
326
|
`;
|
|
@@ -328,43 +341,43 @@ f.inlineLink = {
|
|
|
328
341
|
return !!(e?.linkStyle === "inlined" && t.nodeName === "A" && t.getAttribute("href"));
|
|
329
342
|
},
|
|
330
343
|
replacement: function(t, e) {
|
|
331
|
-
const n =
|
|
344
|
+
const n = G(t);
|
|
332
345
|
let r = e.getAttribute("href")?.replace(/([()])/g, "\\$1"), i;
|
|
333
346
|
const l = e.getAttribute("title");
|
|
334
|
-
return l ? i = ' "' +
|
|
347
|
+
return l ? i = ' "' + h(l).replace(/"/g, '\\"') + '"' : i = "", "[" + n + "](" + r + i + ")";
|
|
335
348
|
}
|
|
336
349
|
};
|
|
337
|
-
const
|
|
350
|
+
const k = {
|
|
338
351
|
filter: function(t, e) {
|
|
339
352
|
return !!(e && e.linkStyle === "referenced" && t.nodeName === "A" && t.getAttribute("href"));
|
|
340
353
|
},
|
|
341
354
|
replacement: function(t, e, n) {
|
|
342
|
-
const r =
|
|
355
|
+
const r = k, i = e.getAttribute("href");
|
|
343
356
|
let l;
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
let s,
|
|
357
|
+
const o = e.getAttribute("title");
|
|
358
|
+
o ? l = ' "' + h(o) + '"' : l = "";
|
|
359
|
+
const a = i + l;
|
|
360
|
+
let s, c;
|
|
348
361
|
switch (n.linkReferenceStyle) {
|
|
349
362
|
case "collapsed":
|
|
350
|
-
s = "[" + t + "][]",
|
|
363
|
+
s = "[" + t + "][]", c = "[" + t + "]: " + a;
|
|
351
364
|
break;
|
|
352
365
|
case "shortcut":
|
|
353
|
-
s = "[" + t + "]",
|
|
366
|
+
s = "[" + t + "]", c = "[" + t + "]: " + a;
|
|
354
367
|
break;
|
|
355
368
|
default: {
|
|
356
|
-
let
|
|
357
|
-
const d = r.urlReferenceIdMap.get(
|
|
358
|
-
n.linkReferenceDeduplication === "full" && d ? (
|
|
369
|
+
let u;
|
|
370
|
+
const d = r.urlReferenceIdMap.get(a);
|
|
371
|
+
n.linkReferenceDeduplication === "full" && d ? (u = d, c = "[" + u + "]: " + i + l) : (u = r.references.length + 1, r.urlReferenceIdMap.set(a, u), c = "[" + u + "]: " + i + l, r.references.push(c)), s = "[" + t + "][" + u + "]";
|
|
359
372
|
break;
|
|
360
373
|
}
|
|
361
374
|
}
|
|
362
|
-
return n.linkReferenceStyle !== "full" && (n.linkReferenceDeduplication === "full" ? r.urlReferenceIdMap.has(
|
|
375
|
+
return n.linkReferenceStyle !== "full" && (n.linkReferenceDeduplication === "full" ? r.urlReferenceIdMap.has(a) || (r.urlReferenceIdMap.set(a, 1), r.references.push(c)) : r.references.push(c)), s;
|
|
363
376
|
},
|
|
364
377
|
references: [],
|
|
365
378
|
urlReferenceIdMap: /* @__PURE__ */ new Map(),
|
|
366
379
|
append: () => {
|
|
367
|
-
const t =
|
|
380
|
+
const t = k;
|
|
368
381
|
let e = "";
|
|
369
382
|
return t.references && t.references.length && (e = `
|
|
370
383
|
|
|
@@ -374,7 +387,7 @@ const R = {
|
|
|
374
387
|
`, t.references = [], t.urlReferenceIdMap = /* @__PURE__ */ new Map()), e;
|
|
375
388
|
}
|
|
376
389
|
};
|
|
377
|
-
f.referenceLink =
|
|
390
|
+
f.referenceLink = k;
|
|
378
391
|
f.emphasis = {
|
|
379
392
|
filter: ["em", "i"],
|
|
380
393
|
replacement: (t, e, n) => (t = t.trim(), t ? n.emDelimiter + t + n.emDelimiter : "")
|
|
@@ -399,11 +412,11 @@ f.code = {
|
|
|
399
412
|
f.image = {
|
|
400
413
|
filter: "img",
|
|
401
414
|
replacement: function(t, e) {
|
|
402
|
-
const n = e.getAttribute("alt"), r = n ?
|
|
403
|
-
return i ? ", r = n ? h(n) : "", i = e.getAttribute("src") || "", l = e.getAttribute("title"), o = l ? h(l) : "", a = o ? ' "' + o + '"' : "";
|
|
416
|
+
return i ? "" : "";
|
|
404
417
|
}
|
|
405
418
|
};
|
|
406
|
-
class
|
|
419
|
+
class K {
|
|
407
420
|
options;
|
|
408
421
|
_keep;
|
|
409
422
|
_remove;
|
|
@@ -450,7 +463,7 @@ class W {
|
|
|
450
463
|
replacement: this.markdownIncludingHtmlReplacement
|
|
451
464
|
};
|
|
452
465
|
let n;
|
|
453
|
-
return (n =
|
|
466
|
+
return (n = g(this.array, e, this.options)) || (n = g(this._keep, e, this.options)) || (n = g(this._remove, e, this.options)) ? n : this.defaultRule;
|
|
454
467
|
}
|
|
455
468
|
/// Check if an element is unsupported for Markdown conversion.
|
|
456
469
|
isUnsupportedElement(e) {
|
|
@@ -490,20 +503,20 @@ class W {
|
|
|
490
503
|
default:
|
|
491
504
|
return !0;
|
|
492
505
|
}
|
|
493
|
-
return
|
|
506
|
+
return z.indexOf(n) === -1;
|
|
494
507
|
}
|
|
495
508
|
forEach(e) {
|
|
496
509
|
for (let n = 0; n < this.array.length; n++)
|
|
497
510
|
e(this.array[n], n);
|
|
498
511
|
}
|
|
499
512
|
}
|
|
500
|
-
function
|
|
513
|
+
function g(t, e, n) {
|
|
501
514
|
for (let r = 0; r < t.length; r++) {
|
|
502
515
|
const i = t[r];
|
|
503
|
-
if (
|
|
516
|
+
if (j(i, e, n)) return i;
|
|
504
517
|
}
|
|
505
518
|
}
|
|
506
|
-
function
|
|
519
|
+
function j(t, e, n) {
|
|
507
520
|
const r = t.filter;
|
|
508
521
|
if (typeof r == "string") {
|
|
509
522
|
if (r === e.nodeName.toLowerCase())
|
|
@@ -518,42 +531,42 @@ function G(t, e, n) {
|
|
|
518
531
|
throw new TypeError("`filter` needs to be a string, array, or function");
|
|
519
532
|
return !1;
|
|
520
533
|
}
|
|
521
|
-
function
|
|
522
|
-
const e = t.element, n = t.isBlock, r = t.isVoid, i = t.isPre || function(
|
|
523
|
-
return
|
|
534
|
+
function Y(t) {
|
|
535
|
+
const e = t.element, n = t.isBlock, r = t.isVoid, i = t.isPre || function(c) {
|
|
536
|
+
return c.nodeName === "PRE";
|
|
524
537
|
};
|
|
525
538
|
if (!e.firstChild || i(e)) return;
|
|
526
|
-
let l = null,
|
|
539
|
+
let l = null, o = !1, a = null, s = C(a, e, i);
|
|
527
540
|
for (; s !== e; ) {
|
|
528
|
-
if (s.nodeType ===
|
|
529
|
-
const
|
|
530
|
-
let d =
|
|
531
|
-
if ((!l || / $/.test(l.data)) && !
|
|
532
|
-
s =
|
|
541
|
+
if (s.nodeType === p.Text || s.nodeType === p.CDATASection) {
|
|
542
|
+
const u = s;
|
|
543
|
+
let d = u.data.replace(/[ \r\n\t]+/g, " ");
|
|
544
|
+
if ((!l || / $/.test(l.data)) && !o && d[0] === " " && (d = d.substr(1)), !d) {
|
|
545
|
+
s = N(s);
|
|
533
546
|
continue;
|
|
534
547
|
}
|
|
535
|
-
|
|
536
|
-
} else if (s.nodeType ===
|
|
537
|
-
n(s) || s.nodeName === "BR" ? (l && (l.data = l.data.replace(/ $/, "")), l = null,
|
|
548
|
+
u.data = d, l = u;
|
|
549
|
+
} else if (s.nodeType === p.Element)
|
|
550
|
+
n(s) || s.nodeName === "BR" ? (l && (l.data = l.data.replace(/ $/, "")), l = null, o = !1) : r(s) || i(s) ? (l = null, o = !0) : l && (o = !1);
|
|
538
551
|
else {
|
|
539
|
-
s =
|
|
552
|
+
s = N(s);
|
|
540
553
|
continue;
|
|
541
554
|
}
|
|
542
|
-
const
|
|
543
|
-
|
|
555
|
+
const c = C(a, s, i);
|
|
556
|
+
a = s, s = c;
|
|
544
557
|
}
|
|
545
|
-
l && (l.data = l.data.replace(/ $/, ""), l.data ||
|
|
558
|
+
l && (l.data = l.data.replace(/ $/, ""), l.data || N(l));
|
|
546
559
|
}
|
|
547
|
-
function
|
|
560
|
+
function N(t) {
|
|
548
561
|
const e = t.nextSibling ?? t.parentNode;
|
|
549
562
|
return t.parentNode && t.parentNode.removeChild(t), e;
|
|
550
563
|
}
|
|
551
|
-
function
|
|
564
|
+
function C(t, e, n) {
|
|
552
565
|
return t && t.parentNode === e || n(e) ? e.nextSibling ?? e.parentNode : e.firstChild ?? e.nextSibling ?? e.parentNode;
|
|
553
566
|
}
|
|
554
|
-
const
|
|
555
|
-
function
|
|
556
|
-
const t = typeof
|
|
567
|
+
const R = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : {};
|
|
568
|
+
function q() {
|
|
569
|
+
const t = typeof R.DOMParser < "u" ? R.DOMParser : void 0;
|
|
557
570
|
let e = !1;
|
|
558
571
|
if (!t) return !1;
|
|
559
572
|
try {
|
|
@@ -562,15 +575,15 @@ function j() {
|
|
|
562
575
|
}
|
|
563
576
|
return e;
|
|
564
577
|
}
|
|
565
|
-
class
|
|
578
|
+
class S {
|
|
566
579
|
// This will be assigned per environment below
|
|
567
580
|
parseFromString(e, n) {
|
|
568
581
|
throw new Error("Not implemented");
|
|
569
582
|
}
|
|
570
583
|
}
|
|
571
|
-
function
|
|
584
|
+
function Q() {
|
|
572
585
|
if (typeof window < "u" && typeof document < "u" && (typeof process > "u" || process.browser), typeof window < "u") {
|
|
573
|
-
class t extends
|
|
586
|
+
class t extends S {
|
|
574
587
|
parseFromString(n, r) {
|
|
575
588
|
const i = document.implementation.createHTMLDocument("");
|
|
576
589
|
return i.open(), i.write(n), i.close(), i;
|
|
@@ -579,7 +592,7 @@ function Y() {
|
|
|
579
592
|
return new t();
|
|
580
593
|
} else {
|
|
581
594
|
const t = require("@mixmark-io/domino");
|
|
582
|
-
class e extends
|
|
595
|
+
class e extends S {
|
|
583
596
|
parseFromString(r, i) {
|
|
584
597
|
return t.createDocument(r);
|
|
585
598
|
}
|
|
@@ -587,30 +600,30 @@ function Y() {
|
|
|
587
600
|
return new e();
|
|
588
601
|
}
|
|
589
602
|
}
|
|
590
|
-
const
|
|
591
|
-
function
|
|
603
|
+
const X = () => q() ? new R.DOMParser() : Q();
|
|
604
|
+
function J(t, { preformattedCode: e }) {
|
|
592
605
|
let n;
|
|
593
|
-
return typeof t == "string" ? n =
|
|
606
|
+
return typeof t == "string" ? n = ee().parseFromString(
|
|
594
607
|
// DOM parsers arrange elements in the <head> and <body>.
|
|
595
608
|
// Wrapping in a custom element ensures elements are reliably arranged in
|
|
596
609
|
// a single element.
|
|
597
610
|
'<x-turnish id="turnish-root">' + t + "</x-turnish>",
|
|
598
611
|
"text/html"
|
|
599
|
-
).getElementById("turnish-root") : n = t.cloneNode(!0),
|
|
612
|
+
).getElementById("turnish-root") : n = t.cloneNode(!0), Y({
|
|
600
613
|
element: n,
|
|
601
614
|
isBlock: E,
|
|
602
|
-
isVoid:
|
|
603
|
-
isPre: e ?
|
|
615
|
+
isVoid: L,
|
|
616
|
+
isPre: e ? te : void 0
|
|
604
617
|
}), n;
|
|
605
618
|
}
|
|
606
|
-
let
|
|
607
|
-
function
|
|
608
|
-
return
|
|
619
|
+
let Z;
|
|
620
|
+
function ee() {
|
|
621
|
+
return Z ??= X();
|
|
609
622
|
}
|
|
610
|
-
function
|
|
623
|
+
function te(t) {
|
|
611
624
|
return t.nodeName === "PRE" || t.nodeName === "CODE";
|
|
612
625
|
}
|
|
613
|
-
const
|
|
626
|
+
const ne = [
|
|
614
627
|
[/\\/g, "\\\\"],
|
|
615
628
|
[/\*/g, "\\*"],
|
|
616
629
|
[/_/g, "\\_"],
|
|
@@ -625,11 +638,14 @@ const ee = [
|
|
|
625
638
|
[/<([^>]*)>/g, "\\<$1\\>"],
|
|
626
639
|
[/^>/g, "\\>"],
|
|
627
640
|
[/^(\d+)\. /g, "$1\\. "]
|
|
628
|
-
],
|
|
641
|
+
], re = {
|
|
629
642
|
rules: f,
|
|
630
643
|
headingStyle: "atx",
|
|
631
644
|
hr: "---",
|
|
632
645
|
bulletListMarker: "-",
|
|
646
|
+
listMarkerSpaceCount: 1,
|
|
647
|
+
listItemIndent: "space",
|
|
648
|
+
listItemIndentSpaceCount: 4,
|
|
633
649
|
codeBlockStyle: "fenced",
|
|
634
650
|
fence: "```",
|
|
635
651
|
emDelimiter: "*",
|
|
@@ -653,21 +669,21 @@ const ee = [
|
|
|
653
669
|
let r = "";
|
|
654
670
|
if (e.attributes && e.attributes.length > 0) {
|
|
655
671
|
const s = [];
|
|
656
|
-
for (let
|
|
657
|
-
const
|
|
658
|
-
s.push(`${
|
|
672
|
+
for (let c = 0; c < e.attributes.length; c++) {
|
|
673
|
+
const u = e.attributes[c];
|
|
674
|
+
s.push(`${u.name}="${u.value}"`);
|
|
659
675
|
}
|
|
660
676
|
r = " " + s.join(" ");
|
|
661
677
|
}
|
|
662
678
|
r += ' markdown="1"';
|
|
663
|
-
const i = `<${n}${r}>`, l = `</${n}>`,
|
|
664
|
-
` +
|
|
679
|
+
const i = `<${n}${r}>`, l = `</${n}>`, o = t.trim(), a = i + `
|
|
680
|
+
` + o + `
|
|
665
681
|
` + l;
|
|
666
682
|
return e.isBlock ? `
|
|
667
683
|
|
|
668
|
-
` +
|
|
684
|
+
` + a + `
|
|
669
685
|
|
|
670
|
-
` :
|
|
686
|
+
` : a;
|
|
671
687
|
},
|
|
672
688
|
defaultReplacement: function(t, e) {
|
|
673
689
|
return e.isBlock ? `
|
|
@@ -677,11 +693,11 @@ const ee = [
|
|
|
677
693
|
` : t;
|
|
678
694
|
}
|
|
679
695
|
};
|
|
680
|
-
class
|
|
696
|
+
class le {
|
|
681
697
|
options;
|
|
682
698
|
rules;
|
|
683
699
|
constructor(e) {
|
|
684
|
-
this.options = Object.assign({},
|
|
700
|
+
this.options = Object.assign({}, re, e), this.rules = new K(this.options);
|
|
685
701
|
}
|
|
686
702
|
/**
|
|
687
703
|
* The entry point for converting a string or DOM node to Markdown
|
|
@@ -691,13 +707,13 @@ class re {
|
|
|
691
707
|
* @type string
|
|
692
708
|
*/
|
|
693
709
|
render(e) {
|
|
694
|
-
if (!
|
|
710
|
+
if (!ie(e))
|
|
695
711
|
throw new TypeError(
|
|
696
712
|
e + " is not a string, or an element/document/fragment node."
|
|
697
713
|
);
|
|
698
714
|
if (e === "")
|
|
699
715
|
return "";
|
|
700
|
-
const n = this.process(
|
|
716
|
+
const n = this.process(J(e, this.options));
|
|
701
717
|
return this.postProcess(n);
|
|
702
718
|
}
|
|
703
719
|
/**
|
|
@@ -755,7 +771,7 @@ class re {
|
|
|
755
771
|
* @type string
|
|
756
772
|
*/
|
|
757
773
|
escape(e) {
|
|
758
|
-
return
|
|
774
|
+
return ne.reduce(function(n, r) {
|
|
759
775
|
return n.replace(r[0], r[1]);
|
|
760
776
|
}, e);
|
|
761
777
|
}
|
|
@@ -768,13 +784,17 @@ class re {
|
|
|
768
784
|
*/
|
|
769
785
|
process(e) {
|
|
770
786
|
return Array.from(e.childNodes).reduce((n, r) => {
|
|
771
|
-
const i =
|
|
787
|
+
const i = H(r, this.options);
|
|
772
788
|
let l = "";
|
|
773
|
-
if (i.nodeType ===
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
789
|
+
if (i.nodeType === p.Text) {
|
|
790
|
+
let o = i.nodeValue ?? "";
|
|
791
|
+
if (r.previousSibling && r.previousSibling.nodeType === p.Element) {
|
|
792
|
+
const a = r.previousSibling;
|
|
793
|
+
a.nodeName === "INPUT" && a.getAttribute("type") === "checkbox" && (o = o.replace(/^\s+/, ""));
|
|
794
|
+
}
|
|
795
|
+
l = i.isCode ? o : this.escape(o);
|
|
796
|
+
} else i.nodeType === p.Element && (l = this.replacementForNode(i));
|
|
797
|
+
return x(n, l);
|
|
778
798
|
}, "");
|
|
779
799
|
}
|
|
780
800
|
/**
|
|
@@ -786,7 +806,7 @@ class re {
|
|
|
786
806
|
*/
|
|
787
807
|
postProcess(e) {
|
|
788
808
|
for (const n of this.rules.array)
|
|
789
|
-
n.append && (e =
|
|
809
|
+
n.append && (e = x(e, n.append(this.options)));
|
|
790
810
|
return e.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
|
|
791
811
|
}
|
|
792
812
|
/**
|
|
@@ -803,16 +823,16 @@ class re {
|
|
|
803
823
|
return (i.leading || i.trailing) && (r = r.trim()), i.leading + n.replacement(r, e, this.options) + i.trailing;
|
|
804
824
|
}
|
|
805
825
|
}
|
|
806
|
-
function
|
|
807
|
-
const n =
|
|
826
|
+
function x(t, e) {
|
|
827
|
+
const n = O(t), r = I(e), i = Math.max(t.length - n.length, e.length - r.length), l = `
|
|
808
828
|
|
|
809
829
|
`.substring(0, i);
|
|
810
830
|
return n + l + r;
|
|
811
831
|
}
|
|
812
|
-
function
|
|
832
|
+
function ie(t) {
|
|
813
833
|
return t != null && (typeof t == "string" || t.nodeType && (t.nodeType === 1 || t.nodeType === 9 || t.nodeType === 11));
|
|
814
834
|
}
|
|
815
835
|
export {
|
|
816
|
-
|
|
836
|
+
le as default
|
|
817
837
|
};
|
|
818
838
|
//# sourceMappingURL=index.mjs.map
|