turnish 1.3.0 → 1.5.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,6 +1,6 @@
1
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 = v(n), n.flankingWhitespace = _(n, e), n;
3
+ return n.isBlock = A(n), n.isCode = n.nodeName === "CODE" || n.parentNode?.isCode, n.isBlank = v(n), n.flankingWhitespace = _(n, e), n;
4
4
  }
5
5
  function v(t) {
6
6
  return !L(t) && !V(t) && /^\s*$/i.test(t.textContent || "") && !U(t) && !W(t);
@@ -34,14 +34,14 @@ function $(t) {
34
34
  }
35
35
  function b(t, e, n) {
36
36
  let r, i, l;
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;
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 && !A(r) && (l = i.test(r.textContent || ""))), l || !1;
38
38
  }
39
39
  const p = {
40
40
  Element: 1,
41
41
  Text: 3,
42
42
  CDATASection: 4
43
43
  };
44
- function T(t, e) {
44
+ function k(t, e) {
45
45
  return Array(e + 1).join(t);
46
46
  }
47
47
  function I(t) {
@@ -107,8 +107,8 @@ const F = [
107
107
  "TR",
108
108
  "UL"
109
109
  ];
110
- function E(t) {
111
- return A(t, F);
110
+ function A(t) {
111
+ return y(t, F);
112
112
  }
113
113
  const D = [
114
114
  "AREA",
@@ -129,7 +129,7 @@ const D = [
129
129
  "WBR"
130
130
  ];
131
131
  function L(t) {
132
- return A(t, D);
132
+ return y(t, D);
133
133
  }
134
134
  function U(t) {
135
135
  return B(t, D);
@@ -178,12 +178,12 @@ const M = [
178
178
  "TD"
179
179
  ];
180
180
  function V(t) {
181
- return A(t, M);
181
+ return y(t, M);
182
182
  }
183
183
  function W(t) {
184
184
  return B(t, M);
185
185
  }
186
- function A(t, e) {
186
+ function y(t, e) {
187
187
  return e.indexOf(t.nodeName) >= 0;
188
188
  }
189
189
  function B(t, e) {
@@ -196,9 +196,9 @@ function P(t) {
196
196
  `) : "";
197
197
  }
198
198
  function G(t) {
199
- return P(t).replace(/[\t\r\n]+/g, " ").replace(/ {2,}/g, " ").replace(/([()])/g, "\\$1").trim();
199
+ return P(t).replace(/[\t\r\n]+/g, " ").replace(/ {2,}/g, " ").trim();
200
200
  }
201
- function h(t) {
201
+ function g(t) {
202
202
  return P(t).replace(/[\t\r\n]+/g, " ");
203
203
  }
204
204
  const f = {};
@@ -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 = T(r === 1 ? "=" : "-", t.length);
227
+ const i = k(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
- ` + T("#", r) + " " + t + `
237
+ ` + k("#", r) + " " + t + `
238
238
 
239
239
  `;
240
240
  }
@@ -267,26 +267,26 @@ f.listItem = {
267
267
  let r = n.bulletListMarker + " ".repeat(n.listMarkerSpaceCount);
268
268
  const i = e.parentNode;
269
269
  if (i.nodeName === "OL") {
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);
270
+ const d = i.getAttribute("start"), h = Array.prototype.indexOf.call(i.children, e);
271
+ r = (d ? Number(d) + h : h + 1) + "." + " ".repeat(n.listMarkerSpaceCount);
272
272
  }
273
273
  const l = /\n$/.test(t);
274
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() !== "")
275
+ ` : ""), e.childNodes.length > 0 && Array.from(e.childNodes).every((d) => d.nodeType === p.Text && /^\s*$/.test(d.nodeValue || "") || d.nodeType === p.Element && ["UL", "OL"].includes(d.nodeName)) && t.trim() !== "")
276
276
  return t + (e.nextSibling ? `
277
277
  ` : "");
278
278
  let a = 0, s = i;
279
279
  for (; s; ) {
280
280
  if (s.nodeName === "UL" || s.nodeName === "OL") {
281
- const m = s.parentNode;
282
- m && m.nodeName === "LI" && a++;
281
+ const d = s.parentNode;
282
+ d && d.nodeName === "LI" && a++;
283
283
  }
284
284
  s = s.parentNode;
285
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 ? `
286
+ let o = n.listItemIndent === "tab" ? " " : " ".repeat(n.listItemIndentSpaceCount), u = o.repeat(a);
287
+ const m = /\n(?!\s*(?:\d+\.\s|[-+*]\s))/gm;
288
+ return t = t.replace(m, `
289
+ ` + o), u + r + t + (e.nextSibling ? `
290
290
  ` : "");
291
291
  }
292
292
  };
@@ -305,23 +305,21 @@ f.indentedCodeBlock = {
305
305
  };
306
306
  f.fencedCodeBlock = {
307
307
  filter: function(t, e) {
308
- return !!(e && e.codeBlockStyle === "fenced" && t.nodeName === "PRE" && t.firstChild && t.firstChild.nodeName === "CODE");
308
+ return !!(e && e.codeBlockStyle === "fenced" && t.nodeName === "PRE");
309
309
  },
310
310
  replacement: function(t, e, n) {
311
- if (!e.firstChild)
312
- return "";
313
- const r = e.firstChild, l = ((r.getAttribute("class") || "").match(/language-(\S+)/) || [null, ""])[1], o = r.textContent || "", a = n.fence?.charAt(0) || "`";
314
- let s = 3;
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);
311
+ const r = e, i = r.firstChild, l = i && i.nodeName === "CODE" ? i : r, a = ((l.getAttribute("class") || "").match(/(?:lang|language)-(\S+)/) || [null, ""])[1], s = l.textContent || "", o = n.fence?.charAt(0) || "`";
312
+ let u = 3;
313
+ const m = new RegExp("^" + o + "{3,}", "gm");
314
+ let d;
315
+ for (; d = m.exec(s); )
316
+ d[0].length >= u && (u = d[0].length + 1);
317
+ const h = k(o, u);
320
318
  return `
321
319
 
322
- ` + d + l + `
323
- ` + o.replace(/\n$/, "") + `
324
- ` + d + `
320
+ ` + h + a + `
321
+ ` + s.replace(/\n$/, "") + `
322
+ ` + h + `
325
323
 
326
324
  `;
327
325
  }
@@ -344,40 +342,40 @@ f.inlineLink = {
344
342
  const n = G(t);
345
343
  let r = e.getAttribute("href")?.replace(/([()])/g, "\\$1"), i;
346
344
  const l = e.getAttribute("title");
347
- return l ? i = ' "' + h(l).replace(/"/g, '\\"') + '"' : i = "", "[" + n + "](" + r + i + ")";
345
+ return l ? i = ' "' + g(l).replace(/"/g, '\\"') + '"' : i = "", "[" + n + "](" + r + i + ")";
348
346
  }
349
347
  };
350
- const k = {
348
+ const R = {
351
349
  filter: function(t, e) {
352
350
  return !!(e && e.linkStyle === "referenced" && t.nodeName === "A" && t.getAttribute("href"));
353
351
  },
354
352
  replacement: function(t, e, n) {
355
- const r = k, i = e.getAttribute("href");
353
+ const r = R, i = e.getAttribute("href");
356
354
  let l;
357
- const o = e.getAttribute("title");
358
- o ? l = ' "' + h(o) + '"' : l = "";
355
+ const c = e.getAttribute("title");
356
+ c ? l = ' "' + g(c) + '"' : l = "";
359
357
  const a = i + l;
360
- let s, c;
358
+ let s, o;
361
359
  switch (n.linkReferenceStyle) {
362
360
  case "collapsed":
363
- s = "[" + t + "][]", c = "[" + t + "]: " + a;
361
+ s = "[" + t + "][]", o = "[" + t + "]: " + a;
364
362
  break;
365
363
  case "shortcut":
366
- s = "[" + t + "]", c = "[" + t + "]: " + a;
364
+ s = "[" + t + "]", o = "[" + t + "]: " + a;
367
365
  break;
368
366
  default: {
369
367
  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 + "]";
368
+ const m = r.urlReferenceIdMap.get(a);
369
+ n.linkReferenceDeduplication === "full" && m ? (u = m, o = "[" + u + "]: " + i + l) : (u = r.references.length + 1, r.urlReferenceIdMap.set(a, u), o = "[" + u + "]: " + i + l, r.references.push(o)), s = "[" + t + "][" + u + "]";
372
370
  break;
373
371
  }
374
372
  }
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;
373
+ return n.linkReferenceStyle !== "full" && (n.linkReferenceDeduplication === "full" ? r.urlReferenceIdMap.has(a) || (r.urlReferenceIdMap.set(a, 1), r.references.push(o)) : r.references.push(o)), s;
376
374
  },
377
375
  references: [],
378
376
  urlReferenceIdMap: /* @__PURE__ */ new Map(),
379
377
  append: () => {
380
- const t = k;
378
+ const t = R;
381
379
  let e = "";
382
380
  return t.references && t.references.length && (e = `
383
381
 
@@ -387,7 +385,7 @@ const k = {
387
385
  `, t.references = [], t.urlReferenceIdMap = /* @__PURE__ */ new Map()), e;
388
386
  }
389
387
  };
390
- f.referenceLink = k;
388
+ f.referenceLink = R;
391
389
  f.emphasis = {
392
390
  filter: ["em", "i"],
393
391
  replacement: (t, e, n) => (t = t.trim(), t ? n.emDelimiter + t + n.emDelimiter : "")
@@ -412,7 +410,7 @@ f.code = {
412
410
  f.image = {
413
411
  filter: "img",
414
412
  replacement: function(t, e) {
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 + '"' : "";
413
+ const n = e.getAttribute("alt"), r = n ? g(n) : "", i = e.getAttribute("src") || "", l = e.getAttribute("title"), c = l ? g(l) : "", a = c ? ' "' + c + '"' : "";
416
414
  return i ? "![" + r + "](" + i + a + ")" : "";
417
415
  }
418
416
  };
@@ -463,7 +461,7 @@ class K {
463
461
  replacement: this.markdownIncludingHtmlReplacement
464
462
  };
465
463
  let 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;
464
+ return (n = N(this.array, e, this.options)) || (n = N(this._keep, e, this.options)) || (n = N(this._remove, e, this.options)) ? n : this.defaultRule;
467
465
  }
468
466
  /// Check if an element is unsupported for Markdown conversion.
469
467
  isUnsupportedElement(e) {
@@ -510,7 +508,7 @@ class K {
510
508
  e(this.array[n], n);
511
509
  }
512
510
  }
513
- function g(t, e, n) {
511
+ function N(t, e, n) {
514
512
  for (let r = 0; r < t.length; r++) {
515
513
  const i = t[r];
516
514
  if (j(i, e, n)) return i;
@@ -532,41 +530,41 @@ function j(t, e, n) {
532
530
  return !1;
533
531
  }
534
532
  function Y(t) {
535
- const e = t.element, n = t.isBlock, r = t.isVoid, i = t.isPre || function(c) {
536
- return c.nodeName === "PRE";
533
+ const e = t.element, n = t.isBlock, r = t.isVoid, i = t.isPre || function(o) {
534
+ return o.nodeName === "PRE";
537
535
  };
538
536
  if (!e.firstChild || i(e)) return;
539
- let l = null, o = !1, a = null, s = C(a, e, i);
537
+ let l = null, c = !1, a = null, s = C(a, e, i);
540
538
  for (; s !== e; ) {
541
539
  if (s.nodeType === p.Text || s.nodeType === p.CDATASection) {
542
540
  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);
541
+ let m = u.data.replace(/[ \r\n\t]+/g, " ");
542
+ if ((!l || / $/.test(l.data)) && !c && m[0] === " " && (m = m.substr(1)), !m) {
543
+ s = T(s);
546
544
  continue;
547
545
  }
548
- u.data = d, l = u;
546
+ u.data = m, l = u;
549
547
  } 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);
548
+ n(s) || s.nodeName === "BR" ? (l && (l.data = l.data.replace(/ $/, "")), l = null, c = !1) : r(s) || i(s) ? (l = null, c = !0) : l && (c = !1);
551
549
  else {
552
- s = N(s);
550
+ s = T(s);
553
551
  continue;
554
552
  }
555
- const c = C(a, s, i);
556
- a = s, s = c;
553
+ const o = C(a, s, i);
554
+ a = s, s = o;
557
555
  }
558
- l && (l.data = l.data.replace(/ $/, ""), l.data || N(l));
556
+ l && (l.data = l.data.replace(/ $/, ""), l.data || T(l));
559
557
  }
560
- function N(t) {
558
+ function T(t) {
561
559
  const e = t.nextSibling ?? t.parentNode;
562
560
  return t.parentNode && t.parentNode.removeChild(t), e;
563
561
  }
564
562
  function C(t, e, n) {
565
563
  return t && t.parentNode === e || n(e) ? e.nextSibling ?? e.parentNode : e.firstChild ?? e.nextSibling ?? e.parentNode;
566
564
  }
567
- const R = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : {};
565
+ const E = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : {};
568
566
  function q() {
569
- const t = typeof R.DOMParser < "u" ? R.DOMParser : void 0;
567
+ const t = typeof E.DOMParser < "u" ? E.DOMParser : void 0;
570
568
  let e = !1;
571
569
  if (!t) return !1;
572
570
  try {
@@ -600,7 +598,7 @@ function Q() {
600
598
  return new e();
601
599
  }
602
600
  }
603
- const X = () => q() ? new R.DOMParser() : Q();
601
+ const X = () => q() ? new E.DOMParser() : Q();
604
602
  function J(t, { preformattedCode: e }) {
605
603
  let n;
606
604
  return typeof t == "string" ? n = ee().parseFromString(
@@ -611,7 +609,7 @@ function J(t, { preformattedCode: e }) {
611
609
  "text/html"
612
610
  ).getElementById("turnish-root") : n = t.cloneNode(!0), Y({
613
611
  element: n,
614
- isBlock: E,
612
+ isBlock: A,
615
613
  isVoid: L,
616
614
  isPre: e ? te : void 0
617
615
  }), n;
@@ -669,15 +667,15 @@ const ne = [
669
667
  let r = "";
670
668
  if (e.attributes && e.attributes.length > 0) {
671
669
  const s = [];
672
- for (let c = 0; c < e.attributes.length; c++) {
673
- const u = e.attributes[c];
670
+ for (let o = 0; o < e.attributes.length; o++) {
671
+ const u = e.attributes[o];
674
672
  s.push(`${u.name}="${u.value}"`);
675
673
  }
676
674
  r = " " + s.join(" ");
677
675
  }
678
676
  r += ' markdown="1"';
679
- const i = `<${n}${r}>`, l = `</${n}>`, o = t.trim(), a = i + `
680
- ` + o + `
677
+ const i = `<${n}${r}>`, l = `</${n}>`, c = t.trim(), a = i + `
678
+ ` + c + `
681
679
  ` + l;
682
680
  return e.isBlock ? `
683
681
 
@@ -787,12 +785,12 @@ class le {
787
785
  const i = H(r, this.options);
788
786
  let l = "";
789
787
  if (i.nodeType === p.Text) {
790
- let o = i.nodeValue ?? "";
788
+ let c = i.nodeValue ?? "";
791
789
  if (r.previousSibling && r.previousSibling.nodeType === p.Element) {
792
790
  const a = r.previousSibling;
793
- a.nodeName === "INPUT" && a.getAttribute("type") === "checkbox" && (o = o.replace(/^\s+/, ""));
791
+ a.nodeName === "INPUT" && a.getAttribute("type") === "checkbox" && (c = c.replace(/^\s+/, ""));
794
792
  }
795
- l = i.isCode ? o : this.escape(o);
793
+ l = i.isCode ? c : this.escape(c);
796
794
  } else i.nodeType === p.Element && (l = this.replacementForNode(i));
797
795
  return x(n, l);
798
796
  }, "");