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/dist/index.mjs CHANGED
@@ -1,18 +1,18 @@
1
- function B(t, e) {
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 = P(n), n.flankingWhitespace = H(n, e), n;
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 P(t) {
6
- return !S(t) && !U(t) && /^\s*$/i.test(t.textContent || "") && !$(t) && !z(t);
5
+ function v(t) {
6
+ return !L(t) && !V(t) && /^\s*$/i.test(t.textContent || "") && !U(t) && !W(t);
7
7
  }
8
- function H(t, e) {
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 = _(t.textContent || "");
13
- return r.leadingAscii && A("left", t, e) && (r.leading = r.leadingNonAscii), r.trailingAscii && A("right", t, e) && (r.trailing = r.trailingNonAscii), { leading: r.leading, trailing: r.trailing };
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 _(t) {
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 A(t, e, n) {
35
+ function b(t, e, n) {
36
36
  let r, i, l;
37
- return t === "left" ? (r = e.previousElementSibling, i = / $/) : (r = e.nextElementSibling, 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;
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 m = {
39
+ const p = {
40
40
  Element: 1,
41
41
  Text: 3,
42
42
  CDATASection: 4
43
43
  };
44
- function N(t, e) {
44
+ function T(t, e) {
45
45
  return Array(e + 1).join(t);
46
46
  }
47
- function D(t) {
47
+ function I(t) {
48
48
  return t.replace(/^\n*/, "");
49
49
  }
50
- function w(t) {
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 x(t) {
57
- return w(D(t));
56
+ function w(t) {
57
+ return O(I(t));
58
58
  }
59
- const v = [
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 k(t, v);
111
+ return A(t, F);
112
112
  }
113
- const O = [
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 S(t) {
132
- return k(t, O);
131
+ function L(t) {
132
+ return A(t, D);
133
133
  }
134
- function $(t) {
135
- return M(t, O);
134
+ function U(t) {
135
+ return B(t, D);
136
136
  }
137
- const L = [
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
- ], F = [
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 U(t) {
181
- return k(t, L);
180
+ function V(t) {
181
+ return A(t, M);
182
182
  }
183
- function z(t) {
184
- return M(t, L);
183
+ function W(t) {
184
+ return B(t, M);
185
185
  }
186
- function k(t, e) {
186
+ function A(t, e) {
187
187
  return e.indexOf(t.nodeName) >= 0;
188
188
  }
189
- function M(t, e) {
189
+ function B(t, e) {
190
190
  return e.some(function(n) {
191
- return t.nodeType !== m.Element ? !1 : t.getElementsByTagName(n).length;
191
+ return t.nodeType !== p.Element ? !1 : t.getElementsByTagName(n).length;
192
192
  });
193
193
  }
194
- function I(t) {
194
+ function P(t) {
195
195
  return t ? t.replace(/(\n+\s*)+/g, `
196
196
  `) : "";
197
197
  }
198
- function V(t) {
199
- return I(t).replace(/[\t\r\n]+/g, " ").replace(/ {2,}/g, " ").replace(/([()])/g, "\\$1").trim();
198
+ function G(t) {
199
+ return P(t).replace(/[\t\r\n]+/g, " ").replace(/ {2,}/g, " ").replace(/([()])/g, "\\$1").trim();
200
200
  }
201
- function p(t) {
202
- return I(t).replace(/[\t\r\n]+/g, " ");
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 = N(r === 1 ? "=" : "-", t.length);
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
- ` + N("#", r) + " " + t + `
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 = x(t).replace(/^/gm, "> "), `
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 a = i.getAttribute("start"), o = Array.prototype.indexOf.call(i.children, e);
271
- r = (a ? Number(a) + o : o + 1) + ". ";
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
- return t = x(t) + (l ? `
275
- ` : ""), t = t.replace(/\n/gm, `
276
- ` + " ".repeat(r.length)), r + t + (e.nextSibling ? `
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], a = r.textContent || "", o = n.fence?.charAt(0) || "`";
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 u = new RegExp("^" + o + "{3,}", "gm");
303
- let c;
304
- for (; c = u.exec(a); )
305
- c[0].length >= s && (s = c[0].length + 1);
306
- const d = N(o, s);
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
- ` + a.replace(/\n$/, "") + `
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 = V(t);
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 = ' "' + p(l).replace(/"/g, '\\"') + '"' : i = "", "[" + n + "](" + r + i + ")";
347
+ return l ? i = ' "' + h(l).replace(/"/g, '\\"') + '"' : i = "", "[" + n + "](" + r + i + ")";
335
348
  }
336
349
  };
337
- const R = {
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 = R, i = e.getAttribute("href");
355
+ const r = k, i = e.getAttribute("href");
343
356
  let l;
344
- const a = e.getAttribute("title");
345
- a ? l = ' "' + p(a) + '"' : l = "";
346
- const o = i + l;
347
- let s, u;
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 + "][]", u = "[" + t + "]: " + o;
363
+ s = "[" + t + "][]", c = "[" + t + "]: " + a;
351
364
  break;
352
365
  case "shortcut":
353
- s = "[" + t + "]", u = "[" + t + "]: " + o;
366
+ s = "[" + t + "]", c = "[" + t + "]: " + a;
354
367
  break;
355
368
  default: {
356
- let c;
357
- const d = r.urlReferenceIdMap.get(o);
358
- n.linkReferenceDeduplication === "full" && d ? (c = d, u = "[" + c + "]: " + i + l) : (c = r.references.length + 1, r.urlReferenceIdMap.set(o, c), u = "[" + c + "]: " + i + l, r.references.push(u)), s = "[" + t + "][" + c + "]";
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(o) || (r.urlReferenceIdMap.set(o, 1), r.references.push(u)) : r.references.push(u)), s;
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 = R;
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 = R;
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 ? p(n) : "", i = e.getAttribute("src") || "", l = e.getAttribute("title"), a = l ? p(l) : "", o = a ? ' "' + a + '"' : "";
403
- return i ? "![" + r + "](" + i + o + ")" : "";
415
+ const n = e.getAttribute("alt"), r = n ? h(n) : "", i = e.getAttribute("src") || "", l = e.getAttribute("title"), o = l ? h(l) : "", a = o ? ' "' + o + '"' : "";
416
+ return i ? "![" + r + "](" + i + a + ")" : "";
404
417
  }
405
418
  };
406
- class W {
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 = h(this.array, e, this.options)) || (n = h(this._keep, e, this.options)) || (n = h(this._remove, e, this.options)) ? n : this.defaultRule;
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 F.indexOf(n) === -1;
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 h(t, e, n) {
513
+ function g(t, e, n) {
501
514
  for (let r = 0; r < t.length; r++) {
502
515
  const i = t[r];
503
- if (G(i, e, n)) return i;
516
+ if (j(i, e, n)) return i;
504
517
  }
505
518
  }
506
- function G(t, e, n) {
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 K(t) {
522
- const e = t.element, n = t.isBlock, r = t.isVoid, i = t.isPre || function(u) {
523
- return u.nodeName === "PRE";
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, a = !1, o = null, s = y(o, e, i);
539
+ let l = null, o = !1, a = null, s = C(a, e, i);
527
540
  for (; s !== e; ) {
528
- if (s.nodeType === m.Text || s.nodeType === m.CDATASection) {
529
- const c = s;
530
- let d = c.data.replace(/[ \r\n\t]+/g, " ");
531
- if ((!l || / $/.test(l.data)) && !a && d[0] === " " && (d = d.substr(1)), !d) {
532
- s = g(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
- c.data = d, l = c;
536
- } else if (s.nodeType === m.Element)
537
- n(s) || s.nodeName === "BR" ? (l && (l.data = l.data.replace(/ $/, "")), l = null, a = !1) : r(s) || i(s) ? (l = null, a = !0) : l && (a = !1);
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 = g(s);
552
+ s = N(s);
540
553
  continue;
541
554
  }
542
- const u = y(o, s, i);
543
- o = s, s = u;
555
+ const c = C(a, s, i);
556
+ a = s, s = c;
544
557
  }
545
- l && (l.data = l.data.replace(/ $/, ""), l.data || g(l));
558
+ l && (l.data = l.data.replace(/ $/, ""), l.data || N(l));
546
559
  }
547
- function g(t) {
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 y(t, e, n) {
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 T = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : {};
555
- function j() {
556
- const t = typeof T.DOMParser < "u" ? T.DOMParser : void 0;
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 C {
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 Y() {
584
+ function Q() {
572
585
  if (typeof window < "u" && typeof document < "u" && (typeof process > "u" || process.browser), typeof window < "u") {
573
- class t extends C {
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 C {
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 q = () => j() ? new T.DOMParser() : Y();
591
- function Q(t, { preformattedCode: e }) {
603
+ const X = () => q() ? new R.DOMParser() : Q();
604
+ function J(t, { preformattedCode: e }) {
592
605
  let n;
593
- return typeof t == "string" ? n = J().parseFromString(
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), K({
612
+ ).getElementById("turnish-root") : n = t.cloneNode(!0), Y({
600
613
  element: n,
601
614
  isBlock: E,
602
- isVoid: S,
603
- isPre: e ? Z : void 0
615
+ isVoid: L,
616
+ isPre: e ? te : void 0
604
617
  }), n;
605
618
  }
606
- let X;
607
- function J() {
608
- return X ??= q();
619
+ let Z;
620
+ function ee() {
621
+ return Z ??= X();
609
622
  }
610
- function Z(t) {
623
+ function te(t) {
611
624
  return t.nodeName === "PRE" || t.nodeName === "CODE";
612
625
  }
613
- const ee = [
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
- ], te = {
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 u = 0; u < e.attributes.length; u++) {
657
- const c = e.attributes[u];
658
- s.push(`${c.name}="${c.value}"`);
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}>`, a = t.trim(), o = i + `
664
- ` + a + `
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
- ` + o + `
684
+ ` + a + `
669
685
 
670
- ` : o;
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 re {
696
+ class le {
681
697
  options;
682
698
  rules;
683
699
  constructor(e) {
684
- this.options = Object.assign({}, te, e), this.rules = new W(this.options);
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 (!ne(e))
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(Q(e, this.options));
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 ee.reduce(function(n, r) {
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 = B(r, this.options);
787
+ const i = H(r, this.options);
772
788
  let l = "";
773
- if (i.nodeType === m.Text) {
774
- const a = i.nodeValue ?? "";
775
- l = i.isCode ? a : this.escape(a);
776
- } else i.nodeType === m.Element && (l = this.replacementForNode(i));
777
- return b(n, l);
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 = b(e, n.append(this.options)));
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 b(t, e) {
807
- const n = w(t), r = D(e), i = Math.max(t.length - n.length, e.length - r.length), l = `
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 ne(t) {
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
- re as default
836
+ le as default
817
837
  };
818
838
  //# sourceMappingURL=index.mjs.map