@siladev/qalam 0.2.1 → 0.3.1

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.js CHANGED
@@ -1,18 +1,1967 @@
1
- import { validateAST as e } from "./schema/index.js";
2
- import { Q as s, a as t } from "./QalamEditor-sYrI0Izl.js";
3
- import { Q as f } from "./QalamRenderer-CbbJYMLn.js";
4
- import { resolveAST as d } from "./resolver/index.js";
5
- import { g as Q, a as p, b as u, i as S, l as g, r as i } from "./lookup-CFbcujyG.js";
1
+ import { validateAST as Yt } from "./schema/index.js";
2
+ import { E as Ce, c as v, f as Ee, g as H, b as _e, i as Ie, P as Pe, d as Le, e as Be, h as He, j as Oe, k as qe, B as De, l as Ne, a as Fe, H as Qe, m as Ze, n as je, I as We, o as Ge, p as Xe, q as Ke, L as Ue } from "./QalamEditor-Cwl4r5om.js";
3
+ import { Q as tn } from "./QalamEditor-Cwl4r5om.js";
4
+ import { Q as rn } from "./QalamRenderer-CbbJYMLn.js";
5
+ import { resolveAST as an } from "./resolver/index.js";
6
+ import { g as on, a as cn, b as hn, i as pn, l as un, r as dn } from "./lookup-CFbcujyG.js";
7
+ function te() {
8
+ return { async: !1, breaks: !1, extensions: null, gfm: !0, hooks: null, pedantic: !1, renderer: null, silent: !1, tokenizer: null, walkTokens: null };
9
+ }
10
+ var P = te();
11
+ function xe(t) {
12
+ P = t;
13
+ }
14
+ var _ = { exec: () => null };
15
+ function k(t, e = "") {
16
+ let n = typeof t == "string" ? t : t.source, s = { replace: (r, i) => {
17
+ let a = typeof i == "string" ? i : i.source;
18
+ return a = a.replace(S.caret, "$1"), n = n.replace(r, a), s;
19
+ }, getRegex: () => new RegExp(n, e) };
20
+ return s;
21
+ }
22
+ var Je = (() => {
23
+ try {
24
+ return !!new RegExp("(?<=1)(?<!1)");
25
+ } catch {
26
+ return !1;
27
+ }
28
+ })(), S = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (t) => new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: (t) => new RegExp(`^ {0,${Math.min(3, t - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), hrRegex: (t) => new RegExp(`^ {0,${Math.min(3, t - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), fencesBeginRegex: (t) => new RegExp(`^ {0,${Math.min(3, t - 1)}}(?:\`\`\`|~~~)`), headingBeginRegex: (t) => new RegExp(`^ {0,${Math.min(3, t - 1)}}#`), htmlBeginRegex: (t) => new RegExp(`^ {0,${Math.min(3, t - 1)}}<(?:[a-z].*>|!--)`, "i"), blockquoteBeginRegex: (t) => new RegExp(`^ {0,${Math.min(3, t - 1)}}>`) }, Ve = /^(?:[ \t]*(?:\n|$))+/, Ye = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, et = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, N = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, tt = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, ne = / {0,3}(?:[*+-]|\d{1,9}[.)])/, me = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, we = k(me).replace(/bull/g, ne).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex(), nt = k(me).replace(/bull/g, ne).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(), re = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, rt = /^[^\n]+/, se = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/, st = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", se).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), it = k(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, ne).getRegex(), G = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", ie = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, at = k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", ie).replace("tag", G).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), be = k(re).replace("hr", N).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", G).getRegex(), lt = k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", be).getRegex(), ae = { blockquote: lt, code: Ye, def: st, fences: et, heading: tt, hr: N, html: at, lheading: we, list: it, newline: Ve, paragraph: be, table: _, text: rt }, he = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", N).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", G).getRegex(), ot = { ...ae, lheading: nt, table: he, paragraph: k(re).replace("hr", N).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", he).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", G).getRegex() }, ct = { ...ae, html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", ie).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: _, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: k(re).replace("hr", N).replace("heading", ` *#{1,6} *[^
29
+ ]`).replace("lheading", we).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() }, ht = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, pt = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, ye = /^( {2,}|\\)\n(?!\s*$)/, ut = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, L = /[\p{P}\p{S}]/u, X = /[\s\p{P}\p{S}]/u, le = /[^\s\p{P}\p{S}]/u, dt = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, X).getRegex(), Te = /(?!~)[\p{P}\p{S}]/u, gt = /(?!~)[\s\p{P}\p{S}]/u, kt = /(?:[^\s\p{P}\p{S}]|~)/u, ft = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Je ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex(), Re = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/, xt = k(Re, "u").replace(/punct/g, L).getRegex(), mt = k(Re, "u").replace(/punct/g, Te).getRegex(), Se = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", wt = k(Se, "gu").replace(/notPunctSpace/g, le).replace(/punctSpace/g, X).replace(/punct/g, L).getRegex(), bt = k(Se, "gu").replace(/notPunctSpace/g, kt).replace(/punctSpace/g, gt).replace(/punct/g, Te).getRegex(), yt = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, le).replace(/punctSpace/g, X).replace(/punct/g, L).getRegex(), Tt = k(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, L).getRegex(), Rt = "^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)", St = k(Rt, "gu").replace(/notPunctSpace/g, le).replace(/punctSpace/g, X).replace(/punct/g, L).getRegex(), $t = k(/\\(punct)/, "gu").replace(/punct/g, L).getRegex(), Mt = k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(), At = k(ie).replace("(?:-->|$)", "-->").getRegex(), zt = k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", At).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), Z = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/, vt = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label", Z).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), $e = k(/^!?\[(label)\]\[(ref)\]/).replace("label", Z).replace("ref", se).getRegex(), Me = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", se).getRegex(), Ct = k("reflink|nolink(?!\\()", "g").replace("reflink", $e).replace("nolink", Me).getRegex(), pe = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/, oe = { _backpedal: _, anyPunctuation: $t, autolink: Mt, blockSkip: ft, br: ye, code: pt, del: _, delLDelim: _, delRDelim: _, emStrongLDelim: xt, emStrongRDelimAst: wt, emStrongRDelimUnd: yt, escape: ht, link: vt, nolink: Me, punctuation: dt, reflink: $e, reflinkSearch: Ct, tag: zt, text: ut, url: _ }, Et = { ...oe, link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", Z).getRegex(), reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", Z).getRegex() }, V = { ...oe, emStrongRDelimAst: bt, emStrongLDelim: mt, delLDelim: Tt, delRDelim: St, url: k(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", pe).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: k(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", pe).getRegex() }, _t = { ...V, br: k(ye).replace("{2,}", "*").getRegex(), text: k(V.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() }, F = { normal: ae, gfm: ot, pedantic: ct }, O = { normal: oe, gfm: V, breaks: _t, pedantic: Et }, It = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, ue = (t) => It[t];
30
+ function z(t, e) {
31
+ if (e) {
32
+ if (S.escapeTest.test(t)) return t.replace(S.escapeReplace, ue);
33
+ } else if (S.escapeTestNoEncode.test(t)) return t.replace(S.escapeReplaceNoEncode, ue);
34
+ return t;
35
+ }
36
+ function de(t) {
37
+ try {
38
+ t = encodeURI(t).replace(S.percentDecode, "%");
39
+ } catch {
40
+ return null;
41
+ }
42
+ return t;
43
+ }
44
+ function ge(t, e) {
45
+ let n = t.replace(S.findPipe, (i, a, o) => {
46
+ let l = !1, h = a;
47
+ for (; --h >= 0 && o[h] === "\\"; ) l = !l;
48
+ return l ? "|" : " |";
49
+ }), s = n.split(S.splitPipe), r = 0;
50
+ if (s[0].trim() || s.shift(), s.length > 0 && !s.at(-1)?.trim() && s.pop(), e) if (s.length > e) s.splice(e);
51
+ else for (; s.length < e; ) s.push("");
52
+ for (; r < s.length; r++) s[r] = s[r].trim().replace(S.slashPipe, "|");
53
+ return s;
54
+ }
55
+ function q(t, e, n) {
56
+ let s = t.length;
57
+ if (s === 0) return "";
58
+ let r = 0;
59
+ for (; r < s && t.charAt(s - r - 1) === e; )
60
+ r++;
61
+ return t.slice(0, s - r);
62
+ }
63
+ function Pt(t, e) {
64
+ if (t.indexOf(e[1]) === -1) return -1;
65
+ let n = 0;
66
+ for (let s = 0; s < t.length; s++) if (t[s] === "\\") s++;
67
+ else if (t[s] === e[0]) n++;
68
+ else if (t[s] === e[1] && (n--, n < 0)) return s;
69
+ return n > 0 ? -2 : -1;
70
+ }
71
+ function Lt(t, e = 0) {
72
+ let n = e, s = "";
73
+ for (let r of t) if (r === " ") {
74
+ let i = 4 - n % 4;
75
+ s += " ".repeat(i), n += i;
76
+ } else s += r, n++;
77
+ return s;
78
+ }
79
+ function ke(t, e, n, s, r) {
80
+ let i = e.href, a = e.title || null, o = t[1].replace(r.other.outputLinkReplace, "$1");
81
+ s.state.inLink = !0;
82
+ let l = { type: t[0].charAt(0) === "!" ? "image" : "link", raw: n, href: i, title: a, text: o, tokens: s.inlineTokens(o) };
83
+ return s.state.inLink = !1, l;
84
+ }
85
+ function Bt(t, e, n) {
86
+ let s = t.match(n.other.indentCodeCompensation);
87
+ if (s === null) return e;
88
+ let r = s[1];
89
+ return e.split(`
90
+ `).map((i) => {
91
+ let a = i.match(n.other.beginningSpace);
92
+ if (a === null) return i;
93
+ let [o] = a;
94
+ return o.length >= r.length ? i.slice(r.length) : i;
95
+ }).join(`
96
+ `);
97
+ }
98
+ var j = class {
99
+ options;
100
+ rules;
101
+ lexer;
102
+ constructor(t) {
103
+ this.options = t || P;
104
+ }
105
+ space(t) {
106
+ let e = this.rules.block.newline.exec(t);
107
+ if (e && e[0].length > 0) return { type: "space", raw: e[0] };
108
+ }
109
+ code(t) {
110
+ let e = this.rules.block.code.exec(t);
111
+ if (e) {
112
+ let n = e[0].replace(this.rules.other.codeRemoveIndent, "");
113
+ return { type: "code", raw: e[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : q(n, `
114
+ `) };
115
+ }
116
+ }
117
+ fences(t) {
118
+ let e = this.rules.block.fences.exec(t);
119
+ if (e) {
120
+ let n = e[0], s = Bt(n, e[3] || "", this.rules);
121
+ return { type: "code", raw: n, lang: e[2] ? e[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : e[2], text: s };
122
+ }
123
+ }
124
+ heading(t) {
125
+ let e = this.rules.block.heading.exec(t);
126
+ if (e) {
127
+ let n = e[2].trim();
128
+ if (this.rules.other.endingHash.test(n)) {
129
+ let s = q(n, "#");
130
+ (this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
131
+ }
132
+ return { type: "heading", raw: e[0], depth: e[1].length, text: n, tokens: this.lexer.inline(n) };
133
+ }
134
+ }
135
+ hr(t) {
136
+ let e = this.rules.block.hr.exec(t);
137
+ if (e) return { type: "hr", raw: q(e[0], `
138
+ `) };
139
+ }
140
+ blockquote(t) {
141
+ let e = this.rules.block.blockquote.exec(t);
142
+ if (e) {
143
+ let n = q(e[0], `
144
+ `).split(`
145
+ `), s = "", r = "", i = [];
146
+ for (; n.length > 0; ) {
147
+ let a = !1, o = [], l;
148
+ for (l = 0; l < n.length; l++) if (this.rules.other.blockquoteStart.test(n[l])) o.push(n[l]), a = !0;
149
+ else if (!a) o.push(n[l]);
150
+ else break;
151
+ n = n.slice(l);
152
+ let h = o.join(`
153
+ `), c = h.replace(this.rules.other.blockquoteSetextReplace, `
154
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
155
+ s = s ? `${s}
156
+ ${h}` : h, r = r ? `${r}
157
+ ${c}` : c;
158
+ let p = this.lexer.state.top;
159
+ if (this.lexer.state.top = !0, this.lexer.blockTokens(c, i, !0), this.lexer.state.top = p, n.length === 0) break;
160
+ let u = i.at(-1);
161
+ if (u?.type === "code") break;
162
+ if (u?.type === "blockquote") {
163
+ let g = u, f = g.raw + `
164
+ ` + n.join(`
165
+ `), w = this.blockquote(f);
166
+ i[i.length - 1] = w, s = s.substring(0, s.length - g.raw.length) + w.raw, r = r.substring(0, r.length - g.text.length) + w.text;
167
+ break;
168
+ } else if (u?.type === "list") {
169
+ let g = u, f = g.raw + `
170
+ ` + n.join(`
171
+ `), w = this.list(f);
172
+ i[i.length - 1] = w, s = s.substring(0, s.length - u.raw.length) + w.raw, r = r.substring(0, r.length - g.raw.length) + w.raw, n = f.substring(i.at(-1).raw.length).split(`
173
+ `);
174
+ continue;
175
+ }
176
+ }
177
+ return { type: "blockquote", raw: s, tokens: i, text: r };
178
+ }
179
+ }
180
+ list(t) {
181
+ let e = this.rules.block.list.exec(t);
182
+ if (e) {
183
+ let n = e[1].trim(), s = n.length > 1, r = { type: "list", raw: "", ordered: s, start: s ? +n.slice(0, -1) : "", loose: !1, items: [] };
184
+ n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
185
+ let i = this.rules.other.listItemRegex(n), a = !1;
186
+ for (; t; ) {
187
+ let l = !1, h = "", c = "";
188
+ if (!(e = i.exec(t)) || this.rules.block.hr.test(t)) break;
189
+ h = e[0], t = t.substring(h.length);
190
+ let p = Lt(e[2].split(`
191
+ `, 1)[0], e[1].length), u = t.split(`
192
+ `, 1)[0], g = !p.trim(), f = 0;
193
+ if (this.options.pedantic ? (f = 2, c = p.trimStart()) : g ? f = e[1].length + 1 : (f = p.search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = p.slice(f), f += e[1].length), g && this.rules.other.blankLine.test(u) && (h += u + `
194
+ `, t = t.substring(u.length + 1), l = !0), !l) {
195
+ let w = this.rules.other.nextBulletRegex(f), y = this.rules.other.hrRegex(f), b = this.rules.other.fencesBeginRegex(f), T = this.rules.other.headingBeginRegex(f), R = this.rules.other.htmlBeginRegex(f), $ = this.rules.other.blockquoteBeginRegex(f);
196
+ for (; t; ) {
197
+ let d = t.split(`
198
+ `, 1)[0], m;
199
+ if (u = d, this.options.pedantic ? (u = u.replace(this.rules.other.listReplaceNesting, " "), m = u) : m = u.replace(this.rules.other.tabCharGlobal, " "), b.test(u) || T.test(u) || R.test(u) || $.test(u) || w.test(u) || y.test(u)) break;
200
+ if (m.search(this.rules.other.nonSpaceChar) >= f || !u.trim()) c += `
201
+ ` + m.slice(f);
202
+ else {
203
+ if (g || p.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || b.test(p) || T.test(p) || y.test(p)) break;
204
+ c += `
205
+ ` + u;
206
+ }
207
+ g = !u.trim(), h += d + `
208
+ `, t = t.substring(d.length + 1), p = m.slice(f);
209
+ }
210
+ }
211
+ r.loose || (a ? r.loose = !0 : this.rules.other.doubleBlankLine.test(h) && (a = !0)), r.items.push({ type: "list_item", raw: h, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: !1, text: c, tokens: [] }), r.raw += h;
212
+ }
213
+ let o = r.items.at(-1);
214
+ if (o) o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
215
+ else return;
216
+ r.raw = r.raw.trimEnd();
217
+ for (let l of r.items) {
218
+ if (this.lexer.state.top = !1, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
219
+ if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
220
+ l.tokens[0].raw = l.tokens[0].raw.replace(this.rules.other.listReplaceTask, ""), l.tokens[0].text = l.tokens[0].text.replace(this.rules.other.listReplaceTask, "");
221
+ for (let c = this.lexer.inlineQueue.length - 1; c >= 0; c--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
222
+ this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
223
+ break;
224
+ }
225
+ }
226
+ let h = this.rules.other.listTaskCheckbox.exec(l.raw);
227
+ if (h) {
228
+ let c = { type: "checkbox", raw: h[0] + " ", checked: h[0] !== "[ ]" };
229
+ l.checked = c.checked, r.loose ? l.tokens[0] && ["paragraph", "text"].includes(l.tokens[0].type) && "tokens" in l.tokens[0] && l.tokens[0].tokens ? (l.tokens[0].raw = c.raw + l.tokens[0].raw, l.tokens[0].text = c.raw + l.tokens[0].text, l.tokens[0].tokens.unshift(c)) : l.tokens.unshift({ type: "paragraph", raw: c.raw, text: c.raw, tokens: [c] }) : l.tokens.unshift(c);
230
+ }
231
+ }
232
+ if (!r.loose) {
233
+ let h = l.tokens.filter((p) => p.type === "space"), c = h.length > 0 && h.some((p) => this.rules.other.anyLine.test(p.raw));
234
+ r.loose = c;
235
+ }
236
+ }
237
+ if (r.loose) for (let l of r.items) {
238
+ l.loose = !0;
239
+ for (let h of l.tokens) h.type === "text" && (h.type = "paragraph");
240
+ }
241
+ return r;
242
+ }
243
+ }
244
+ html(t) {
245
+ let e = this.rules.block.html.exec(t);
246
+ if (e) return { type: "html", block: !0, raw: e[0], pre: e[1] === "pre" || e[1] === "script" || e[1] === "style", text: e[0] };
247
+ }
248
+ def(t) {
249
+ let e = this.rules.block.def.exec(t);
250
+ if (e) {
251
+ let n = e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), s = e[2] ? e[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = e[3] ? e[3].substring(1, e[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : e[3];
252
+ return { type: "def", tag: n, raw: e[0], href: s, title: r };
253
+ }
254
+ }
255
+ table(t) {
256
+ let e = this.rules.block.table.exec(t);
257
+ if (!e || !this.rules.other.tableDelimiter.test(e[2])) return;
258
+ let n = ge(e[1]), s = e[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = e[3]?.trim() ? e[3].replace(this.rules.other.tableRowBlankLine, "").split(`
259
+ `) : [], i = { type: "table", raw: e[0], header: [], align: [], rows: [] };
260
+ if (n.length === s.length) {
261
+ for (let a of s) this.rules.other.tableAlignRight.test(a) ? i.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? i.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? i.align.push("left") : i.align.push(null);
262
+ for (let a = 0; a < n.length; a++) i.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: !0, align: i.align[a] });
263
+ for (let a of r) i.rows.push(ge(a, i.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: !1, align: i.align[l] })));
264
+ return i;
265
+ }
266
+ }
267
+ lheading(t) {
268
+ let e = this.rules.block.lheading.exec(t);
269
+ if (e) {
270
+ let n = e[1].trim();
271
+ return { type: "heading", raw: e[0], depth: e[2].charAt(0) === "=" ? 1 : 2, text: n, tokens: this.lexer.inline(n) };
272
+ }
273
+ }
274
+ paragraph(t) {
275
+ let e = this.rules.block.paragraph.exec(t);
276
+ if (e) {
277
+ let n = e[1].charAt(e[1].length - 1) === `
278
+ ` ? e[1].slice(0, -1) : e[1];
279
+ return { type: "paragraph", raw: e[0], text: n, tokens: this.lexer.inline(n) };
280
+ }
281
+ }
282
+ text(t) {
283
+ let e = this.rules.block.text.exec(t);
284
+ if (e) return { type: "text", raw: e[0], text: e[0], tokens: this.lexer.inline(e[0]) };
285
+ }
286
+ escape(t) {
287
+ let e = this.rules.inline.escape.exec(t);
288
+ if (e) return { type: "escape", raw: e[0], text: e[1] };
289
+ }
290
+ tag(t) {
291
+ let e = this.rules.inline.tag.exec(t);
292
+ if (e) return !this.lexer.state.inLink && this.rules.other.startATag.test(e[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && this.rules.other.endATag.test(e[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(e[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(e[0]) && (this.lexer.state.inRawBlock = !1), { type: "html", raw: e[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: !1, text: e[0] };
293
+ }
294
+ link(t) {
295
+ let e = this.rules.inline.link.exec(t);
296
+ if (e) {
297
+ let n = e[2].trim();
298
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
299
+ if (!this.rules.other.endAngleBracket.test(n)) return;
300
+ let i = q(n.slice(0, -1), "\\");
301
+ if ((n.length - i.length) % 2 === 0) return;
302
+ } else {
303
+ let i = Pt(e[2], "()");
304
+ if (i === -2) return;
305
+ if (i > -1) {
306
+ let a = (e[0].indexOf("!") === 0 ? 5 : 4) + e[1].length + i;
307
+ e[2] = e[2].substring(0, i), e[0] = e[0].substring(0, a).trim(), e[3] = "";
308
+ }
309
+ }
310
+ let s = e[2], r = "";
311
+ if (this.options.pedantic) {
312
+ let i = this.rules.other.pedanticHrefTitle.exec(s);
313
+ i && (s = i[1], r = i[3]);
314
+ } else r = e[3] ? e[3].slice(1, -1) : "";
315
+ return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), ke(e, { href: s && s.replace(this.rules.inline.anyPunctuation, "$1"), title: r && r.replace(this.rules.inline.anyPunctuation, "$1") }, e[0], this.lexer, this.rules);
316
+ }
317
+ }
318
+ reflink(t, e) {
319
+ let n;
320
+ if ((n = this.rules.inline.reflink.exec(t)) || (n = this.rules.inline.nolink.exec(t))) {
321
+ let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), r = e[s.toLowerCase()];
322
+ if (!r) {
323
+ let i = n[0].charAt(0);
324
+ return { type: "text", raw: i, text: i };
325
+ }
326
+ return ke(n, r, n[0], this.lexer, this.rules);
327
+ }
328
+ }
329
+ emStrong(t, e, n = "") {
330
+ let s = this.rules.inline.emStrongLDelim.exec(t);
331
+ if (!(!s || !s[1] && !s[2] && !s[3] && !s[4] || s[4] && n.match(this.rules.other.unicodeAlphaNumeric)) && (!(s[1] || s[3]) || !n || this.rules.inline.punctuation.exec(n))) {
332
+ let r = [...s[0]].length - 1, i, a, o = r, l = 0, h = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
333
+ for (h.lastIndex = 0, e = e.slice(-1 * t.length + r); (s = h.exec(e)) != null; ) {
334
+ if (i = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !i) continue;
335
+ if (a = [...i].length, s[3] || s[4]) {
336
+ o += a;
337
+ continue;
338
+ } else if ((s[5] || s[6]) && r % 3 && !((r + a) % 3)) {
339
+ l += a;
340
+ continue;
341
+ }
342
+ if (o -= a, o > 0) continue;
343
+ a = Math.min(a, a + o + l);
344
+ let c = [...s[0]][0].length, p = t.slice(0, r + s.index + c + a);
345
+ if (Math.min(r, a) % 2) {
346
+ let g = p.slice(1, -1);
347
+ return { type: "em", raw: p, text: g, tokens: this.lexer.inlineTokens(g) };
348
+ }
349
+ let u = p.slice(2, -2);
350
+ return { type: "strong", raw: p, text: u, tokens: this.lexer.inlineTokens(u) };
351
+ }
352
+ }
353
+ }
354
+ codespan(t) {
355
+ let e = this.rules.inline.code.exec(t);
356
+ if (e) {
357
+ let n = e[2].replace(this.rules.other.newLineCharGlobal, " "), s = this.rules.other.nonSpaceChar.test(n), r = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
358
+ return s && r && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: e[0], text: n };
359
+ }
360
+ }
361
+ br(t) {
362
+ let e = this.rules.inline.br.exec(t);
363
+ if (e) return { type: "br", raw: e[0] };
364
+ }
365
+ del(t, e, n = "") {
366
+ let s = this.rules.inline.delLDelim.exec(t);
367
+ if (s && (!s[1] || !n || this.rules.inline.punctuation.exec(n))) {
368
+ let r = [...s[0]].length - 1, i, a, o = r, l = this.rules.inline.delRDelim;
369
+ for (l.lastIndex = 0, e = e.slice(-1 * t.length + r); (s = l.exec(e)) != null; ) {
370
+ if (i = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !i || (a = [...i].length, a !== r)) continue;
371
+ if (s[3] || s[4]) {
372
+ o += a;
373
+ continue;
374
+ }
375
+ if (o -= a, o > 0) continue;
376
+ a = Math.min(a, a + o);
377
+ let h = [...s[0]][0].length, c = t.slice(0, r + s.index + h + a), p = c.slice(r, -r);
378
+ return { type: "del", raw: c, text: p, tokens: this.lexer.inlineTokens(p) };
379
+ }
380
+ }
381
+ }
382
+ autolink(t) {
383
+ let e = this.rules.inline.autolink.exec(t);
384
+ if (e) {
385
+ let n, s;
386
+ return e[2] === "@" ? (n = e[1], s = "mailto:" + n) : (n = e[1], s = n), { type: "link", raw: e[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
387
+ }
388
+ }
389
+ url(t) {
390
+ let e;
391
+ if (e = this.rules.inline.url.exec(t)) {
392
+ let n, s;
393
+ if (e[2] === "@") n = e[0], s = "mailto:" + n;
394
+ else {
395
+ let r;
396
+ do
397
+ r = e[0], e[0] = this.rules.inline._backpedal.exec(e[0])?.[0] ?? "";
398
+ while (r !== e[0]);
399
+ n = e[0], e[1] === "www." ? s = "http://" + e[0] : s = e[0];
400
+ }
401
+ return { type: "link", raw: e[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
402
+ }
403
+ }
404
+ inlineText(t) {
405
+ let e = this.rules.inline.text.exec(t);
406
+ if (e) {
407
+ let n = this.lexer.state.inRawBlock;
408
+ return { type: "text", raw: e[0], text: e[0], escaped: n };
409
+ }
410
+ }
411
+ }, M = class Y {
412
+ tokens;
413
+ options;
414
+ state;
415
+ inlineQueue;
416
+ tokenizer;
417
+ constructor(e) {
418
+ this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || P, this.options.tokenizer = this.options.tokenizer || new j(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: !1, inRawBlock: !1, top: !0 };
419
+ let n = { other: S, block: F.normal, inline: O.normal };
420
+ this.options.pedantic ? (n.block = F.pedantic, n.inline = O.pedantic) : this.options.gfm && (n.block = F.gfm, this.options.breaks ? n.inline = O.breaks : n.inline = O.gfm), this.tokenizer.rules = n;
421
+ }
422
+ static get rules() {
423
+ return { block: F, inline: O };
424
+ }
425
+ static lex(e, n) {
426
+ return new Y(n).lex(e);
427
+ }
428
+ static lexInline(e, n) {
429
+ return new Y(n).inlineTokens(e);
430
+ }
431
+ lex(e) {
432
+ e = e.replace(S.carriageReturn, `
433
+ `), this.blockTokens(e, this.tokens);
434
+ for (let n = 0; n < this.inlineQueue.length; n++) {
435
+ let s = this.inlineQueue[n];
436
+ this.inlineTokens(s.src, s.tokens);
437
+ }
438
+ return this.inlineQueue = [], this.tokens;
439
+ }
440
+ blockTokens(e, n = [], s = !1) {
441
+ for (this.tokenizer.lexer = this, this.options.pedantic && (e = e.replace(S.tabCharGlobal, " ").replace(S.spaceLine, "")); e; ) {
442
+ let r;
443
+ if (this.options.extensions?.block?.some((a) => (r = a.call({ lexer: this }, e, n)) ? (e = e.substring(r.raw.length), n.push(r), !0) : !1)) continue;
444
+ if (r = this.tokenizer.space(e)) {
445
+ e = e.substring(r.raw.length);
446
+ let a = n.at(-1);
447
+ r.raw.length === 1 && a !== void 0 ? a.raw += `
448
+ ` : n.push(r);
449
+ continue;
450
+ }
451
+ if (r = this.tokenizer.code(e)) {
452
+ e = e.substring(r.raw.length);
453
+ let a = n.at(-1);
454
+ a?.type === "paragraph" || a?.type === "text" ? (a.raw += (a.raw.endsWith(`
455
+ `) ? "" : `
456
+ `) + r.raw, a.text += `
457
+ ` + r.text, this.inlineQueue.at(-1).src = a.text) : n.push(r);
458
+ continue;
459
+ }
460
+ if (r = this.tokenizer.fences(e)) {
461
+ e = e.substring(r.raw.length), n.push(r);
462
+ continue;
463
+ }
464
+ if (r = this.tokenizer.heading(e)) {
465
+ e = e.substring(r.raw.length), n.push(r);
466
+ continue;
467
+ }
468
+ if (r = this.tokenizer.hr(e)) {
469
+ e = e.substring(r.raw.length), n.push(r);
470
+ continue;
471
+ }
472
+ if (r = this.tokenizer.blockquote(e)) {
473
+ e = e.substring(r.raw.length), n.push(r);
474
+ continue;
475
+ }
476
+ if (r = this.tokenizer.list(e)) {
477
+ e = e.substring(r.raw.length), n.push(r);
478
+ continue;
479
+ }
480
+ if (r = this.tokenizer.html(e)) {
481
+ e = e.substring(r.raw.length), n.push(r);
482
+ continue;
483
+ }
484
+ if (r = this.tokenizer.def(e)) {
485
+ e = e.substring(r.raw.length);
486
+ let a = n.at(-1);
487
+ a?.type === "paragraph" || a?.type === "text" ? (a.raw += (a.raw.endsWith(`
488
+ `) ? "" : `
489
+ `) + r.raw, a.text += `
490
+ ` + r.raw, this.inlineQueue.at(-1).src = a.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, n.push(r));
491
+ continue;
492
+ }
493
+ if (r = this.tokenizer.table(e)) {
494
+ e = e.substring(r.raw.length), n.push(r);
495
+ continue;
496
+ }
497
+ if (r = this.tokenizer.lheading(e)) {
498
+ e = e.substring(r.raw.length), n.push(r);
499
+ continue;
500
+ }
501
+ let i = e;
502
+ if (this.options.extensions?.startBlock) {
503
+ let a = 1 / 0, o = e.slice(1), l;
504
+ this.options.extensions.startBlock.forEach((h) => {
505
+ l = h.call({ lexer: this }, o), typeof l == "number" && l >= 0 && (a = Math.min(a, l));
506
+ }), a < 1 / 0 && a >= 0 && (i = e.substring(0, a + 1));
507
+ }
508
+ if (this.state.top && (r = this.tokenizer.paragraph(i))) {
509
+ let a = n.at(-1);
510
+ s && a?.type === "paragraph" ? (a.raw += (a.raw.endsWith(`
511
+ `) ? "" : `
512
+ `) + r.raw, a.text += `
513
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = a.text) : n.push(r), s = i.length !== e.length, e = e.substring(r.raw.length);
514
+ continue;
515
+ }
516
+ if (r = this.tokenizer.text(e)) {
517
+ e = e.substring(r.raw.length);
518
+ let a = n.at(-1);
519
+ a?.type === "text" ? (a.raw += (a.raw.endsWith(`
520
+ `) ? "" : `
521
+ `) + r.raw, a.text += `
522
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = a.text) : n.push(r);
523
+ continue;
524
+ }
525
+ if (e) {
526
+ let a = "Infinite loop on byte: " + e.charCodeAt(0);
527
+ if (this.options.silent) {
528
+ console.error(a);
529
+ break;
530
+ } else throw new Error(a);
531
+ }
532
+ }
533
+ return this.state.top = !0, n;
534
+ }
535
+ inline(e, n = []) {
536
+ return this.inlineQueue.push({ src: e, tokens: n }), n;
537
+ }
538
+ inlineTokens(e, n = []) {
539
+ this.tokenizer.lexer = this;
540
+ let s = e, r = null;
541
+ if (this.tokens.links) {
542
+ let l = Object.keys(this.tokens.links);
543
+ if (l.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(s)) != null; ) l.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (s = s.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
544
+ }
545
+ for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(s)) != null; ) s = s.slice(0, r.index) + "++" + s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
546
+ let i;
547
+ for (; (r = this.tokenizer.rules.inline.blockSkip.exec(s)) != null; ) i = r[2] ? r[2].length : 0, s = s.slice(0, r.index + i) + "[" + "a".repeat(r[0].length - i - 2) + "]" + s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
548
+ s = this.options.hooks?.emStrongMask?.call({ lexer: this }, s) ?? s;
549
+ let a = !1, o = "";
550
+ for (; e; ) {
551
+ a || (o = ""), a = !1;
552
+ let l;
553
+ if (this.options.extensions?.inline?.some((c) => (l = c.call({ lexer: this }, e, n)) ? (e = e.substring(l.raw.length), n.push(l), !0) : !1)) continue;
554
+ if (l = this.tokenizer.escape(e)) {
555
+ e = e.substring(l.raw.length), n.push(l);
556
+ continue;
557
+ }
558
+ if (l = this.tokenizer.tag(e)) {
559
+ e = e.substring(l.raw.length), n.push(l);
560
+ continue;
561
+ }
562
+ if (l = this.tokenizer.link(e)) {
563
+ e = e.substring(l.raw.length), n.push(l);
564
+ continue;
565
+ }
566
+ if (l = this.tokenizer.reflink(e, this.tokens.links)) {
567
+ e = e.substring(l.raw.length);
568
+ let c = n.at(-1);
569
+ l.type === "text" && c?.type === "text" ? (c.raw += l.raw, c.text += l.text) : n.push(l);
570
+ continue;
571
+ }
572
+ if (l = this.tokenizer.emStrong(e, s, o)) {
573
+ e = e.substring(l.raw.length), n.push(l);
574
+ continue;
575
+ }
576
+ if (l = this.tokenizer.codespan(e)) {
577
+ e = e.substring(l.raw.length), n.push(l);
578
+ continue;
579
+ }
580
+ if (l = this.tokenizer.br(e)) {
581
+ e = e.substring(l.raw.length), n.push(l);
582
+ continue;
583
+ }
584
+ if (l = this.tokenizer.del(e, s, o)) {
585
+ e = e.substring(l.raw.length), n.push(l);
586
+ continue;
587
+ }
588
+ if (l = this.tokenizer.autolink(e)) {
589
+ e = e.substring(l.raw.length), n.push(l);
590
+ continue;
591
+ }
592
+ if (!this.state.inLink && (l = this.tokenizer.url(e))) {
593
+ e = e.substring(l.raw.length), n.push(l);
594
+ continue;
595
+ }
596
+ let h = e;
597
+ if (this.options.extensions?.startInline) {
598
+ let c = 1 / 0, p = e.slice(1), u;
599
+ this.options.extensions.startInline.forEach((g) => {
600
+ u = g.call({ lexer: this }, p), typeof u == "number" && u >= 0 && (c = Math.min(c, u));
601
+ }), c < 1 / 0 && c >= 0 && (h = e.substring(0, c + 1));
602
+ }
603
+ if (l = this.tokenizer.inlineText(h)) {
604
+ e = e.substring(l.raw.length), l.raw.slice(-1) !== "_" && (o = l.raw.slice(-1)), a = !0;
605
+ let c = n.at(-1);
606
+ c?.type === "text" ? (c.raw += l.raw, c.text += l.text) : n.push(l);
607
+ continue;
608
+ }
609
+ if (e) {
610
+ let c = "Infinite loop on byte: " + e.charCodeAt(0);
611
+ if (this.options.silent) {
612
+ console.error(c);
613
+ break;
614
+ } else throw new Error(c);
615
+ }
616
+ }
617
+ return n;
618
+ }
619
+ }, W = class {
620
+ options;
621
+ parser;
622
+ constructor(t) {
623
+ this.options = t || P;
624
+ }
625
+ space(t) {
626
+ return "";
627
+ }
628
+ code({ text: t, lang: e, escaped: n }) {
629
+ let s = (e || "").match(S.notSpaceStart)?.[0], r = t.replace(S.endingNewline, "") + `
630
+ `;
631
+ return s ? '<pre><code class="language-' + z(s) + '">' + (n ? r : z(r, !0)) + `</code></pre>
632
+ ` : "<pre><code>" + (n ? r : z(r, !0)) + `</code></pre>
633
+ `;
634
+ }
635
+ blockquote({ tokens: t }) {
636
+ return `<blockquote>
637
+ ${this.parser.parse(t)}</blockquote>
638
+ `;
639
+ }
640
+ html({ text: t }) {
641
+ return t;
642
+ }
643
+ def(t) {
644
+ return "";
645
+ }
646
+ heading({ tokens: t, depth: e }) {
647
+ return `<h${e}>${this.parser.parseInline(t)}</h${e}>
648
+ `;
649
+ }
650
+ hr(t) {
651
+ return `<hr>
652
+ `;
653
+ }
654
+ list(t) {
655
+ let e = t.ordered, n = t.start, s = "";
656
+ for (let a = 0; a < t.items.length; a++) {
657
+ let o = t.items[a];
658
+ s += this.listitem(o);
659
+ }
660
+ let r = e ? "ol" : "ul", i = e && n !== 1 ? ' start="' + n + '"' : "";
661
+ return "<" + r + i + `>
662
+ ` + s + "</" + r + `>
663
+ `;
664
+ }
665
+ listitem(t) {
666
+ return `<li>${this.parser.parse(t.tokens)}</li>
667
+ `;
668
+ }
669
+ checkbox({ checked: t }) {
670
+ return "<input " + (t ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
671
+ }
672
+ paragraph({ tokens: t }) {
673
+ return `<p>${this.parser.parseInline(t)}</p>
674
+ `;
675
+ }
676
+ table(t) {
677
+ let e = "", n = "";
678
+ for (let r = 0; r < t.header.length; r++) n += this.tablecell(t.header[r]);
679
+ e += this.tablerow({ text: n });
680
+ let s = "";
681
+ for (let r = 0; r < t.rows.length; r++) {
682
+ let i = t.rows[r];
683
+ n = "";
684
+ for (let a = 0; a < i.length; a++) n += this.tablecell(i[a]);
685
+ s += this.tablerow({ text: n });
686
+ }
687
+ return s && (s = `<tbody>${s}</tbody>`), `<table>
688
+ <thead>
689
+ ` + e + `</thead>
690
+ ` + s + `</table>
691
+ `;
692
+ }
693
+ tablerow({ text: t }) {
694
+ return `<tr>
695
+ ${t}</tr>
696
+ `;
697
+ }
698
+ tablecell(t) {
699
+ let e = this.parser.parseInline(t.tokens), n = t.header ? "th" : "td";
700
+ return (t.align ? `<${n} align="${t.align}">` : `<${n}>`) + e + `</${n}>
701
+ `;
702
+ }
703
+ strong({ tokens: t }) {
704
+ return `<strong>${this.parser.parseInline(t)}</strong>`;
705
+ }
706
+ em({ tokens: t }) {
707
+ return `<em>${this.parser.parseInline(t)}</em>`;
708
+ }
709
+ codespan({ text: t }) {
710
+ return `<code>${z(t, !0)}</code>`;
711
+ }
712
+ br(t) {
713
+ return "<br>";
714
+ }
715
+ del({ tokens: t }) {
716
+ return `<del>${this.parser.parseInline(t)}</del>`;
717
+ }
718
+ link({ href: t, title: e, tokens: n }) {
719
+ let s = this.parser.parseInline(n), r = de(t);
720
+ if (r === null) return s;
721
+ t = r;
722
+ let i = '<a href="' + t + '"';
723
+ return e && (i += ' title="' + z(e) + '"'), i += ">" + s + "</a>", i;
724
+ }
725
+ image({ href: t, title: e, text: n, tokens: s }) {
726
+ s && (n = this.parser.parseInline(s, this.parser.textRenderer));
727
+ let r = de(t);
728
+ if (r === null) return z(n);
729
+ t = r;
730
+ let i = `<img src="${t}" alt="${z(n)}"`;
731
+ return e && (i += ` title="${z(e)}"`), i += ">", i;
732
+ }
733
+ text(t) {
734
+ return "tokens" in t && t.tokens ? this.parser.parseInline(t.tokens) : "escaped" in t && t.escaped ? t.text : z(t.text);
735
+ }
736
+ }, ce = class {
737
+ strong({ text: t }) {
738
+ return t;
739
+ }
740
+ em({ text: t }) {
741
+ return t;
742
+ }
743
+ codespan({ text: t }) {
744
+ return t;
745
+ }
746
+ del({ text: t }) {
747
+ return t;
748
+ }
749
+ html({ text: t }) {
750
+ return t;
751
+ }
752
+ text({ text: t }) {
753
+ return t;
754
+ }
755
+ link({ text: t }) {
756
+ return "" + t;
757
+ }
758
+ image({ text: t }) {
759
+ return "" + t;
760
+ }
761
+ br() {
762
+ return "";
763
+ }
764
+ checkbox({ raw: t }) {
765
+ return t;
766
+ }
767
+ }, A = class ee {
768
+ options;
769
+ renderer;
770
+ textRenderer;
771
+ constructor(e) {
772
+ this.options = e || P, this.options.renderer = this.options.renderer || new W(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new ce();
773
+ }
774
+ static parse(e, n) {
775
+ return new ee(n).parse(e);
776
+ }
777
+ static parseInline(e, n) {
778
+ return new ee(n).parseInline(e);
779
+ }
780
+ parse(e) {
781
+ this.renderer.parser = this;
782
+ let n = "";
783
+ for (let s = 0; s < e.length; s++) {
784
+ let r = e[s];
785
+ if (this.options.extensions?.renderers?.[r.type]) {
786
+ let a = r, o = this.options.extensions.renderers[a.type].call({ parser: this }, a);
787
+ if (o !== !1 || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(a.type)) {
788
+ n += o || "";
789
+ continue;
790
+ }
791
+ }
792
+ let i = r;
793
+ switch (i.type) {
794
+ case "space": {
795
+ n += this.renderer.space(i);
796
+ break;
797
+ }
798
+ case "hr": {
799
+ n += this.renderer.hr(i);
800
+ break;
801
+ }
802
+ case "heading": {
803
+ n += this.renderer.heading(i);
804
+ break;
805
+ }
806
+ case "code": {
807
+ n += this.renderer.code(i);
808
+ break;
809
+ }
810
+ case "table": {
811
+ n += this.renderer.table(i);
812
+ break;
813
+ }
814
+ case "blockquote": {
815
+ n += this.renderer.blockquote(i);
816
+ break;
817
+ }
818
+ case "list": {
819
+ n += this.renderer.list(i);
820
+ break;
821
+ }
822
+ case "checkbox": {
823
+ n += this.renderer.checkbox(i);
824
+ break;
825
+ }
826
+ case "html": {
827
+ n += this.renderer.html(i);
828
+ break;
829
+ }
830
+ case "def": {
831
+ n += this.renderer.def(i);
832
+ break;
833
+ }
834
+ case "paragraph": {
835
+ n += this.renderer.paragraph(i);
836
+ break;
837
+ }
838
+ case "text": {
839
+ n += this.renderer.text(i);
840
+ break;
841
+ }
842
+ default: {
843
+ let a = 'Token with "' + i.type + '" type was not found.';
844
+ if (this.options.silent) return console.error(a), "";
845
+ throw new Error(a);
846
+ }
847
+ }
848
+ }
849
+ return n;
850
+ }
851
+ parseInline(e, n = this.renderer) {
852
+ this.renderer.parser = this;
853
+ let s = "";
854
+ for (let r = 0; r < e.length; r++) {
855
+ let i = e[r];
856
+ if (this.options.extensions?.renderers?.[i.type]) {
857
+ let o = this.options.extensions.renderers[i.type].call({ parser: this }, i);
858
+ if (o !== !1 || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
859
+ s += o || "";
860
+ continue;
861
+ }
862
+ }
863
+ let a = i;
864
+ switch (a.type) {
865
+ case "escape": {
866
+ s += n.text(a);
867
+ break;
868
+ }
869
+ case "html": {
870
+ s += n.html(a);
871
+ break;
872
+ }
873
+ case "link": {
874
+ s += n.link(a);
875
+ break;
876
+ }
877
+ case "image": {
878
+ s += n.image(a);
879
+ break;
880
+ }
881
+ case "checkbox": {
882
+ s += n.checkbox(a);
883
+ break;
884
+ }
885
+ case "strong": {
886
+ s += n.strong(a);
887
+ break;
888
+ }
889
+ case "em": {
890
+ s += n.em(a);
891
+ break;
892
+ }
893
+ case "codespan": {
894
+ s += n.codespan(a);
895
+ break;
896
+ }
897
+ case "br": {
898
+ s += n.br(a);
899
+ break;
900
+ }
901
+ case "del": {
902
+ s += n.del(a);
903
+ break;
904
+ }
905
+ case "text": {
906
+ s += n.text(a);
907
+ break;
908
+ }
909
+ default: {
910
+ let o = 'Token with "' + a.type + '" type was not found.';
911
+ if (this.options.silent) return console.error(o), "";
912
+ throw new Error(o);
913
+ }
914
+ }
915
+ }
916
+ return s;
917
+ }
918
+ }, D = class {
919
+ options;
920
+ block;
921
+ constructor(t) {
922
+ this.options = t || P;
923
+ }
924
+ static passThroughHooks = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
925
+ static passThroughHooksRespectAsync = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"]);
926
+ preprocess(t) {
927
+ return t;
928
+ }
929
+ postprocess(t) {
930
+ return t;
931
+ }
932
+ processAllTokens(t) {
933
+ return t;
934
+ }
935
+ emStrongMask(t) {
936
+ return t;
937
+ }
938
+ provideLexer() {
939
+ return this.block ? M.lex : M.lexInline;
940
+ }
941
+ provideParser() {
942
+ return this.block ? A.parse : A.parseInline;
943
+ }
944
+ }, Ht = class {
945
+ defaults = te();
946
+ options = this.setOptions;
947
+ parse = this.parseMarkdown(!0);
948
+ parseInline = this.parseMarkdown(!1);
949
+ Parser = A;
950
+ Renderer = W;
951
+ TextRenderer = ce;
952
+ Lexer = M;
953
+ Tokenizer = j;
954
+ Hooks = D;
955
+ constructor(...t) {
956
+ this.use(...t);
957
+ }
958
+ walkTokens(t, e) {
959
+ let n = [];
960
+ for (let s of t) switch (n = n.concat(e.call(this, s)), s.type) {
961
+ case "table": {
962
+ let r = s;
963
+ for (let i of r.header) n = n.concat(this.walkTokens(i.tokens, e));
964
+ for (let i of r.rows) for (let a of i) n = n.concat(this.walkTokens(a.tokens, e));
965
+ break;
966
+ }
967
+ case "list": {
968
+ let r = s;
969
+ n = n.concat(this.walkTokens(r.items, e));
970
+ break;
971
+ }
972
+ default: {
973
+ let r = s;
974
+ this.defaults.extensions?.childTokens?.[r.type] ? this.defaults.extensions.childTokens[r.type].forEach((i) => {
975
+ let a = r[i].flat(1 / 0);
976
+ n = n.concat(this.walkTokens(a, e));
977
+ }) : r.tokens && (n = n.concat(this.walkTokens(r.tokens, e)));
978
+ }
979
+ }
980
+ return n;
981
+ }
982
+ use(...t) {
983
+ let e = this.defaults.extensions || { renderers: {}, childTokens: {} };
984
+ return t.forEach((n) => {
985
+ let s = { ...n };
986
+ if (s.async = this.defaults.async || s.async || !1, n.extensions && (n.extensions.forEach((r) => {
987
+ if (!r.name) throw new Error("extension name required");
988
+ if ("renderer" in r) {
989
+ let i = e.renderers[r.name];
990
+ i ? e.renderers[r.name] = function(...a) {
991
+ let o = r.renderer.apply(this, a);
992
+ return o === !1 && (o = i.apply(this, a)), o;
993
+ } : e.renderers[r.name] = r.renderer;
994
+ }
995
+ if ("tokenizer" in r) {
996
+ if (!r.level || r.level !== "block" && r.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
997
+ let i = e[r.level];
998
+ i ? i.unshift(r.tokenizer) : e[r.level] = [r.tokenizer], r.start && (r.level === "block" ? e.startBlock ? e.startBlock.push(r.start) : e.startBlock = [r.start] : r.level === "inline" && (e.startInline ? e.startInline.push(r.start) : e.startInline = [r.start]));
999
+ }
1000
+ "childTokens" in r && r.childTokens && (e.childTokens[r.name] = r.childTokens);
1001
+ }), s.extensions = e), n.renderer) {
1002
+ let r = this.defaults.renderer || new W(this.defaults);
1003
+ for (let i in n.renderer) {
1004
+ if (!(i in r)) throw new Error(`renderer '${i}' does not exist`);
1005
+ if (["options", "parser"].includes(i)) continue;
1006
+ let a = i, o = n.renderer[a], l = r[a];
1007
+ r[a] = (...h) => {
1008
+ let c = o.apply(r, h);
1009
+ return c === !1 && (c = l.apply(r, h)), c || "";
1010
+ };
1011
+ }
1012
+ s.renderer = r;
1013
+ }
1014
+ if (n.tokenizer) {
1015
+ let r = this.defaults.tokenizer || new j(this.defaults);
1016
+ for (let i in n.tokenizer) {
1017
+ if (!(i in r)) throw new Error(`tokenizer '${i}' does not exist`);
1018
+ if (["options", "rules", "lexer"].includes(i)) continue;
1019
+ let a = i, o = n.tokenizer[a], l = r[a];
1020
+ r[a] = (...h) => {
1021
+ let c = o.apply(r, h);
1022
+ return c === !1 && (c = l.apply(r, h)), c;
1023
+ };
1024
+ }
1025
+ s.tokenizer = r;
1026
+ }
1027
+ if (n.hooks) {
1028
+ let r = this.defaults.hooks || new D();
1029
+ for (let i in n.hooks) {
1030
+ if (!(i in r)) throw new Error(`hook '${i}' does not exist`);
1031
+ if (["options", "block"].includes(i)) continue;
1032
+ let a = i, o = n.hooks[a], l = r[a];
1033
+ D.passThroughHooks.has(i) ? r[a] = (h) => {
1034
+ if (this.defaults.async && D.passThroughHooksRespectAsync.has(i)) return (async () => {
1035
+ let p = await o.call(r, h);
1036
+ return l.call(r, p);
1037
+ })();
1038
+ let c = o.call(r, h);
1039
+ return l.call(r, c);
1040
+ } : r[a] = (...h) => {
1041
+ if (this.defaults.async) return (async () => {
1042
+ let p = await o.apply(r, h);
1043
+ return p === !1 && (p = await l.apply(r, h)), p;
1044
+ })();
1045
+ let c = o.apply(r, h);
1046
+ return c === !1 && (c = l.apply(r, h)), c;
1047
+ };
1048
+ }
1049
+ s.hooks = r;
1050
+ }
1051
+ if (n.walkTokens) {
1052
+ let r = this.defaults.walkTokens, i = n.walkTokens;
1053
+ s.walkTokens = function(a) {
1054
+ let o = [];
1055
+ return o.push(i.call(this, a)), r && (o = o.concat(r.call(this, a))), o;
1056
+ };
1057
+ }
1058
+ this.defaults = { ...this.defaults, ...s };
1059
+ }), this;
1060
+ }
1061
+ setOptions(t) {
1062
+ return this.defaults = { ...this.defaults, ...t }, this;
1063
+ }
1064
+ lexer(t, e) {
1065
+ return M.lex(t, e ?? this.defaults);
1066
+ }
1067
+ parser(t, e) {
1068
+ return A.parse(t, e ?? this.defaults);
1069
+ }
1070
+ parseMarkdown(t) {
1071
+ return (e, n) => {
1072
+ let s = { ...n }, r = { ...this.defaults, ...s }, i = this.onError(!!r.silent, !!r.async);
1073
+ if (this.defaults.async === !0 && s.async === !1) return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
1074
+ if (typeof e > "u" || e === null) return i(new Error("marked(): input parameter is undefined or null"));
1075
+ if (typeof e != "string") return i(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(e) + ", string expected"));
1076
+ if (r.hooks && (r.hooks.options = r, r.hooks.block = t), r.async) return (async () => {
1077
+ let a = r.hooks ? await r.hooks.preprocess(e) : e, o = await (r.hooks ? await r.hooks.provideLexer() : t ? M.lex : M.lexInline)(a, r), l = r.hooks ? await r.hooks.processAllTokens(o) : o;
1078
+ r.walkTokens && await Promise.all(this.walkTokens(l, r.walkTokens));
1079
+ let h = await (r.hooks ? await r.hooks.provideParser() : t ? A.parse : A.parseInline)(l, r);
1080
+ return r.hooks ? await r.hooks.postprocess(h) : h;
1081
+ })().catch(i);
1082
+ try {
1083
+ r.hooks && (e = r.hooks.preprocess(e));
1084
+ let a = (r.hooks ? r.hooks.provideLexer() : t ? M.lex : M.lexInline)(e, r);
1085
+ r.hooks && (a = r.hooks.processAllTokens(a)), r.walkTokens && this.walkTokens(a, r.walkTokens);
1086
+ let o = (r.hooks ? r.hooks.provideParser() : t ? A.parse : A.parseInline)(a, r);
1087
+ return r.hooks && (o = r.hooks.postprocess(o)), o;
1088
+ } catch (a) {
1089
+ return i(a);
1090
+ }
1091
+ };
1092
+ }
1093
+ onError(t, e) {
1094
+ return (n) => {
1095
+ if (n.message += `
1096
+ Please report this to https://github.com/markedjs/marked.`, t) {
1097
+ let s = "<p>An error occurred:</p><pre>" + z(n.message + "", !0) + "</pre>";
1098
+ return e ? Promise.resolve(s) : s;
1099
+ }
1100
+ if (e) return Promise.reject(n);
1101
+ throw n;
1102
+ };
1103
+ }
1104
+ }, I = new Ht();
1105
+ function x(t, e) {
1106
+ return I.parse(t, e);
1107
+ }
1108
+ x.options = x.setOptions = function(t) {
1109
+ return I.setOptions(t), x.defaults = I.defaults, xe(x.defaults), x;
1110
+ };
1111
+ x.getDefaults = te;
1112
+ x.defaults = P;
1113
+ x.use = function(...t) {
1114
+ return I.use(...t), x.defaults = I.defaults, xe(x.defaults), x;
1115
+ };
1116
+ x.walkTokens = function(t, e) {
1117
+ return I.walkTokens(t, e);
1118
+ };
1119
+ x.parseInline = I.parseInline;
1120
+ x.Parser = A;
1121
+ x.parser = A.parse;
1122
+ x.Renderer = W;
1123
+ x.TextRenderer = ce;
1124
+ x.Lexer = M;
1125
+ x.lexer = M.lex;
1126
+ x.Tokenizer = j;
1127
+ x.Hooks = D;
1128
+ x.parse = x;
1129
+ x.options;
1130
+ x.setOptions;
1131
+ x.use;
1132
+ x.walkTokens;
1133
+ x.parseInline;
1134
+ A.parse;
1135
+ M.lex;
1136
+ function Ot(t, e) {
1137
+ const s = e.split(`
1138
+ `).flatMap((r) => [r, ""]).map((r) => `${t}${r}`).join(`
1139
+ `);
1140
+ return s.slice(0, s.length - 1);
1141
+ }
1142
+ function qt(t, e) {
1143
+ const n = [];
1144
+ return Array.from(t.keys()).forEach((s) => {
1145
+ (!e || !e.marks || !e.marks.map((r) => r.type).includes(s)) && n.push(s);
1146
+ }), n;
1147
+ }
1148
+ function Dt(t, e) {
1149
+ const n = [];
1150
+ return Array.from(e.entries()).forEach(([s, r]) => {
1151
+ t.has(s) || n.push({ type: s, mark: r });
1152
+ }), n;
1153
+ }
1154
+ function Nt(t, e, n, s) {
1155
+ const r = !n, i = n && n.type === "text" && (!n.marks || n.marks.length === 0), a = n && n.type === "text" && n.marks && !s(e, new Map(n.marks.map((l) => [l.type, l]))), o = [];
1156
+ if (r || i || a)
1157
+ if (n && n.type === "text" && n.marks) {
1158
+ const l = new Map(n.marks.map((h) => [h.type, h]));
1159
+ Array.from(t.keys()).reverse().forEach((h) => {
1160
+ l.has(h) || o.push(h);
1161
+ });
1162
+ } else (r || i) && o.push(...Array.from(t.keys()).reverse());
1163
+ return o;
1164
+ }
1165
+ function Ft(t, e) {
1166
+ let n = "";
1167
+ return Array.from(t.keys()).reverse().forEach((s) => {
1168
+ const r = t.get(s), i = e(s, r);
1169
+ i && (n = i + n);
1170
+ }), t.clear(), n;
1171
+ }
1172
+ function Qt(t, e, n) {
1173
+ let s = "";
1174
+ return Array.from(t.entries()).forEach(([r, i]) => {
1175
+ const a = n(r, i);
1176
+ a && (s += a), e.set(r, i);
1177
+ }), s;
1178
+ }
1179
+ function U(t) {
1180
+ const n = (t.raw || t.text || "").match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);
1181
+ return n ? { isTask: !0, checked: n[2].toLowerCase() === "x", indentLevel: n[1].length } : { isTask: !1, indentLevel: 0 };
1182
+ }
1183
+ function Q(t, e) {
1184
+ return typeof t != "string" ? "json" : e;
1185
+ }
1186
+ var Ae = class {
1187
+ /**
1188
+ * Create a MarkdownManager.
1189
+ * @param options.marked Optional marked instance to use (injected).
1190
+ * @param options.markedOptions Optional options to pass to marked.setOptions
1191
+ * @param options.indentation Indentation settings (style and size).
1192
+ * @param options.extensions An array of Tiptap extensions to register for markdown parsing and rendering.
1193
+ */
1194
+ constructor(t) {
1195
+ this.baseExtensions = [], this.extensions = [], this.lastParseResult = null;
1196
+ var e, n, s, r, i;
1197
+ this.markedInstance = (e = t?.marked) != null ? e : x, this.lexer = new this.markedInstance.Lexer(), this.indentStyle = (s = (n = t?.indentation) == null ? void 0 : n.style) != null ? s : "space", this.indentSize = (i = (r = t?.indentation) == null ? void 0 : r.size) != null ? i : 2, this.baseExtensions = t?.extensions || [], t?.markedOptions && typeof this.markedInstance.setOptions == "function" && this.markedInstance.setOptions(t.markedOptions), this.registry = /* @__PURE__ */ new Map(), this.nodeTypeRegistry = /* @__PURE__ */ new Map(), t?.extensions && (this.baseExtensions = t.extensions, Ee(t.extensions).forEach((o) => this.registerExtension(o, !1))), this.lexer = new this.markedInstance.Lexer();
1198
+ }
1199
+ /** Returns the underlying marked instance. */
1200
+ get instance() {
1201
+ return this.markedInstance;
1202
+ }
1203
+ /** Returns the correct indentCharacter (space or tab) */
1204
+ get indentCharacter() {
1205
+ return this.indentStyle === "space" ? " " : " ";
1206
+ }
1207
+ /** Returns the correct indentString repeated X times */
1208
+ get indentString() {
1209
+ return this.indentCharacter.repeat(this.indentSize);
1210
+ }
1211
+ /** Helper to quickly check whether a marked instance is available. */
1212
+ hasMarked() {
1213
+ return !!this.markedInstance;
1214
+ }
1215
+ /**
1216
+ * Register a Tiptap extension (Node/Mark/Extension). This will read
1217
+ * `markdownName`, `parseMarkdown`, `renderMarkdown` and `priority` from the
1218
+ * extension config (using the same resolution used across the codebase).
1219
+ */
1220
+ registerExtension(t, e = !0) {
1221
+ var n, s;
1222
+ this.extensions.push(t);
1223
+ const r = t.name, i = H(t, "markdownTokenName") || r, a = H(t, "parseMarkdown"), o = H(t, "renderMarkdown"), l = H(t, "markdownTokenizer"), h = (n = H(t, "markdownOptions")) != null ? n : null, c = (s = h?.indentsContent) != null ? s : !1, p = h?.htmlReopen, u = {
1224
+ tokenName: i,
1225
+ nodeName: r,
1226
+ parseMarkdown: a,
1227
+ renderMarkdown: o,
1228
+ isIndenting: c,
1229
+ htmlReopen: p,
1230
+ tokenizer: l
1231
+ };
1232
+ if (i && a) {
1233
+ const g = this.registry.get(i) || [];
1234
+ g.push(u), this.registry.set(i, g);
1235
+ }
1236
+ if (o) {
1237
+ const g = this.nodeTypeRegistry.get(r) || [];
1238
+ g.push(u), this.nodeTypeRegistry.set(r, g);
1239
+ }
1240
+ l && this.hasMarked() && (this.registerTokenizer(l), e && (this.lexer = new this.markedInstance.Lexer()));
1241
+ }
1242
+ /**
1243
+ * Register a custom tokenizer with marked.js for parsing non-standard markdown syntax.
1244
+ */
1245
+ registerTokenizer(t) {
1246
+ if (!this.hasMarked())
1247
+ return;
1248
+ const { name: e, start: n, level: s = "inline", tokenize: r } = t, o = {
1249
+ inlineTokens: (c) => this.lexer.inlineTokens(c),
1250
+ blockTokens: (c) => this.lexer.blockTokens(c)
1251
+ };
1252
+ let l;
1253
+ n ? l = typeof n == "function" ? n : (c) => c.indexOf(n) : l = (c) => {
1254
+ const p = r(c, [], o);
1255
+ return p && p.raw ? c.indexOf(p.raw) : -1;
1256
+ };
1257
+ const h = {
1258
+ name: e,
1259
+ level: s,
1260
+ start: l,
1261
+ tokenizer: (c, p) => {
1262
+ const u = r(c, p, o);
1263
+ if (u && u.type)
1264
+ return {
1265
+ ...u,
1266
+ type: u.type || e,
1267
+ raw: u.raw || "",
1268
+ tokens: u.tokens || []
1269
+ };
1270
+ },
1271
+ childTokens: []
1272
+ };
1273
+ this.markedInstance.use({
1274
+ extensions: [h]
1275
+ });
1276
+ }
1277
+ /** Get registered handlers for a token type and try each until one succeeds. */
1278
+ getHandlersForToken(t) {
1279
+ try {
1280
+ return this.registry.get(t) || [];
1281
+ } catch {
1282
+ return [];
1283
+ }
1284
+ }
1285
+ /** Get the first handler for a token type (for backwards compatibility). */
1286
+ getHandlerForToken(t) {
1287
+ const e = this.getHandlersForToken(t);
1288
+ if (e.length > 0)
1289
+ return e[0];
1290
+ const n = this.getHandlersForNodeType(t);
1291
+ return n.length > 0 ? n[0] : void 0;
1292
+ }
1293
+ /** Get registered handlers for a node type (for rendering). */
1294
+ getHandlersForNodeType(t) {
1295
+ try {
1296
+ return this.nodeTypeRegistry.get(t) || [];
1297
+ } catch {
1298
+ return [];
1299
+ }
1300
+ }
1301
+ /**
1302
+ * Serialize a ProseMirror-like JSON document (or node array) to a Markdown string
1303
+ * using registered renderers and fallback renderers.
1304
+ */
1305
+ serialize(t) {
1306
+ if (!t)
1307
+ return "";
1308
+ const e = this.renderNodes(t, t);
1309
+ return this.isEmptyOutput(e) ? "" : e;
1310
+ }
1311
+ /**
1312
+ * Check if the markdown output represents an empty document.
1313
+ * Empty documents may contain only &nbsp; entities or non-breaking space characters
1314
+ * which are used by the Paragraph extension to preserve blank lines.
1315
+ */
1316
+ isEmptyOutput(t) {
1317
+ return !t || t.trim() === "" ? !0 : t.replace(/&nbsp;/g, "").replace(/\u00A0/g, "").trim() === "";
1318
+ }
1319
+ /**
1320
+ * Parse markdown string into Tiptap JSON document using registered extension handlers.
1321
+ */
1322
+ parse(t) {
1323
+ if (!this.hasMarked())
1324
+ throw new Error("No marked instance available for parsing");
1325
+ const e = this.markedInstance.lexer(t);
1326
+ return {
1327
+ type: "doc",
1328
+ content: this.parseTokens(e, !0)
1329
+ };
1330
+ }
1331
+ /**
1332
+ * Convert an array of marked tokens into Tiptap JSON nodes using registered extension handlers.
1333
+ */
1334
+ parseTokens(t, e = !1) {
1335
+ const n = t.reduce((i, a, o) => (a.type !== "space" && i.push(o), i), []);
1336
+ let s = -1, r = 0;
1337
+ return t.flatMap((i, a) => {
1338
+ for (var o; r < n.length && n[r] < a; )
1339
+ s = n[r], r += 1;
1340
+ if (e && i.type === "space") {
1341
+ const h = (o = n[r]) != null ? o : -1;
1342
+ return this.createImplicitEmptyParagraphsFromSpace(i, s, h);
1343
+ }
1344
+ const l = this.parseToken(i, e);
1345
+ return l === null ? [] : Array.isArray(l) ? l : [l];
1346
+ });
1347
+ }
1348
+ createImplicitEmptyParagraphsFromSpace(t, e, n) {
1349
+ const s = this.countParagraphSeparators(t.raw || "");
1350
+ if (s === 0)
1351
+ return [];
1352
+ const i = Math.max(s - (e === -1 || n === -1 ? 0 : 1), 0);
1353
+ return Array.from({ length: i }, () => ({ type: "paragraph", content: [] }));
1354
+ }
1355
+ countParagraphSeparators(t) {
1356
+ return (t.replace(/\r\n/g, `
1357
+ `).match(/\n\n/g) || []).length;
1358
+ }
1359
+ /**
1360
+ * Parse a single token into Tiptap JSON using the appropriate registered handler.
1361
+ */
1362
+ parseToken(t, e = !1) {
1363
+ if (!t.type)
1364
+ return null;
1365
+ if (t.type === "list")
1366
+ return this.parseListToken(t);
1367
+ const n = this.getHandlersForToken(t.type), s = this.createParseHelpers();
1368
+ if (n.find((i) => {
1369
+ if (!i.parseMarkdown)
1370
+ return !1;
1371
+ const a = i.parseMarkdown(t, s), o = this.normalizeParseResult(a);
1372
+ return o && (!Array.isArray(o) || o.length > 0) ? (this.lastParseResult = o, !0) : !1;
1373
+ }) && this.lastParseResult) {
1374
+ const i = this.lastParseResult;
1375
+ return this.lastParseResult = null, i;
1376
+ }
1377
+ return this.parseFallbackToken(t, e);
1378
+ }
1379
+ /**
1380
+ * Parse a list token, handling mixed bullet and task list items by splitting them into separate lists.
1381
+ * This ensures that consecutive task items and bullet items are grouped and parsed as separate list nodes.
1382
+ *
1383
+ * @param token The list token to parse
1384
+ * @returns Array of parsed list nodes, or null if parsing fails
1385
+ */
1386
+ parseListToken(t) {
1387
+ if (!t.items || t.items.length === 0)
1388
+ return this.parseTokenWithHandlers(t);
1389
+ const e = t.items.some((o) => U(o).isTask), n = t.items.some((o) => !U(o).isTask);
1390
+ if (!e || !n || this.getHandlersForToken("taskList").length === 0)
1391
+ return this.parseTokenWithHandlers(t);
1392
+ const s = [];
1393
+ let r = [], i = null;
1394
+ for (let o = 0; o < t.items.length; o += 1) {
1395
+ const l = t.items[o], { isTask: h, checked: c, indentLevel: p } = U(l);
1396
+ let u = l;
1397
+ if (h) {
1398
+ const w = (l.raw || l.text || "").split(`
1399
+ `), y = w[0].match(/^\s*[-+*]\s+\[([ xX])\]\s+(.*)$/), b = y ? y[2] : "";
1400
+ let T = [];
1401
+ if (w.length > 1 && w.slice(1).join(`
1402
+ `).trim()) {
1403
+ const $ = w.slice(1), d = $.filter((m) => m.trim());
1404
+ if (d.length > 0) {
1405
+ const m = Math.min(...d.map((B) => B.length - B.trimStart().length)), E = $.map((B) => B.trim() ? B.slice(m) : "").join(`
1406
+ `).trim();
1407
+ E && (T = this.markedInstance.lexer(`${E}
1408
+ `));
1409
+ }
1410
+ }
1411
+ u = {
1412
+ type: "taskItem",
1413
+ raw: "",
1414
+ mainContent: b,
1415
+ indentLevel: p,
1416
+ checked: c ?? !1,
1417
+ text: b,
1418
+ tokens: this.lexer.inlineTokens(b),
1419
+ nestedTokens: T
1420
+ };
1421
+ }
1422
+ const g = h ? "taskList" : "list";
1423
+ i !== g ? (r.length > 0 && s.push({ type: i, items: r }), r = [u], i = g) : r.push(u);
1424
+ }
1425
+ r.length > 0 && s.push({ type: i, items: r });
1426
+ const a = [];
1427
+ for (let o = 0; o < s.length; o += 1) {
1428
+ const l = s[o], h = { ...t, type: l.type, items: l.items }, c = this.parseToken(h);
1429
+ c && (Array.isArray(c) ? a.push(...c) : a.push(c));
1430
+ }
1431
+ return a.length > 0 ? a : null;
1432
+ }
1433
+ /**
1434
+ * Parse a token using registered handlers (extracted for reuse).
1435
+ */
1436
+ parseTokenWithHandlers(t) {
1437
+ if (!t.type)
1438
+ return null;
1439
+ const e = this.getHandlersForToken(t.type), n = this.createParseHelpers();
1440
+ if (e.find((r) => {
1441
+ if (!r.parseMarkdown)
1442
+ return !1;
1443
+ const i = r.parseMarkdown(t, n), a = this.normalizeParseResult(i);
1444
+ return a && (!Array.isArray(a) || a.length > 0) ? (this.lastParseResult = a, !0) : !1;
1445
+ }) && this.lastParseResult) {
1446
+ const r = this.lastParseResult;
1447
+ return this.lastParseResult = null, r;
1448
+ }
1449
+ return this.parseFallbackToken(t);
1450
+ }
1451
+ /**
1452
+ * Creates helper functions for parsing markdown tokens.
1453
+ * @returns An object containing helper functions for parsing.
1454
+ */
1455
+ createParseHelpers() {
1456
+ return {
1457
+ parseInline: (t) => this.parseInlineTokens(t),
1458
+ parseChildren: (t) => this.parseTokens(t),
1459
+ parseBlockChildren: (t) => this.parseTokens(t, !0),
1460
+ createTextNode: (t, e) => ({
1461
+ type: "text",
1462
+ text: t,
1463
+ marks: e || void 0
1464
+ }),
1465
+ createNode: (t, e, n) => {
1466
+ const s = {
1467
+ type: t,
1468
+ attrs: e || void 0,
1469
+ content: n || void 0
1470
+ };
1471
+ return (!e || Object.keys(e).length === 0) && delete s.attrs, s;
1472
+ },
1473
+ applyMark: (t, e, n) => ({
1474
+ mark: t,
1475
+ content: e,
1476
+ attrs: n && Object.keys(n).length > 0 ? n : void 0
1477
+ })
1478
+ };
1479
+ }
1480
+ /**
1481
+ * Escape special regex characters in a string.
1482
+ */
1483
+ escapeRegex(t) {
1484
+ return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1485
+ }
1486
+ /**
1487
+ * Parse inline tokens (bold, italic, links, etc.) into text nodes with marks.
1488
+ * This is the complex part that handles mark nesting and boundaries.
1489
+ */
1490
+ parseInlineTokens(t) {
1491
+ var e, n, s, r;
1492
+ const i = [];
1493
+ for (let a = 0; a < t.length; a += 1) {
1494
+ const o = t[a];
1495
+ if (o.type === "text")
1496
+ i.push({
1497
+ type: "text",
1498
+ text: o.text || ""
1499
+ });
1500
+ else if (o.type === "html") {
1501
+ const l = ((n = (e = o.raw) != null ? e : o.text) != null ? n : "").toString(), h = /^<\/[\s]*[\w-]+/i.test(l), c = l.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);
1502
+ if (!h && c && !/\/>$/.test(l)) {
1503
+ const u = c[1], g = this.escapeRegex(u), f = new RegExp(`^<\\/\\s*${g}\\b`, "i");
1504
+ let w = -1;
1505
+ const y = [l];
1506
+ for (let b = a + 1; b < t.length; b += 1) {
1507
+ const T = t[b], R = ((r = (s = T.raw) != null ? s : T.text) != null ? r : "").toString();
1508
+ if (y.push(R), T.type === "html" && f.test(R)) {
1509
+ w = b;
1510
+ break;
1511
+ }
1512
+ }
1513
+ if (w !== -1) {
1514
+ const b = y.join(""), T = {
1515
+ type: "html",
1516
+ raw: b,
1517
+ text: b,
1518
+ block: !1
1519
+ }, R = this.parseHTMLToken(T);
1520
+ if (R) {
1521
+ const $ = this.normalizeParseResult(R);
1522
+ Array.isArray($) ? i.push(...$) : $ && i.push($);
1523
+ }
1524
+ a = w;
1525
+ continue;
1526
+ }
1527
+ }
1528
+ const p = this.parseHTMLToken(o);
1529
+ if (p) {
1530
+ const u = this.normalizeParseResult(p);
1531
+ Array.isArray(u) ? i.push(...u) : u && i.push(u);
1532
+ }
1533
+ } else if (o.type) {
1534
+ const l = this.getHandlerForToken(o.type);
1535
+ if (l && l.parseMarkdown) {
1536
+ const h = this.createParseHelpers(), c = l.parseMarkdown(o, h);
1537
+ if (this.isMarkResult(c)) {
1538
+ const p = this.applyMarkToContent(c.mark, c.content, c.attrs);
1539
+ i.push(...p);
1540
+ } else {
1541
+ const p = this.normalizeParseResult(c);
1542
+ Array.isArray(p) ? i.push(...p) : p && i.push(p);
1543
+ }
1544
+ } else o.tokens && i.push(...this.parseInlineTokens(o.tokens));
1545
+ }
1546
+ }
1547
+ return i;
1548
+ }
1549
+ /**
1550
+ * Apply a mark to content nodes.
1551
+ */
1552
+ applyMarkToContent(t, e, n) {
1553
+ return e.map((s) => {
1554
+ if (s.type === "text") {
1555
+ const r = s.marks || [], i = n ? { type: t, attrs: n } : { type: t };
1556
+ return {
1557
+ ...s,
1558
+ marks: [...r, i]
1559
+ };
1560
+ }
1561
+ return {
1562
+ ...s,
1563
+ content: s.content ? this.applyMarkToContent(t, s.content, n) : void 0
1564
+ };
1565
+ });
1566
+ }
1567
+ /**
1568
+ * Check if a parse result represents a mark to be applied.
1569
+ */
1570
+ isMarkResult(t) {
1571
+ return t && typeof t == "object" && "mark" in t;
1572
+ }
1573
+ /**
1574
+ * Normalize parse results to ensure they're valid JSONContent.
1575
+ */
1576
+ normalizeParseResult(t) {
1577
+ return t ? this.isMarkResult(t) ? t.content : t : null;
1578
+ }
1579
+ /**
1580
+ * Fallback parsing for common tokens when no specific handler is registered.
1581
+ */
1582
+ parseFallbackToken(t, e = !1) {
1583
+ switch (t.type) {
1584
+ case "paragraph":
1585
+ return {
1586
+ type: "paragraph",
1587
+ content: t.tokens ? this.parseInlineTokens(t.tokens) : []
1588
+ };
1589
+ case "heading":
1590
+ return {
1591
+ type: "heading",
1592
+ attrs: { level: t.depth || 1 },
1593
+ content: t.tokens ? this.parseInlineTokens(t.tokens) : []
1594
+ };
1595
+ case "text":
1596
+ return {
1597
+ type: "text",
1598
+ text: t.text || ""
1599
+ };
1600
+ case "html":
1601
+ return this.parseHTMLToken(t);
1602
+ case "space":
1603
+ return null;
1604
+ default:
1605
+ return t.tokens ? this.parseTokens(t.tokens, e) : null;
1606
+ }
1607
+ }
1608
+ /**
1609
+ * Parse HTML tokens using extensions' parseHTML methods.
1610
+ * This allows HTML within markdown to be parsed according to extension rules.
1611
+ */
1612
+ parseHTMLToken(t) {
1613
+ const e = t.text || t.raw || "";
1614
+ if (!e.trim())
1615
+ return null;
1616
+ if (typeof window > "u")
1617
+ return t.block ? {
1618
+ type: "paragraph",
1619
+ content: [
1620
+ {
1621
+ type: "text",
1622
+ text: e
1623
+ }
1624
+ ]
1625
+ } : {
1626
+ type: "text",
1627
+ text: e
1628
+ };
1629
+ try {
1630
+ const n = _e(e, this.baseExtensions);
1631
+ return n.type === "doc" && n.content ? t.block ? n.content : n.content.length === 1 && n.content[0].type === "paragraph" && n.content[0].content ? n.content[0].content : n.content : n;
1632
+ } catch (n) {
1633
+ throw new Error(`Failed to parse HTML in markdown: ${n}`);
1634
+ }
1635
+ }
1636
+ renderNodeToMarkdown(t, e, n = 0, s = 0, r = {}) {
1637
+ var i;
1638
+ if (t.type === "text")
1639
+ return t.text || "";
1640
+ if (!t.type)
1641
+ return "";
1642
+ const a = this.getHandlerForToken(t.type);
1643
+ if (!a)
1644
+ return "";
1645
+ const o = Array.isArray(e?.content) && n > 0 ? e.content[n - 1] : void 0, l = {
1646
+ renderChildren: (p, u) => {
1647
+ const g = a.isIndenting ? s + 1 : s;
1648
+ return !Array.isArray(p) && p.content ? this.renderNodes(p.content, t, u || "", n, g) : this.renderNodes(p, t, u || "", n, g);
1649
+ },
1650
+ renderChild: (p, u) => {
1651
+ const g = a.isIndenting ? s + 1 : s;
1652
+ return this.renderNodeToMarkdown(p, t, u, g);
1653
+ },
1654
+ indent: (p) => this.indentString + p,
1655
+ wrapInBlock: Ot
1656
+ }, h = {
1657
+ index: n,
1658
+ level: s,
1659
+ parentType: e?.type,
1660
+ previousNode: o,
1661
+ meta: {
1662
+ parentAttrs: e?.attrs,
1663
+ ...r
1664
+ }
1665
+ };
1666
+ return ((i = a.renderMarkdown) == null ? void 0 : i.call(a, t, l, h)) || "";
1667
+ }
1668
+ /**
1669
+ * Render a node or an array of nodes. Parent type controls how children
1670
+ * are joined (which determines newline insertion between children).
1671
+ */
1672
+ renderNodes(t, e, n = "", s = 0, r = 0) {
1673
+ return Array.isArray(t) ? this.renderNodesWithMarkBoundaries(t, e, n, r) : t.type ? this.renderNodeToMarkdown(t, e, s, r) : "";
1674
+ }
1675
+ /**
1676
+ * Render an array of nodes while properly tracking mark boundaries.
1677
+ * This handles cases where marks span across multiple text nodes.
1678
+ */
1679
+ renderNodesWithMarkBoundaries(t, e, n = "", s = 0) {
1680
+ const r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
1681
+ return t.forEach((l, h) => {
1682
+ const c = h < t.length - 1 ? t[h + 1] : null;
1683
+ if (l.type)
1684
+ if (l.type === "text") {
1685
+ let p = l.text || "";
1686
+ const u = new Map((l.marks || []).map((d) => [d.type, d])), g = Dt(i, u), f = qt(u, c), w = f.filter((d) => i.has(d)), y = w.length > 0 && g.length > 0;
1687
+ let b = "";
1688
+ if (f.length > 0 && !y) {
1689
+ const d = p.match(/(\s+)$/);
1690
+ d && (b = d[1], p = p.slice(0, -b.length));
1691
+ }
1692
+ y || f.forEach((d) => {
1693
+ if (!i.has(d))
1694
+ return;
1695
+ const m = u.get(d), C = this.getMarkClosing(d, m, o.get(d));
1696
+ C && (p += C), i.has(d) && (i.delete(d), o.delete(d));
1697
+ });
1698
+ let T = "";
1699
+ if (g.length > 0) {
1700
+ const d = p.match(/^(\s+)/);
1701
+ d && (T = d[1], p = p.slice(T.length));
1702
+ }
1703
+ g.forEach(({ type: d, mark: m }) => {
1704
+ const C = a.has(d) ? "html" : "markdown", E = this.getMarkOpening(d, m, C);
1705
+ E && (p = E + p), o.set(d, C), a.delete(d);
1706
+ }), y || g.slice().reverse().forEach(({ type: d, mark: m }) => {
1707
+ i.set(d, m);
1708
+ }), p = T + p;
1709
+ let R;
1710
+ if (y) {
1711
+ const d = new Set((c?.marks || []).map((m) => m.type));
1712
+ g.forEach(({ type: m }) => {
1713
+ d.has(m) && this.getHtmlReopenTags(m) && a.add(m);
1714
+ }), R = [
1715
+ ...g.map((m) => m.type),
1716
+ // inner (opened here) — close first
1717
+ ...w
1718
+ // outer (were active before) — close last
1719
+ ];
1720
+ } else
1721
+ R = Nt(i, u, c, this.markSetsEqual.bind(this));
1722
+ let $ = "";
1723
+ if (R.length > 0) {
1724
+ const d = p.match(/(\s+)$/);
1725
+ d && ($ = d[1], p = p.slice(0, -$.length));
1726
+ }
1727
+ R.forEach((d) => {
1728
+ var m;
1729
+ const C = (m = i.get(d)) != null ? m : u.get(d), E = this.getMarkClosing(d, C, o.get(d));
1730
+ E && (p += E), i.delete(d), o.delete(d);
1731
+ }), p += $, p += b, r.push(p);
1732
+ } else {
1733
+ const p = new Map(i), u = new Map(o), g = Ft(i, (y, b) => this.getMarkClosing(y, b, o.get(y)));
1734
+ o.clear();
1735
+ const f = this.renderNodeToMarkdown(l, e, h, s), w = l.type === "hardBreak" ? "" : Qt(p, i, (y, b) => {
1736
+ var T;
1737
+ const R = (T = u.get(y)) != null ? T : "markdown";
1738
+ return o.set(y, R), this.getMarkOpening(y, b, R);
1739
+ });
1740
+ r.push(g + f + w);
1741
+ }
1742
+ }), r.join(n);
1743
+ }
1744
+ /**
1745
+ * Get the opening markdown syntax for a mark type.
1746
+ */
1747
+ getMarkOpening(t, e, n = "markdown") {
1748
+ var s;
1749
+ if (n === "html")
1750
+ return ((s = this.getHtmlReopenTags(t)) == null ? void 0 : s.open) || "";
1751
+ const r = this.getHandlersForNodeType(t), i = r.length > 0 ? r[0] : void 0;
1752
+ if (!i || !i.renderMarkdown)
1753
+ return "";
1754
+ const a = "__TIPTAP_MARKDOWN_PLACEHOLDER__", o = {
1755
+ type: t,
1756
+ attrs: e.attrs || {},
1757
+ content: [{ type: "text", text: a }]
1758
+ };
1759
+ try {
1760
+ const l = i.renderMarkdown(
1761
+ o,
1762
+ {
1763
+ renderChildren: () => a,
1764
+ renderChild: () => a,
1765
+ indent: (c) => c,
1766
+ wrapInBlock: (c, p) => c + p
1767
+ },
1768
+ { index: 0, level: 0, parentType: "text", meta: {} }
1769
+ ), h = l.indexOf(a);
1770
+ return h >= 0 ? l.substring(0, h) : "";
1771
+ } catch (l) {
1772
+ throw new Error(`Failed to get mark opening for ${t}: ${l}`);
1773
+ }
1774
+ }
1775
+ /**
1776
+ * Get the closing markdown syntax for a mark type.
1777
+ */
1778
+ getMarkClosing(t, e, n = "markdown") {
1779
+ var s;
1780
+ if (n === "html")
1781
+ return ((s = this.getHtmlReopenTags(t)) == null ? void 0 : s.close) || "";
1782
+ const r = this.getHandlersForNodeType(t), i = r.length > 0 ? r[0] : void 0;
1783
+ if (!i || !i.renderMarkdown)
1784
+ return "";
1785
+ const a = "__TIPTAP_MARKDOWN_PLACEHOLDER__", o = {
1786
+ type: t,
1787
+ attrs: e.attrs || {},
1788
+ content: [{ type: "text", text: a }]
1789
+ };
1790
+ try {
1791
+ const l = i.renderMarkdown(
1792
+ o,
1793
+ {
1794
+ renderChildren: () => a,
1795
+ renderChild: () => a,
1796
+ indent: (p) => p,
1797
+ wrapInBlock: (p, u) => p + u
1798
+ },
1799
+ { index: 0, level: 0, parentType: "text", meta: {} }
1800
+ ), h = l.indexOf(a), c = h + a.length;
1801
+ return h >= 0 ? l.substring(c) : "";
1802
+ } catch (l) {
1803
+ throw new Error(`Failed to get mark closing for ${t}: ${l}`);
1804
+ }
1805
+ }
1806
+ /**
1807
+ * Returns the inline HTML tags an extension exposes for overlap-boundary
1808
+ * reopen handling, if that mark explicitly opted into HTML reopen mode.
1809
+ */
1810
+ getHtmlReopenTags(t) {
1811
+ const e = this.getHandlersForNodeType(t), n = e.length > 0 ? e[0] : void 0;
1812
+ return n?.htmlReopen;
1813
+ }
1814
+ /**
1815
+ * Check if two mark sets are equal.
1816
+ */
1817
+ markSetsEqual(t, e) {
1818
+ return t.size !== e.size ? !1 : Array.from(t.keys()).every((n) => e.has(n));
1819
+ }
1820
+ }, fe = Ae;
1821
+ Ce.create({
1822
+ name: "markdown",
1823
+ addOptions() {
1824
+ return {
1825
+ indentation: { style: "space", size: 2 },
1826
+ marked: void 0,
1827
+ markedOptions: {}
1828
+ };
1829
+ },
1830
+ addCommands() {
1831
+ return {
1832
+ setContent: (t, e) => {
1833
+ if (!e?.contentType)
1834
+ return v.setContent(t, e);
1835
+ if (Q(t, e?.contentType) !== "markdown" || !this.editor.markdown)
1836
+ return v.setContent(t, e);
1837
+ const s = this.editor.markdown.parse(t);
1838
+ return v.setContent(s, e);
1839
+ },
1840
+ insertContent: (t, e) => {
1841
+ if (!e?.contentType)
1842
+ return v.insertContent(t, e);
1843
+ if (Q(t, e?.contentType) !== "markdown" || !this.editor.markdown)
1844
+ return v.insertContent(t, e);
1845
+ const s = this.editor.markdown.parse(t);
1846
+ return v.insertContent(s, e);
1847
+ },
1848
+ insertContentAt: (t, e, n) => {
1849
+ if (!n?.contentType)
1850
+ return v.insertContentAt(t, e, n);
1851
+ if (Q(e, n?.contentType) !== "markdown" || !this.editor.markdown)
1852
+ return v.insertContentAt(t, e, n);
1853
+ const r = this.editor.markdown.parse(e);
1854
+ return v.insertContentAt(t, r, n);
1855
+ }
1856
+ };
1857
+ },
1858
+ addStorage() {
1859
+ return {
1860
+ manager: new fe({
1861
+ indentation: this.options.indentation,
1862
+ marked: this.options.marked,
1863
+ markedOptions: this.options.markedOptions,
1864
+ extensions: []
1865
+ })
1866
+ };
1867
+ },
1868
+ onBeforeCreate() {
1869
+ if (this.editor.markdown) {
1870
+ console.error(
1871
+ "[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior."
1872
+ );
1873
+ return;
1874
+ }
1875
+ if (this.storage.manager = new fe({
1876
+ indentation: this.options.indentation,
1877
+ marked: this.options.marked,
1878
+ markedOptions: this.options.markedOptions,
1879
+ extensions: this.editor.extensionManager.baseExtensions
1880
+ }), this.editor.markdown = this.storage.manager, this.editor.getMarkdown = () => this.storage.manager.serialize(this.editor.getJSON()), !this.editor.options.contentType || Q(this.editor.options.content, this.editor.options.contentType) !== "markdown")
1881
+ return;
1882
+ if (!this.editor.markdown)
1883
+ throw new Error(
1884
+ '[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.'
1885
+ );
1886
+ if (this.editor.options.content === void 0 || typeof this.editor.options.content != "string")
1887
+ throw new Error(
1888
+ '[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.'
1889
+ );
1890
+ const e = this.editor.markdown.parse(this.editor.options.content);
1891
+ this.editor.options.content = e;
1892
+ }
1893
+ });
1894
+ const Zt = [
1895
+ Ie,
1896
+ Pe,
1897
+ Le,
1898
+ Ke.configure({ levels: [1, 2, 3] }),
1899
+ Be,
1900
+ He,
1901
+ Oe,
1902
+ Ue.configure({ taskList: !1, taskItem: !1, orderedList: !1 }),
1903
+ qe,
1904
+ De,
1905
+ Ne,
1906
+ Fe,
1907
+ Qe,
1908
+ Ze,
1909
+ je,
1910
+ We,
1911
+ Ge,
1912
+ Xe
1913
+ ];
1914
+ function jt() {
1915
+ const t = new Ae();
1916
+ for (const e of Zt)
1917
+ t.registerExtension(e);
1918
+ return t;
1919
+ }
1920
+ let J = null;
1921
+ function K() {
1922
+ return J || (J = jt()), J;
1923
+ }
1924
+ function Gt(t) {
1925
+ return K().serialize(t);
1926
+ }
1927
+ function ze(t) {
1928
+ for (; t.content.length > 1; ) {
1929
+ const e = t.content[t.content.length - 1];
1930
+ if (e.type === "paragraph" && (!("content" in e) || !e.content?.length))
1931
+ t.content.pop();
1932
+ else break;
1933
+ }
1934
+ }
1935
+ function ve(t) {
1936
+ t.resolved && delete t.resolved, Array.isArray(t.content) && t.content.forEach(ve);
1937
+ }
1938
+ function Xt(t) {
1939
+ const e = K().parse(t);
1940
+ return ze(e), ve(e), e;
1941
+ }
1942
+ function Kt(t) {
1943
+ return K().serialize(t);
1944
+ }
1945
+ function Ut(t) {
1946
+ const e = K().parse(t);
1947
+ return ze(e), e;
1948
+ }
6
1949
  export {
7
- s as QalamEditor,
8
- f as QalamRenderer,
9
- t as QuranRef,
10
- Q as getAllSurahs,
11
- p as getSurahInfo,
12
- u as getVerseText,
13
- S as isDataLoaded,
14
- g as loadQuranData,
15
- d as resolveAST,
16
- i as resolveSurah,
17
- e as validateAST
1950
+ Ae as MarkdownManager,
1951
+ tn as QalamEditor,
1952
+ rn as QalamRenderer,
1953
+ Fe as QuranRef,
1954
+ jt as createMarkdownManager,
1955
+ Gt as docToMarkdown,
1956
+ on as getAllSurahs,
1957
+ cn as getSurahInfo,
1958
+ hn as getVerseText,
1959
+ pn as isDataLoaded,
1960
+ un as loadQuranData,
1961
+ Xt as markdownToDoc,
1962
+ Ut as markdownToResolvedDoc,
1963
+ an as resolveAST,
1964
+ dn as resolveSurah,
1965
+ Kt as resolvedDocToMarkdown,
1966
+ Yt as validateAST
18
1967
  };