catmdx 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as getTOC, r as walkMarkdown, t as getSection } from "./section-Cw5XNpYg.js";
1
+ import { n as getTOC, t as getSections } from "./section-BGi0lC4H.js";
2
2
  import { program } from "commander";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import { resolve } from "node:path";
@@ -12,23 +12,1599 @@ async function getContent(options) {
12
12
  return Buffer.concat(chunks).toString("utf8");
13
13
  }
14
14
 
15
+ //#endregion
16
+ //#region node_modules/.pnpm/marked@17.0.3/node_modules/marked/lib/marked.esm.js
17
+ /**
18
+ * marked v17.0.3 - a markdown parser
19
+ * Copyright (c) 2018-2026, MarkedJS. (MIT License)
20
+ * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)
21
+ * https://github.com/markedjs/marked
22
+ */
23
+ /**
24
+ * DO NOT EDIT THIS FILE
25
+ * The code in this file is generated from files in ./src/
26
+ */
27
+ function M() {
28
+ return {
29
+ async: !1,
30
+ breaks: !1,
31
+ extensions: null,
32
+ gfm: !0,
33
+ hooks: null,
34
+ pedantic: !1,
35
+ renderer: null,
36
+ silent: !1,
37
+ tokenizer: null,
38
+ walkTokens: null
39
+ };
40
+ }
41
+ var T = M();
42
+ function H(u) {
43
+ T = u;
44
+ }
45
+ var _ = { exec: () => null };
46
+ function k(u, e = "") {
47
+ let t = typeof u == "string" ? u : u.source, n = {
48
+ replace: (r, i) => {
49
+ let s = typeof i == "string" ? i : i.source;
50
+ return s = s.replace(m.caret, "$1"), t = t.replace(r, s), n;
51
+ },
52
+ getRegex: () => new RegExp(t, e)
53
+ };
54
+ return n;
55
+ }
56
+ var Re = (() => {
57
+ try {
58
+ return true;
59
+ } catch {
60
+ return !1;
61
+ }
62
+ })(), m = {
63
+ codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
64
+ outputLinkReplace: /\\([\[\]])/g,
65
+ indentCodeCompensation: /^(\s+)(?:```)/,
66
+ beginningSpace: /^\s+/,
67
+ endingHash: /#$/,
68
+ startingSpaceChar: /^ /,
69
+ endingSpaceChar: / $/,
70
+ nonSpaceChar: /[^ ]/,
71
+ newLineCharGlobal: /\n/g,
72
+ tabCharGlobal: /\t/g,
73
+ multipleSpaceGlobal: /\s+/g,
74
+ blankLine: /^[ \t]*$/,
75
+ doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
76
+ blockquoteStart: /^ {0,3}>/,
77
+ blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
78
+ blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
79
+ listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
80
+ listIsTask: /^\[[ xX]\] +\S/,
81
+ listReplaceTask: /^\[[ xX]\] +/,
82
+ listTaskCheckbox: /\[[ xX]\]/,
83
+ anyLine: /\n.*\n/,
84
+ hrefBrackets: /^<(.*)>$/,
85
+ tableDelimiter: /[:|]/,
86
+ tableAlignChars: /^\||\| *$/g,
87
+ tableRowBlankLine: /\n[ \t]*$/,
88
+ tableAlignRight: /^ *-+: *$/,
89
+ tableAlignCenter: /^ *:-+: *$/,
90
+ tableAlignLeft: /^ *:-+ *$/,
91
+ startATag: /^<a /i,
92
+ endATag: /^<\/a>/i,
93
+ startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
94
+ endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
95
+ startAngleBracket: /^</,
96
+ endAngleBracket: />$/,
97
+ pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
98
+ unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
99
+ escapeTest: /[&<>"']/,
100
+ escapeReplace: /[&<>"']/g,
101
+ escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
102
+ escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
103
+ unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,
104
+ caret: /(^|[^\[])\^/g,
105
+ percentDecode: /%25/g,
106
+ findPipe: /\|/g,
107
+ splitPipe: / \|/,
108
+ slashPipe: /\\\|/g,
109
+ carriageReturn: /\r\n|\r/g,
110
+ spaceLine: /^ +$/gm,
111
+ notSpaceStart: /^\S*/,
112
+ endingNewline: /\n$/,
113
+ listItemRegex: (u) => new RegExp(`^( {0,3}${u})((?:[ ][^\\n]*)?(?:\\n|$))`),
114
+ nextBulletRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
115
+ hrRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
116
+ fencesBeginRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}(?:\`\`\`|~~~)`),
117
+ headingBeginRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}#`),
118
+ htmlBeginRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}<(?:[a-z].*>|!--)`, "i"),
119
+ blockquoteBeginRegex: (u) => new RegExp(`^ {0,${Math.min(3, u - 1)}}>`)
120
+ }, Te = /^(?:[ \t]*(?:\n|$))+/, Oe = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, we = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, ye = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, N = / {0,3}(?:[*+-]|\d{1,9}[.)])/, re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, se = k(re).replace(/bull/g, N).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(), Pe = k(re).replace(/bull/g, N).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(), Q = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, Se = /^[^\n]+/, F = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/, $e = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", F).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), _e = k(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, N).getRegex(), q = "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", j = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, Le = 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", j).replace("tag", q).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), ie = k(Q).replace("hr", I).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", q).getRegex(), U = {
121
+ blockquote: k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", ie).getRegex(),
122
+ code: Oe,
123
+ def: $e,
124
+ fences: we,
125
+ heading: ye,
126
+ hr: I,
127
+ html: Le,
128
+ lheading: se,
129
+ list: _e,
130
+ newline: Te,
131
+ paragraph: ie,
132
+ table: _,
133
+ text: Se
134
+ }, te = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).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", q).getRegex(), ze = {
135
+ ...U,
136
+ lheading: Pe,
137
+ table: te,
138
+ paragraph: k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", te).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", q).getRegex()
139
+ }, Ce = {
140
+ ...U,
141
+ html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", j).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(),
142
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
143
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
144
+ fences: _,
145
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
146
+ paragraph: k(Q).replace("hr", I).replace("heading", ` *#{1,6} *[^
147
+ ]`).replace("lheading", se).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
148
+ }, Ae = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, Ie = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, oe = /^( {2,}|\\)\n(?!\s*$)/, Ee = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, v = /[\p{P}\p{S}]/u, K = /[\s\p{P}\p{S}]/u, ae = /[^\s\p{P}\p{S}]/u, Be = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, K).getRegex(), le = /(?!~)[\p{P}\p{S}]/u, De = /(?!~)[\s\p{P}\p{S}]/u, qe = /(?:[^\s\p{P}\p{S}]|~)/u, ue = /(?![*_])[\p{P}\p{S}]/u, ve = /(?![*_])[\s\p{P}\p{S}]/u, Ge = /(?:[^\s\p{P}\p{S}]|[*_])/u, He = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Re ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex(), pe = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, Ze = k(pe, "u").replace(/punct/g, v).getRegex(), Ne = k(pe, "u").replace(/punct/g, le).getRegex(), ce = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", Qe = k(ce, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, v).getRegex(), Fe = k(ce, "gu").replace(/notPunctSpace/g, qe).replace(/punctSpace/g, De).replace(/punct/g, le).getRegex(), je = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, v).getRegex(), Ue = k(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, ue).getRegex(), We = k("^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, Ge).replace(/punctSpace/g, ve).replace(/punct/g, ue).getRegex(), Xe = k(/\\(punct)/, "gu").replace(/punct/g, v).getRegex(), Je = 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(), Ve = k(j).replace("(?:-->|$)", "-->").getRegex(), Ye = 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", Ve).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), D = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/, et = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", D).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), he = k(/^!?\[(label)\]\[(ref)\]/).replace("label", D).replace("ref", F).getRegex(), ke = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", F).getRegex(), tt = k("reflink|nolink(?!\\()", "g").replace("reflink", he).replace("nolink", ke).getRegex(), ne = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/, W = {
149
+ _backpedal: _,
150
+ anyPunctuation: Xe,
151
+ autolink: Je,
152
+ blockSkip: He,
153
+ br: oe,
154
+ code: Ie,
155
+ del: _,
156
+ delLDelim: _,
157
+ delRDelim: _,
158
+ emStrongLDelim: Ze,
159
+ emStrongRDelimAst: Qe,
160
+ emStrongRDelimUnd: je,
161
+ escape: Ae,
162
+ link: et,
163
+ nolink: ke,
164
+ punctuation: Be,
165
+ reflink: he,
166
+ reflinkSearch: tt,
167
+ tag: Ye,
168
+ text: Ee,
169
+ url: _
170
+ }, nt = {
171
+ ...W,
172
+ link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", D).getRegex(),
173
+ reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", D).getRegex()
174
+ }, Z = {
175
+ ...W,
176
+ emStrongRDelimAst: Fe,
177
+ emStrongLDelim: Ne,
178
+ delLDelim: Ue,
179
+ delRDelim: We,
180
+ url: k(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ne).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
181
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
182
+ del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,
183
+ 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", ne).getRegex()
184
+ }, rt = {
185
+ ...Z,
186
+ br: k(oe).replace("{2,}", "*").getRegex(),
187
+ text: k(Z.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
188
+ }, E = {
189
+ normal: U,
190
+ gfm: ze,
191
+ pedantic: Ce
192
+ }, z = {
193
+ normal: W,
194
+ gfm: Z,
195
+ breaks: rt,
196
+ pedantic: nt
197
+ };
198
+ var st = {
199
+ "&": "&amp;",
200
+ "<": "&lt;",
201
+ ">": "&gt;",
202
+ "\"": "&quot;",
203
+ "'": "&#39;"
204
+ }, de = (u) => st[u];
205
+ function O(u, e) {
206
+ if (e) {
207
+ if (m.escapeTest.test(u)) return u.replace(m.escapeReplace, de);
208
+ } else if (m.escapeTestNoEncode.test(u)) return u.replace(m.escapeReplaceNoEncode, de);
209
+ return u;
210
+ }
211
+ function X(u) {
212
+ try {
213
+ u = encodeURI(u).replace(m.percentDecode, "%");
214
+ } catch {
215
+ return null;
216
+ }
217
+ return u;
218
+ }
219
+ function J(u, e) {
220
+ let n = u.replace(m.findPipe, (i, s, a) => {
221
+ let o = !1, l = s;
222
+ for (; --l >= 0 && a[l] === "\\";) o = !o;
223
+ return o ? "|" : " |";
224
+ }).split(m.splitPipe), r = 0;
225
+ if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
226
+ else for (; n.length < e;) n.push("");
227
+ for (; r < n.length; r++) n[r] = n[r].trim().replace(m.slashPipe, "|");
228
+ return n;
229
+ }
230
+ function C(u, e, t) {
231
+ let n = u.length;
232
+ if (n === 0) return "";
233
+ let r = 0;
234
+ for (; r < n;) {
235
+ let i = u.charAt(n - r - 1);
236
+ if (i === e && !t) r++;
237
+ else if (i !== e && t) r++;
238
+ else break;
239
+ }
240
+ return u.slice(0, n - r);
241
+ }
242
+ function ge(u, e) {
243
+ if (u.indexOf(e[1]) === -1) return -1;
244
+ let t = 0;
245
+ for (let n = 0; n < u.length; n++) if (u[n] === "\\") n++;
246
+ else if (u[n] === e[0]) t++;
247
+ else if (u[n] === e[1] && (t--, t < 0)) return n;
248
+ return t > 0 ? -2 : -1;
249
+ }
250
+ function fe(u, e = 0) {
251
+ let t = e, n = "";
252
+ for (let r of u) if (r === " ") {
253
+ let i = 4 - t % 4;
254
+ n += " ".repeat(i), t += i;
255
+ } else n += r, t++;
256
+ return n;
257
+ }
258
+ function me(u, e, t, n, r) {
259
+ let i = e.href, s = e.title || null, a = u[1].replace(r.other.outputLinkReplace, "$1");
260
+ n.state.inLink = !0;
261
+ let o = {
262
+ type: u[0].charAt(0) === "!" ? "image" : "link",
263
+ raw: t,
264
+ href: i,
265
+ title: s,
266
+ text: a,
267
+ tokens: n.inlineTokens(a)
268
+ };
269
+ return n.state.inLink = !1, o;
270
+ }
271
+ function it(u, e, t) {
272
+ let n = u.match(t.other.indentCodeCompensation);
273
+ if (n === null) return e;
274
+ let r = n[1];
275
+ return e.split(`
276
+ `).map((i) => {
277
+ let s = i.match(t.other.beginningSpace);
278
+ if (s === null) return i;
279
+ let [a] = s;
280
+ return a.length >= r.length ? i.slice(r.length) : i;
281
+ }).join(`
282
+ `);
283
+ }
284
+ var w = class {
285
+ options;
286
+ rules;
287
+ lexer;
288
+ constructor(e) {
289
+ this.options = e || T;
290
+ }
291
+ space(e) {
292
+ let t = this.rules.block.newline.exec(e);
293
+ if (t && t[0].length > 0) return {
294
+ type: "space",
295
+ raw: t[0]
296
+ };
297
+ }
298
+ code(e) {
299
+ let t = this.rules.block.code.exec(e);
300
+ if (t) {
301
+ let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
302
+ return {
303
+ type: "code",
304
+ raw: t[0],
305
+ codeBlockStyle: "indented",
306
+ text: this.options.pedantic ? n : C(n, `
307
+ `)
308
+ };
309
+ }
310
+ }
311
+ fences(e) {
312
+ let t = this.rules.block.fences.exec(e);
313
+ if (t) {
314
+ let n = t[0], r = it(n, t[3] || "", this.rules);
315
+ return {
316
+ type: "code",
317
+ raw: n,
318
+ lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2],
319
+ text: r
320
+ };
321
+ }
322
+ }
323
+ heading(e) {
324
+ let t = this.rules.block.heading.exec(e);
325
+ if (t) {
326
+ let n = t[2].trim();
327
+ if (this.rules.other.endingHash.test(n)) {
328
+ let r = C(n, "#");
329
+ (this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
330
+ }
331
+ return {
332
+ type: "heading",
333
+ raw: t[0],
334
+ depth: t[1].length,
335
+ text: n,
336
+ tokens: this.lexer.inline(n)
337
+ };
338
+ }
339
+ }
340
+ hr(e) {
341
+ let t = this.rules.block.hr.exec(e);
342
+ if (t) return {
343
+ type: "hr",
344
+ raw: C(t[0], `
345
+ `)
346
+ };
347
+ }
348
+ blockquote(e) {
349
+ let t = this.rules.block.blockquote.exec(e);
350
+ if (t) {
351
+ let n = C(t[0], `
352
+ `).split(`
353
+ `), r = "", i = "", s = [];
354
+ for (; n.length > 0;) {
355
+ let a = !1, o = [], l;
356
+ for (l = 0; l < n.length; l++) if (this.rules.other.blockquoteStart.test(n[l])) o.push(n[l]), a = !0;
357
+ else if (!a) o.push(n[l]);
358
+ else break;
359
+ n = n.slice(l);
360
+ let p = o.join(`
361
+ `), c = p.replace(this.rules.other.blockquoteSetextReplace, `
362
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
363
+ r = r ? `${r}
364
+ ${p}` : p, i = i ? `${i}
365
+ ${c}` : c;
366
+ let d = this.lexer.state.top;
367
+ if (this.lexer.state.top = !0, this.lexer.blockTokens(c, s, !0), this.lexer.state.top = d, n.length === 0) break;
368
+ let h = s.at(-1);
369
+ if (h?.type === "code") break;
370
+ if (h?.type === "blockquote") {
371
+ let R = h, f = R.raw + `
372
+ ` + n.join(`
373
+ `), S = this.blockquote(f);
374
+ s[s.length - 1] = S, r = r.substring(0, r.length - R.raw.length) + S.raw, i = i.substring(0, i.length - R.text.length) + S.text;
375
+ break;
376
+ } else if (h?.type === "list") {
377
+ let R = h, f = R.raw + `
378
+ ` + n.join(`
379
+ `), S = this.list(f);
380
+ s[s.length - 1] = S, r = r.substring(0, r.length - h.raw.length) + S.raw, i = i.substring(0, i.length - R.raw.length) + S.raw, n = f.substring(s.at(-1).raw.length).split(`
381
+ `);
382
+ continue;
383
+ }
384
+ }
385
+ return {
386
+ type: "blockquote",
387
+ raw: r,
388
+ tokens: s,
389
+ text: i
390
+ };
391
+ }
392
+ }
393
+ list(e) {
394
+ let t = this.rules.block.list.exec(e);
395
+ if (t) {
396
+ let n = t[1].trim(), r = n.length > 1, i = {
397
+ type: "list",
398
+ raw: "",
399
+ ordered: r,
400
+ start: r ? +n.slice(0, -1) : "",
401
+ loose: !1,
402
+ items: []
403
+ };
404
+ n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
405
+ let s = this.rules.other.listItemRegex(n), a = !1;
406
+ for (; e;) {
407
+ let l = !1, p = "", c = "";
408
+ if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
409
+ p = t[0], e = e.substring(p.length);
410
+ let d = fe(t[2].split(`
411
+ `, 1)[0], t[1].length), h = e.split(`
412
+ `, 1)[0], R = !d.trim(), f = 0;
413
+ if (this.options.pedantic ? (f = 2, c = d.trimStart()) : R ? f = t[1].length + 1 : (f = d.search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = d.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (p += h + `
414
+ `, e = e.substring(h.length + 1), l = !0), !l) {
415
+ let S = this.rules.other.nextBulletRegex(f), V = this.rules.other.hrRegex(f), Y = this.rules.other.fencesBeginRegex(f), ee = this.rules.other.headingBeginRegex(f), xe = this.rules.other.htmlBeginRegex(f), be = this.rules.other.blockquoteBeginRegex(f);
416
+ for (; e;) {
417
+ let G = e.split(`
418
+ `, 1)[0], A;
419
+ if (h = G, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), A = h) : A = h.replace(this.rules.other.tabCharGlobal, " "), Y.test(h) || ee.test(h) || xe.test(h) || be.test(h) || S.test(h) || V.test(h)) break;
420
+ if (A.search(this.rules.other.nonSpaceChar) >= f || !h.trim()) c += `
421
+ ` + A.slice(f);
422
+ else {
423
+ if (R || d.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(d) || ee.test(d) || V.test(d)) break;
424
+ c += `
425
+ ` + h;
426
+ }
427
+ R = !h.trim(), p += G + `
428
+ `, e = e.substring(G.length + 1), d = A.slice(f);
429
+ }
430
+ }
431
+ i.loose || (a ? i.loose = !0 : this.rules.other.doubleBlankLine.test(p) && (a = !0)), i.items.push({
432
+ type: "list_item",
433
+ raw: p,
434
+ task: !!this.options.gfm && this.rules.other.listIsTask.test(c),
435
+ loose: !1,
436
+ text: c,
437
+ tokens: []
438
+ }), i.raw += p;
439
+ }
440
+ let o = i.items.at(-1);
441
+ if (o) o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
442
+ else return;
443
+ i.raw = i.raw.trimEnd();
444
+ for (let l of i.items) {
445
+ if (this.lexer.state.top = !1, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
446
+ if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
447
+ 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, "");
448
+ for (let c = this.lexer.inlineQueue.length - 1; c >= 0; c--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
449
+ this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
450
+ break;
451
+ }
452
+ }
453
+ let p = this.rules.other.listTaskCheckbox.exec(l.raw);
454
+ if (p) {
455
+ let c = {
456
+ type: "checkbox",
457
+ raw: p[0] + " ",
458
+ checked: p[0] !== "[ ]"
459
+ };
460
+ l.checked = c.checked, i.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({
461
+ type: "paragraph",
462
+ raw: c.raw,
463
+ text: c.raw,
464
+ tokens: [c]
465
+ }) : l.tokens.unshift(c);
466
+ }
467
+ }
468
+ if (!i.loose) {
469
+ let p = l.tokens.filter((d) => d.type === "space");
470
+ i.loose = p.length > 0 && p.some((d) => this.rules.other.anyLine.test(d.raw));
471
+ }
472
+ }
473
+ if (i.loose) for (let l of i.items) {
474
+ l.loose = !0;
475
+ for (let p of l.tokens) p.type === "text" && (p.type = "paragraph");
476
+ }
477
+ return i;
478
+ }
479
+ }
480
+ html(e) {
481
+ let t = this.rules.block.html.exec(e);
482
+ if (t) return {
483
+ type: "html",
484
+ block: !0,
485
+ raw: t[0],
486
+ pre: t[1] === "pre" || t[1] === "script" || t[1] === "style",
487
+ text: t[0]
488
+ };
489
+ }
490
+ def(e) {
491
+ let t = this.rules.block.def.exec(e);
492
+ if (t) {
493
+ let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), r = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
494
+ return {
495
+ type: "def",
496
+ tag: n,
497
+ raw: t[0],
498
+ href: r,
499
+ title: i
500
+ };
501
+ }
502
+ }
503
+ table(e) {
504
+ let t = this.rules.block.table.exec(e);
505
+ if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
506
+ let n = J(t[1]), r = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
507
+ `) : [], s = {
508
+ type: "table",
509
+ raw: t[0],
510
+ header: [],
511
+ align: [],
512
+ rows: []
513
+ };
514
+ if (n.length === r.length) {
515
+ for (let a of r) this.rules.other.tableAlignRight.test(a) ? s.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? s.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? s.align.push("left") : s.align.push(null);
516
+ for (let a = 0; a < n.length; a++) s.header.push({
517
+ text: n[a],
518
+ tokens: this.lexer.inline(n[a]),
519
+ header: !0,
520
+ align: s.align[a]
521
+ });
522
+ for (let a of i) s.rows.push(J(a, s.header.length).map((o, l) => ({
523
+ text: o,
524
+ tokens: this.lexer.inline(o),
525
+ header: !1,
526
+ align: s.align[l]
527
+ })));
528
+ return s;
529
+ }
530
+ }
531
+ lheading(e) {
532
+ let t = this.rules.block.lheading.exec(e);
533
+ if (t) return {
534
+ type: "heading",
535
+ raw: t[0],
536
+ depth: t[2].charAt(0) === "=" ? 1 : 2,
537
+ text: t[1],
538
+ tokens: this.lexer.inline(t[1])
539
+ };
540
+ }
541
+ paragraph(e) {
542
+ let t = this.rules.block.paragraph.exec(e);
543
+ if (t) {
544
+ let n = t[1].charAt(t[1].length - 1) === `
545
+ ` ? t[1].slice(0, -1) : t[1];
546
+ return {
547
+ type: "paragraph",
548
+ raw: t[0],
549
+ text: n,
550
+ tokens: this.lexer.inline(n)
551
+ };
552
+ }
553
+ }
554
+ text(e) {
555
+ let t = this.rules.block.text.exec(e);
556
+ if (t) return {
557
+ type: "text",
558
+ raw: t[0],
559
+ text: t[0],
560
+ tokens: this.lexer.inline(t[0])
561
+ };
562
+ }
563
+ escape(e) {
564
+ let t = this.rules.inline.escape.exec(e);
565
+ if (t) return {
566
+ type: "escape",
567
+ raw: t[0],
568
+ text: t[1]
569
+ };
570
+ }
571
+ tag(e) {
572
+ let t = this.rules.inline.tag.exec(e);
573
+ if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = !1), {
574
+ type: "html",
575
+ raw: t[0],
576
+ inLink: this.lexer.state.inLink,
577
+ inRawBlock: this.lexer.state.inRawBlock,
578
+ block: !1,
579
+ text: t[0]
580
+ };
581
+ }
582
+ link(e) {
583
+ let t = this.rules.inline.link.exec(e);
584
+ if (t) {
585
+ let n = t[2].trim();
586
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
587
+ if (!this.rules.other.endAngleBracket.test(n)) return;
588
+ let s = C(n.slice(0, -1), "\\");
589
+ if ((n.length - s.length) % 2 === 0) return;
590
+ } else {
591
+ let s = ge(t[2], "()");
592
+ if (s === -2) return;
593
+ if (s > -1) {
594
+ let o = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + s;
595
+ t[2] = t[2].substring(0, s), t[0] = t[0].substring(0, o).trim(), t[3] = "";
596
+ }
597
+ }
598
+ let r = t[2], i = "";
599
+ if (this.options.pedantic) {
600
+ let s = this.rules.other.pedanticHrefTitle.exec(r);
601
+ s && (r = s[1], i = s[3]);
602
+ } else i = t[3] ? t[3].slice(1, -1) : "";
603
+ return r = r.trim(), this.rules.other.startAngleBracket.test(r) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? r = r.slice(1) : r = r.slice(1, -1)), me(t, {
604
+ href: r && r.replace(this.rules.inline.anyPunctuation, "$1"),
605
+ title: i && i.replace(this.rules.inline.anyPunctuation, "$1")
606
+ }, t[0], this.lexer, this.rules);
607
+ }
608
+ }
609
+ reflink(e, t) {
610
+ let n;
611
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
612
+ let i = t[(n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " ").toLowerCase()];
613
+ if (!i) {
614
+ let s = n[0].charAt(0);
615
+ return {
616
+ type: "text",
617
+ raw: s,
618
+ text: s
619
+ };
620
+ }
621
+ return me(n, i, n[0], this.lexer, this.rules);
622
+ }
623
+ }
624
+ emStrong(e, t, n = "") {
625
+ let r = this.rules.inline.emStrongLDelim.exec(e);
626
+ if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
627
+ if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
628
+ let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
629
+ for (c.lastIndex = 0, t = t.slice(-1 * e.length + s); (r = c.exec(t)) != null;) {
630
+ if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a) continue;
631
+ if (o = [...a].length, r[3] || r[4]) {
632
+ l += o;
633
+ continue;
634
+ } else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
635
+ p += o;
636
+ continue;
637
+ }
638
+ if (l -= o, l > 0) continue;
639
+ o = Math.min(o, o + l + p);
640
+ let d = [...r[0]][0].length, h = e.slice(0, s + r.index + d + o);
641
+ if (Math.min(s, o) % 2) {
642
+ let f = h.slice(1, -1);
643
+ return {
644
+ type: "em",
645
+ raw: h,
646
+ text: f,
647
+ tokens: this.lexer.inlineTokens(f)
648
+ };
649
+ }
650
+ let R = h.slice(2, -2);
651
+ return {
652
+ type: "strong",
653
+ raw: h,
654
+ text: R,
655
+ tokens: this.lexer.inlineTokens(R)
656
+ };
657
+ }
658
+ }
659
+ }
660
+ codespan(e) {
661
+ let t = this.rules.inline.code.exec(e);
662
+ if (t) {
663
+ let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), r = this.rules.other.nonSpaceChar.test(n), i = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
664
+ return r && i && (n = n.substring(1, n.length - 1)), {
665
+ type: "codespan",
666
+ raw: t[0],
667
+ text: n
668
+ };
669
+ }
670
+ }
671
+ br(e) {
672
+ let t = this.rules.inline.br.exec(e);
673
+ if (t) return {
674
+ type: "br",
675
+ raw: t[0]
676
+ };
677
+ }
678
+ del(e, t, n = "") {
679
+ let r = this.rules.inline.delLDelim.exec(e);
680
+ if (!r) return;
681
+ if (!(r[1] || "") || !n || this.rules.inline.punctuation.exec(n)) {
682
+ let s = [...r[0]].length - 1, a, o, l = s, p = this.rules.inline.delRDelim;
683
+ for (p.lastIndex = 0, t = t.slice(-1 * e.length + s); (r = p.exec(t)) != null;) {
684
+ if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a || (o = [...a].length, o !== s)) continue;
685
+ if (r[3] || r[4]) {
686
+ l += o;
687
+ continue;
688
+ }
689
+ if (l -= o, l > 0) continue;
690
+ o = Math.min(o, o + l);
691
+ let c = [...r[0]][0].length, d = e.slice(0, s + r.index + c + o), h = d.slice(s, -s);
692
+ return {
693
+ type: "del",
694
+ raw: d,
695
+ text: h,
696
+ tokens: this.lexer.inlineTokens(h)
697
+ };
698
+ }
699
+ }
700
+ }
701
+ autolink(e) {
702
+ let t = this.rules.inline.autolink.exec(e);
703
+ if (t) {
704
+ let n, r;
705
+ return t[2] === "@" ? (n = t[1], r = "mailto:" + n) : (n = t[1], r = n), {
706
+ type: "link",
707
+ raw: t[0],
708
+ text: n,
709
+ href: r,
710
+ tokens: [{
711
+ type: "text",
712
+ raw: n,
713
+ text: n
714
+ }]
715
+ };
716
+ }
717
+ }
718
+ url(e) {
719
+ let t;
720
+ if (t = this.rules.inline.url.exec(e)) {
721
+ let n, r;
722
+ if (t[2] === "@") n = t[0], r = "mailto:" + n;
723
+ else {
724
+ let i;
725
+ do
726
+ i = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
727
+ while (i !== t[0]);
728
+ n = t[0], t[1] === "www." ? r = "http://" + t[0] : r = t[0];
729
+ }
730
+ return {
731
+ type: "link",
732
+ raw: t[0],
733
+ text: n,
734
+ href: r,
735
+ tokens: [{
736
+ type: "text",
737
+ raw: n,
738
+ text: n
739
+ }]
740
+ };
741
+ }
742
+ }
743
+ inlineText(e) {
744
+ let t = this.rules.inline.text.exec(e);
745
+ if (t) {
746
+ let n = this.lexer.state.inRawBlock;
747
+ return {
748
+ type: "text",
749
+ raw: t[0],
750
+ text: t[0],
751
+ escaped: n
752
+ };
753
+ }
754
+ }
755
+ };
756
+ var x = class u {
757
+ tokens;
758
+ options;
759
+ state;
760
+ inlineQueue;
761
+ tokenizer;
762
+ constructor(e) {
763
+ this.tokens = [], this.tokens.links = Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new w(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
764
+ inLink: !1,
765
+ inRawBlock: !1,
766
+ top: !0
767
+ };
768
+ let t = {
769
+ other: m,
770
+ block: E.normal,
771
+ inline: z.normal
772
+ };
773
+ this.options.pedantic ? (t.block = E.pedantic, t.inline = z.pedantic) : this.options.gfm && (t.block = E.gfm, this.options.breaks ? t.inline = z.breaks : t.inline = z.gfm), this.tokenizer.rules = t;
774
+ }
775
+ static get rules() {
776
+ return {
777
+ block: E,
778
+ inline: z
779
+ };
780
+ }
781
+ static lex(e, t) {
782
+ return new u(t).lex(e);
783
+ }
784
+ static lexInline(e, t) {
785
+ return new u(t).inlineTokens(e);
786
+ }
787
+ lex(e) {
788
+ e = e.replace(m.carriageReturn, `
789
+ `), this.blockTokens(e, this.tokens);
790
+ for (let t = 0; t < this.inlineQueue.length; t++) {
791
+ let n = this.inlineQueue[t];
792
+ this.inlineTokens(n.src, n.tokens);
793
+ }
794
+ return this.inlineQueue = [], this.tokens;
795
+ }
796
+ blockTokens(e, t = [], n = !1) {
797
+ for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, "")); e;) {
798
+ let r;
799
+ if (this.options.extensions?.block?.some((s) => (r = s.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), !0) : !1)) continue;
800
+ if (r = this.tokenizer.space(e)) {
801
+ e = e.substring(r.raw.length);
802
+ let s = t.at(-1);
803
+ r.raw.length === 1 && s !== void 0 ? s.raw += `
804
+ ` : t.push(r);
805
+ continue;
806
+ }
807
+ if (r = this.tokenizer.code(e)) {
808
+ e = e.substring(r.raw.length);
809
+ let s = t.at(-1);
810
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
811
+ `) ? "" : `
812
+ `) + r.raw, s.text += `
813
+ ` + r.text, this.inlineQueue.at(-1).src = s.text) : t.push(r);
814
+ continue;
815
+ }
816
+ if (r = this.tokenizer.fences(e)) {
817
+ e = e.substring(r.raw.length), t.push(r);
818
+ continue;
819
+ }
820
+ if (r = this.tokenizer.heading(e)) {
821
+ e = e.substring(r.raw.length), t.push(r);
822
+ continue;
823
+ }
824
+ if (r = this.tokenizer.hr(e)) {
825
+ e = e.substring(r.raw.length), t.push(r);
826
+ continue;
827
+ }
828
+ if (r = this.tokenizer.blockquote(e)) {
829
+ e = e.substring(r.raw.length), t.push(r);
830
+ continue;
831
+ }
832
+ if (r = this.tokenizer.list(e)) {
833
+ e = e.substring(r.raw.length), t.push(r);
834
+ continue;
835
+ }
836
+ if (r = this.tokenizer.html(e)) {
837
+ e = e.substring(r.raw.length), t.push(r);
838
+ continue;
839
+ }
840
+ if (r = this.tokenizer.def(e)) {
841
+ e = e.substring(r.raw.length);
842
+ let s = t.at(-1);
843
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
844
+ `) ? "" : `
845
+ `) + r.raw, s.text += `
846
+ ` + r.raw, this.inlineQueue.at(-1).src = s.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = {
847
+ href: r.href,
848
+ title: r.title
849
+ }, t.push(r));
850
+ continue;
851
+ }
852
+ if (r = this.tokenizer.table(e)) {
853
+ e = e.substring(r.raw.length), t.push(r);
854
+ continue;
855
+ }
856
+ if (r = this.tokenizer.lheading(e)) {
857
+ e = e.substring(r.raw.length), t.push(r);
858
+ continue;
859
+ }
860
+ let i = e;
861
+ if (this.options.extensions?.startBlock) {
862
+ let s = Infinity, a = e.slice(1), o;
863
+ this.options.extensions.startBlock.forEach((l) => {
864
+ o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
865
+ }), s < Infinity && s >= 0 && (i = e.substring(0, s + 1));
866
+ }
867
+ if (this.state.top && (r = this.tokenizer.paragraph(i))) {
868
+ let s = t.at(-1);
869
+ n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
870
+ `) ? "" : `
871
+ `) + r.raw, s.text += `
872
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
873
+ continue;
874
+ }
875
+ if (r = this.tokenizer.text(e)) {
876
+ e = e.substring(r.raw.length);
877
+ let s = t.at(-1);
878
+ s?.type === "text" ? (s.raw += (s.raw.endsWith(`
879
+ `) ? "" : `
880
+ `) + r.raw, s.text += `
881
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r);
882
+ continue;
883
+ }
884
+ if (e) {
885
+ let s = "Infinite loop on byte: " + e.charCodeAt(0);
886
+ if (this.options.silent) {
887
+ console.error(s);
888
+ break;
889
+ } else throw new Error(s);
890
+ }
891
+ }
892
+ return this.state.top = !0, t;
893
+ }
894
+ inline(e, t = []) {
895
+ return this.inlineQueue.push({
896
+ src: e,
897
+ tokens: t
898
+ }), t;
899
+ }
900
+ inlineTokens(e, t = []) {
901
+ let n = e, r = null;
902
+ if (this.tokens.links) {
903
+ let o = Object.keys(this.tokens.links);
904
+ if (o.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null;) o.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
905
+ }
906
+ for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null;) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
907
+ let i;
908
+ for (; (r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null;) i = r[2] ? r[2].length : 0, n = n.slice(0, r.index + i) + "[" + "a".repeat(r[0].length - i - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
909
+ n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
910
+ let s = !1, a = "";
911
+ for (; e;) {
912
+ s || (a = ""), s = !1;
913
+ let o;
914
+ if (this.options.extensions?.inline?.some((p) => (o = p.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), !0) : !1)) continue;
915
+ if (o = this.tokenizer.escape(e)) {
916
+ e = e.substring(o.raw.length), t.push(o);
917
+ continue;
918
+ }
919
+ if (o = this.tokenizer.tag(e)) {
920
+ e = e.substring(o.raw.length), t.push(o);
921
+ continue;
922
+ }
923
+ if (o = this.tokenizer.link(e)) {
924
+ e = e.substring(o.raw.length), t.push(o);
925
+ continue;
926
+ }
927
+ if (o = this.tokenizer.reflink(e, this.tokens.links)) {
928
+ e = e.substring(o.raw.length);
929
+ let p = t.at(-1);
930
+ o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
931
+ continue;
932
+ }
933
+ if (o = this.tokenizer.emStrong(e, n, a)) {
934
+ e = e.substring(o.raw.length), t.push(o);
935
+ continue;
936
+ }
937
+ if (o = this.tokenizer.codespan(e)) {
938
+ e = e.substring(o.raw.length), t.push(o);
939
+ continue;
940
+ }
941
+ if (o = this.tokenizer.br(e)) {
942
+ e = e.substring(o.raw.length), t.push(o);
943
+ continue;
944
+ }
945
+ if (o = this.tokenizer.del(e, n, a)) {
946
+ e = e.substring(o.raw.length), t.push(o);
947
+ continue;
948
+ }
949
+ if (o = this.tokenizer.autolink(e)) {
950
+ e = e.substring(o.raw.length), t.push(o);
951
+ continue;
952
+ }
953
+ if (!this.state.inLink && (o = this.tokenizer.url(e))) {
954
+ e = e.substring(o.raw.length), t.push(o);
955
+ continue;
956
+ }
957
+ let l = e;
958
+ if (this.options.extensions?.startInline) {
959
+ let p = Infinity, c = e.slice(1), d;
960
+ this.options.extensions.startInline.forEach((h) => {
961
+ d = h.call({ lexer: this }, c), typeof d == "number" && d >= 0 && (p = Math.min(p, d));
962
+ }), p < Infinity && p >= 0 && (l = e.substring(0, p + 1));
963
+ }
964
+ if (o = this.tokenizer.inlineText(l)) {
965
+ e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = !0;
966
+ let p = t.at(-1);
967
+ p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
968
+ continue;
969
+ }
970
+ if (e) {
971
+ let p = "Infinite loop on byte: " + e.charCodeAt(0);
972
+ if (this.options.silent) {
973
+ console.error(p);
974
+ break;
975
+ } else throw new Error(p);
976
+ }
977
+ }
978
+ return t;
979
+ }
980
+ };
981
+ var y = class {
982
+ options;
983
+ parser;
984
+ constructor(e) {
985
+ this.options = e || T;
986
+ }
987
+ space(e) {
988
+ return "";
989
+ }
990
+ code({ text: e, lang: t, escaped: n }) {
991
+ let r = (t || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
992
+ `;
993
+ return r ? "<pre><code class=\"language-" + O(r) + "\">" + (n ? i : O(i, !0)) + `</code></pre>
994
+ ` : "<pre><code>" + (n ? i : O(i, !0)) + `</code></pre>
995
+ `;
996
+ }
997
+ blockquote({ tokens: e }) {
998
+ return `<blockquote>
999
+ ${this.parser.parse(e)}</blockquote>
1000
+ `;
1001
+ }
1002
+ html({ text: e }) {
1003
+ return e;
1004
+ }
1005
+ def(e) {
1006
+ return "";
1007
+ }
1008
+ heading({ tokens: e, depth: t }) {
1009
+ return `<h${t}>${this.parser.parseInline(e)}</h${t}>
1010
+ `;
1011
+ }
1012
+ hr(e) {
1013
+ return `<hr>
1014
+ `;
1015
+ }
1016
+ list(e) {
1017
+ let t = e.ordered, n = e.start, r = "";
1018
+ for (let a = 0; a < e.items.length; a++) {
1019
+ let o = e.items[a];
1020
+ r += this.listitem(o);
1021
+ }
1022
+ let i = t ? "ol" : "ul", s = t && n !== 1 ? " start=\"" + n + "\"" : "";
1023
+ return "<" + i + s + `>
1024
+ ` + r + "</" + i + `>
1025
+ `;
1026
+ }
1027
+ listitem(e) {
1028
+ return `<li>${this.parser.parse(e.tokens)}</li>
1029
+ `;
1030
+ }
1031
+ checkbox({ checked: e }) {
1032
+ return "<input " + (e ? "checked=\"\" " : "") + "disabled=\"\" type=\"checkbox\"> ";
1033
+ }
1034
+ paragraph({ tokens: e }) {
1035
+ return `<p>${this.parser.parseInline(e)}</p>
1036
+ `;
1037
+ }
1038
+ table(e) {
1039
+ let t = "", n = "";
1040
+ for (let i = 0; i < e.header.length; i++) n += this.tablecell(e.header[i]);
1041
+ t += this.tablerow({ text: n });
1042
+ let r = "";
1043
+ for (let i = 0; i < e.rows.length; i++) {
1044
+ let s = e.rows[i];
1045
+ n = "";
1046
+ for (let a = 0; a < s.length; a++) n += this.tablecell(s[a]);
1047
+ r += this.tablerow({ text: n });
1048
+ }
1049
+ return r && (r = `<tbody>${r}</tbody>`), `<table>
1050
+ <thead>
1051
+ ` + t + `</thead>
1052
+ ` + r + `</table>
1053
+ `;
1054
+ }
1055
+ tablerow({ text: e }) {
1056
+ return `<tr>
1057
+ ${e}</tr>
1058
+ `;
1059
+ }
1060
+ tablecell(e) {
1061
+ let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
1062
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
1063
+ `;
1064
+ }
1065
+ strong({ tokens: e }) {
1066
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
1067
+ }
1068
+ em({ tokens: e }) {
1069
+ return `<em>${this.parser.parseInline(e)}</em>`;
1070
+ }
1071
+ codespan({ text: e }) {
1072
+ return `<code>${O(e, !0)}</code>`;
1073
+ }
1074
+ br(e) {
1075
+ return "<br>";
1076
+ }
1077
+ del({ tokens: e }) {
1078
+ return `<del>${this.parser.parseInline(e)}</del>`;
1079
+ }
1080
+ link({ href: e, title: t, tokens: n }) {
1081
+ let r = this.parser.parseInline(n), i = X(e);
1082
+ if (i === null) return r;
1083
+ e = i;
1084
+ let s = "<a href=\"" + e + "\"";
1085
+ return t && (s += " title=\"" + O(t) + "\""), s += ">" + r + "</a>", s;
1086
+ }
1087
+ image({ href: e, title: t, text: n, tokens: r }) {
1088
+ r && (n = this.parser.parseInline(r, this.parser.textRenderer));
1089
+ let i = X(e);
1090
+ if (i === null) return O(n);
1091
+ e = i;
1092
+ let s = `<img src="${e}" alt="${O(n)}"`;
1093
+ return t && (s += ` title="${O(t)}"`), s += ">", s;
1094
+ }
1095
+ text(e) {
1096
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : O(e.text);
1097
+ }
1098
+ };
1099
+ var $ = class {
1100
+ strong({ text: e }) {
1101
+ return e;
1102
+ }
1103
+ em({ text: e }) {
1104
+ return e;
1105
+ }
1106
+ codespan({ text: e }) {
1107
+ return e;
1108
+ }
1109
+ del({ text: e }) {
1110
+ return e;
1111
+ }
1112
+ html({ text: e }) {
1113
+ return e;
1114
+ }
1115
+ text({ text: e }) {
1116
+ return e;
1117
+ }
1118
+ link({ text: e }) {
1119
+ return "" + e;
1120
+ }
1121
+ image({ text: e }) {
1122
+ return "" + e;
1123
+ }
1124
+ br() {
1125
+ return "";
1126
+ }
1127
+ checkbox({ raw: e }) {
1128
+ return e;
1129
+ }
1130
+ };
1131
+ var b = class u {
1132
+ options;
1133
+ renderer;
1134
+ textRenderer;
1135
+ constructor(e) {
1136
+ this.options = e || T, this.options.renderer = this.options.renderer || new y(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $();
1137
+ }
1138
+ static parse(e, t) {
1139
+ return new u(t).parse(e);
1140
+ }
1141
+ static parseInline(e, t) {
1142
+ return new u(t).parseInline(e);
1143
+ }
1144
+ parse(e) {
1145
+ let t = "";
1146
+ for (let n = 0; n < e.length; n++) {
1147
+ let r = e[n];
1148
+ if (this.options.extensions?.renderers?.[r.type]) {
1149
+ let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
1150
+ if (a !== !1 || ![
1151
+ "space",
1152
+ "hr",
1153
+ "heading",
1154
+ "code",
1155
+ "table",
1156
+ "blockquote",
1157
+ "list",
1158
+ "html",
1159
+ "def",
1160
+ "paragraph",
1161
+ "text"
1162
+ ].includes(s.type)) {
1163
+ t += a || "";
1164
+ continue;
1165
+ }
1166
+ }
1167
+ let i = r;
1168
+ switch (i.type) {
1169
+ case "space":
1170
+ t += this.renderer.space(i);
1171
+ break;
1172
+ case "hr":
1173
+ t += this.renderer.hr(i);
1174
+ break;
1175
+ case "heading":
1176
+ t += this.renderer.heading(i);
1177
+ break;
1178
+ case "code":
1179
+ t += this.renderer.code(i);
1180
+ break;
1181
+ case "table":
1182
+ t += this.renderer.table(i);
1183
+ break;
1184
+ case "blockquote":
1185
+ t += this.renderer.blockquote(i);
1186
+ break;
1187
+ case "list":
1188
+ t += this.renderer.list(i);
1189
+ break;
1190
+ case "checkbox":
1191
+ t += this.renderer.checkbox(i);
1192
+ break;
1193
+ case "html":
1194
+ t += this.renderer.html(i);
1195
+ break;
1196
+ case "def":
1197
+ t += this.renderer.def(i);
1198
+ break;
1199
+ case "paragraph":
1200
+ t += this.renderer.paragraph(i);
1201
+ break;
1202
+ case "text":
1203
+ t += this.renderer.text(i);
1204
+ break;
1205
+ default: {
1206
+ let s = "Token with \"" + i.type + "\" type was not found.";
1207
+ if (this.options.silent) return console.error(s), "";
1208
+ throw new Error(s);
1209
+ }
1210
+ }
1211
+ }
1212
+ return t;
1213
+ }
1214
+ parseInline(e, t = this.renderer) {
1215
+ let n = "";
1216
+ for (let r = 0; r < e.length; r++) {
1217
+ let i = e[r];
1218
+ if (this.options.extensions?.renderers?.[i.type]) {
1219
+ let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
1220
+ if (a !== !1 || ![
1221
+ "escape",
1222
+ "html",
1223
+ "link",
1224
+ "image",
1225
+ "strong",
1226
+ "em",
1227
+ "codespan",
1228
+ "br",
1229
+ "del",
1230
+ "text"
1231
+ ].includes(i.type)) {
1232
+ n += a || "";
1233
+ continue;
1234
+ }
1235
+ }
1236
+ let s = i;
1237
+ switch (s.type) {
1238
+ case "escape":
1239
+ n += t.text(s);
1240
+ break;
1241
+ case "html":
1242
+ n += t.html(s);
1243
+ break;
1244
+ case "link":
1245
+ n += t.link(s);
1246
+ break;
1247
+ case "image":
1248
+ n += t.image(s);
1249
+ break;
1250
+ case "checkbox":
1251
+ n += t.checkbox(s);
1252
+ break;
1253
+ case "strong":
1254
+ n += t.strong(s);
1255
+ break;
1256
+ case "em":
1257
+ n += t.em(s);
1258
+ break;
1259
+ case "codespan":
1260
+ n += t.codespan(s);
1261
+ break;
1262
+ case "br":
1263
+ n += t.br(s);
1264
+ break;
1265
+ case "del":
1266
+ n += t.del(s);
1267
+ break;
1268
+ case "text":
1269
+ n += t.text(s);
1270
+ break;
1271
+ default: {
1272
+ let a = "Token with \"" + s.type + "\" type was not found.";
1273
+ if (this.options.silent) return console.error(a), "";
1274
+ throw new Error(a);
1275
+ }
1276
+ }
1277
+ }
1278
+ return n;
1279
+ }
1280
+ };
1281
+ var P = class {
1282
+ options;
1283
+ block;
1284
+ constructor(e) {
1285
+ this.options = e || T;
1286
+ }
1287
+ static passThroughHooks = new Set([
1288
+ "preprocess",
1289
+ "postprocess",
1290
+ "processAllTokens",
1291
+ "emStrongMask"
1292
+ ]);
1293
+ static passThroughHooksRespectAsync = new Set([
1294
+ "preprocess",
1295
+ "postprocess",
1296
+ "processAllTokens"
1297
+ ]);
1298
+ preprocess(e) {
1299
+ return e;
1300
+ }
1301
+ postprocess(e) {
1302
+ return e;
1303
+ }
1304
+ processAllTokens(e) {
1305
+ return e;
1306
+ }
1307
+ emStrongMask(e) {
1308
+ return e;
1309
+ }
1310
+ provideLexer() {
1311
+ return this.block ? x.lex : x.lexInline;
1312
+ }
1313
+ provideParser() {
1314
+ return this.block ? b.parse : b.parseInline;
1315
+ }
1316
+ };
1317
+ var B = class {
1318
+ defaults = M();
1319
+ options = this.setOptions;
1320
+ parse = this.parseMarkdown(!0);
1321
+ parseInline = this.parseMarkdown(!1);
1322
+ Parser = b;
1323
+ Renderer = y;
1324
+ TextRenderer = $;
1325
+ Lexer = x;
1326
+ Tokenizer = w;
1327
+ Hooks = P;
1328
+ constructor(...e) {
1329
+ this.use(...e);
1330
+ }
1331
+ walkTokens(e, t) {
1332
+ let n = [];
1333
+ for (let r of e) switch (n = n.concat(t.call(this, r)), r.type) {
1334
+ case "table": {
1335
+ let i = r;
1336
+ for (let s of i.header) n = n.concat(this.walkTokens(s.tokens, t));
1337
+ for (let s of i.rows) for (let a of s) n = n.concat(this.walkTokens(a.tokens, t));
1338
+ break;
1339
+ }
1340
+ case "list": {
1341
+ let i = r;
1342
+ n = n.concat(this.walkTokens(i.items, t));
1343
+ break;
1344
+ }
1345
+ default: {
1346
+ let i = r;
1347
+ this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
1348
+ let a = i[s].flat(Infinity);
1349
+ n = n.concat(this.walkTokens(a, t));
1350
+ }) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t)));
1351
+ }
1352
+ }
1353
+ return n;
1354
+ }
1355
+ use(...e) {
1356
+ let t = this.defaults.extensions || {
1357
+ renderers: {},
1358
+ childTokens: {}
1359
+ };
1360
+ return e.forEach((n) => {
1361
+ let r = { ...n };
1362
+ if (r.async = this.defaults.async || r.async || !1, n.extensions && (n.extensions.forEach((i) => {
1363
+ if (!i.name) throw new Error("extension name required");
1364
+ if ("renderer" in i) {
1365
+ let s = t.renderers[i.name];
1366
+ s ? t.renderers[i.name] = function(...a) {
1367
+ let o = i.renderer.apply(this, a);
1368
+ return o === !1 && (o = s.apply(this, a)), o;
1369
+ } : t.renderers[i.name] = i.renderer;
1370
+ }
1371
+ if ("tokenizer" in i) {
1372
+ if (!i.level || i.level !== "block" && i.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
1373
+ let s = t[i.level];
1374
+ s ? s.unshift(i.tokenizer) : t[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t.startBlock ? t.startBlock.push(i.start) : t.startBlock = [i.start] : i.level === "inline" && (t.startInline ? t.startInline.push(i.start) : t.startInline = [i.start]));
1375
+ }
1376
+ "childTokens" in i && i.childTokens && (t.childTokens[i.name] = i.childTokens);
1377
+ }), r.extensions = t), n.renderer) {
1378
+ let i = this.defaults.renderer || new y(this.defaults);
1379
+ for (let s in n.renderer) {
1380
+ if (!(s in i)) throw new Error(`renderer '${s}' does not exist`);
1381
+ if (["options", "parser"].includes(s)) continue;
1382
+ let a = s, o = n.renderer[a], l = i[a];
1383
+ i[a] = (...p) => {
1384
+ let c = o.apply(i, p);
1385
+ return c === !1 && (c = l.apply(i, p)), c || "";
1386
+ };
1387
+ }
1388
+ r.renderer = i;
1389
+ }
1390
+ if (n.tokenizer) {
1391
+ let i = this.defaults.tokenizer || new w(this.defaults);
1392
+ for (let s in n.tokenizer) {
1393
+ if (!(s in i)) throw new Error(`tokenizer '${s}' does not exist`);
1394
+ if ([
1395
+ "options",
1396
+ "rules",
1397
+ "lexer"
1398
+ ].includes(s)) continue;
1399
+ let a = s, o = n.tokenizer[a], l = i[a];
1400
+ i[a] = (...p) => {
1401
+ let c = o.apply(i, p);
1402
+ return c === !1 && (c = l.apply(i, p)), c;
1403
+ };
1404
+ }
1405
+ r.tokenizer = i;
1406
+ }
1407
+ if (n.hooks) {
1408
+ let i = this.defaults.hooks || new P();
1409
+ for (let s in n.hooks) {
1410
+ if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
1411
+ if (["options", "block"].includes(s)) continue;
1412
+ let a = s, o = n.hooks[a], l = i[a];
1413
+ P.passThroughHooks.has(s) ? i[a] = (p) => {
1414
+ if (this.defaults.async && P.passThroughHooksRespectAsync.has(s)) return (async () => {
1415
+ let d = await o.call(i, p);
1416
+ return l.call(i, d);
1417
+ })();
1418
+ let c = o.call(i, p);
1419
+ return l.call(i, c);
1420
+ } : i[a] = (...p) => {
1421
+ if (this.defaults.async) return (async () => {
1422
+ let d = await o.apply(i, p);
1423
+ return d === !1 && (d = await l.apply(i, p)), d;
1424
+ })();
1425
+ let c = o.apply(i, p);
1426
+ return c === !1 && (c = l.apply(i, p)), c;
1427
+ };
1428
+ }
1429
+ r.hooks = i;
1430
+ }
1431
+ if (n.walkTokens) {
1432
+ let i = this.defaults.walkTokens, s = n.walkTokens;
1433
+ r.walkTokens = function(a) {
1434
+ let o = [];
1435
+ return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
1436
+ };
1437
+ }
1438
+ this.defaults = {
1439
+ ...this.defaults,
1440
+ ...r
1441
+ };
1442
+ }), this;
1443
+ }
1444
+ setOptions(e) {
1445
+ return this.defaults = {
1446
+ ...this.defaults,
1447
+ ...e
1448
+ }, this;
1449
+ }
1450
+ lexer(e, t) {
1451
+ return x.lex(e, t ?? this.defaults);
1452
+ }
1453
+ parser(e, t) {
1454
+ return b.parse(e, t ?? this.defaults);
1455
+ }
1456
+ parseMarkdown(e) {
1457
+ return (n, r) => {
1458
+ let i = { ...r }, s = {
1459
+ ...this.defaults,
1460
+ ...i
1461
+ }, a = this.onError(!!s.silent, !!s.async);
1462
+ if (this.defaults.async === !0 && i.async === !1) return a(/* @__PURE__ */ 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."));
1463
+ if (typeof n > "u" || n === null) return a(/* @__PURE__ */ new Error("marked(): input parameter is undefined or null"));
1464
+ if (typeof n != "string") return a(/* @__PURE__ */ new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
1465
+ if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async) return (async () => {
1466
+ let o = s.hooks ? await s.hooks.preprocess(n) : n, p = await (s.hooks ? await s.hooks.provideLexer() : e ? x.lex : x.lexInline)(o, s), c = s.hooks ? await s.hooks.processAllTokens(p) : p;
1467
+ s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
1468
+ let h = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
1469
+ return s.hooks ? await s.hooks.postprocess(h) : h;
1470
+ })().catch(a);
1471
+ try {
1472
+ s.hooks && (n = s.hooks.preprocess(n));
1473
+ let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
1474
+ s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
1475
+ let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
1476
+ return s.hooks && (c = s.hooks.postprocess(c)), c;
1477
+ } catch (o) {
1478
+ return a(o);
1479
+ }
1480
+ };
1481
+ }
1482
+ onError(e, t) {
1483
+ return (n) => {
1484
+ if (n.message += `
1485
+ Please report this to https://github.com/markedjs/marked.`, e) {
1486
+ let r = "<p>An error occurred:</p><pre>" + O(n.message + "", !0) + "</pre>";
1487
+ return t ? Promise.resolve(r) : r;
1488
+ }
1489
+ if (t) return Promise.reject(n);
1490
+ throw n;
1491
+ };
1492
+ }
1493
+ };
1494
+ var L = new B();
1495
+ function g(u, e) {
1496
+ return L.parse(u, e);
1497
+ }
1498
+ g.options = g.setOptions = function(u) {
1499
+ return L.setOptions(u), g.defaults = L.defaults, H(g.defaults), g;
1500
+ };
1501
+ g.getDefaults = M;
1502
+ g.defaults = T;
1503
+ g.use = function(...u) {
1504
+ return L.use(...u), g.defaults = L.defaults, H(g.defaults), g;
1505
+ };
1506
+ g.walkTokens = function(u, e) {
1507
+ return L.walkTokens(u, e);
1508
+ };
1509
+ g.parseInline = L.parseInline;
1510
+ g.Parser = b;
1511
+ g.parser = b.parse;
1512
+ g.Renderer = y;
1513
+ g.TextRenderer = $;
1514
+ g.Lexer = x;
1515
+ g.lexer = x.lex;
1516
+ g.Tokenizer = w;
1517
+ g.Hooks = P;
1518
+ g.parse = g;
1519
+ var Ut = g.options, Kt = g.setOptions, Wt = g.use, Xt = g.walkTokens, Jt = g.parseInline, Vt = g, Yt = b.parse, en = x.lex;
1520
+
1521
+ //#endregion
1522
+ //#region src/normalize.ts
1523
+ const METADATA_START_REGEX = /^---\r?\n/;
1524
+ const METADATA_END_REGEX = /\r?\n---(\r?\n|$)/;
1525
+ function normalizeMarkdown(markdown) {
1526
+ let content = markdown;
1527
+ if (content[0] === "") content = content.slice(1);
1528
+ if (!METADATA_START_REGEX.test(content)) return {
1529
+ metadata: void 0,
1530
+ content
1531
+ };
1532
+ const endIndex = content.search(METADATA_END_REGEX);
1533
+ if (endIndex < 0) return {
1534
+ metadata: void 0,
1535
+ content
1536
+ };
1537
+ return {
1538
+ metadata: content.slice(4, endIndex),
1539
+ content: content.slice(endIndex + 5)
1540
+ };
1541
+ }
1542
+
1543
+ //#endregion
1544
+ //#region src/parser.ts
1545
+ function parse(markdown) {
1546
+ const { metadata, content } = normalizeMarkdown(markdown);
1547
+ const tokens = new x({ silent: true }).lex(content);
1548
+ const root = {
1549
+ tokens: [],
1550
+ range: {
1551
+ start: 0,
1552
+ end: 0
1553
+ },
1554
+ numbers: [],
1555
+ children: []
1556
+ };
1557
+ const stack = [root];
1558
+ let index = 0;
1559
+ for (const token of tokens) {
1560
+ const startIndex = index;
1561
+ index += token.raw.length;
1562
+ const currentSection = stack[stack.length - 1];
1563
+ if (token.type !== "heading") {
1564
+ currentSection.range.end = index;
1565
+ currentSection.tokens.push(token);
1566
+ continue;
1567
+ }
1568
+ currentSection.range.end = startIndex;
1569
+ const head = token;
1570
+ const parentIndex = stack.findLastIndex((sect) => {
1571
+ return (sect.headingToken?.depth || 0) < head.depth;
1572
+ });
1573
+ const parent = stack[parentIndex];
1574
+ const sect = {
1575
+ headingToken: head,
1576
+ numbers: [...parent.numbers, parent.children.length + 1],
1577
+ tokens: [],
1578
+ range: {
1579
+ start: startIndex,
1580
+ end: index
1581
+ },
1582
+ parent,
1583
+ children: []
1584
+ };
1585
+ stack.length = parentIndex + 1;
1586
+ stack.push(sect);
1587
+ parent.children.push(sect);
1588
+ }
1589
+ return {
1590
+ content: markdown,
1591
+ metadata,
1592
+ root
1593
+ };
1594
+ }
1595
+
15
1596
  //#endregion
16
1597
  //#region src/cli.ts
17
- program.description("Parse and display specific contents of a markdown").argument("[path]", "Path to the markdown file, optional with --content or --stdin flag").option("-c, --content <content>", "Markdown content provided as a string").option("-i, --stdin", "Read markdown content from stdin").option("-m, --metadata", "Print metadata").option("-t, --toc", "Print table of contents").option("-s, --section <section>", "Print specific section (e.g. \"Introduction\" or \"#2\")").action(async (file, options) => {
18
- if (!file && !options.content && !options.stdin) program.addHelpText("after", "\nError: Please provide a file path / markdown content / or the stdin flag").help();
19
- const content = await getContent({
1598
+ program.description("Parse and display specific contents of a markdown").argument("[path]", "Path to the markdown file, optional with --content or --stdin flag").option("-c, --content <content>", "Markdown content provided as a string").option("-i, --stdin", "Read markdown content from stdin").option("-m, --metadata", "Print metadata").option("-t, --toc", "Print table of contents").option("--toc-metadata", "Print section metadata in table of contents").option("-s, --section <sections...>", "Print specific sections (e.g. \"Introduction\" or \"#2\")").option("-r, --recursive", "Print subsections recursively").action(async (file, options) => {
1599
+ if (!file && !options.content && !options.stdin) program.addHelpText("after", "\nError: Please provide a file path / markdown content / or the stdin flag").help({ error: true });
1600
+ const md = parse(await getContent({
20
1601
  ...options,
21
1602
  file
22
- });
23
- const tokens = Array.from(walkMarkdown(content));
24
- if (!tokens.length) return;
1603
+ }));
25
1604
  const contents = [];
26
- if (options.metadata && tokens[0].type === "metadata") contents.push(`---\n${tokens[0].metadata}\n---`);
27
- if (options.toc) contents.push(`[TOC]\n${getTOC(tokens)}`);
28
- if (options.section) {
29
- const section = getSection(tokens, options.section);
30
- if (section != null) contents.push(section);
31
- }
1605
+ if (options.metadata && md.metadata) contents.push(`---\n${md.metadata}\n---`);
1606
+ if (options.toc) contents.push(getTOC(md, options));
1607
+ if (options.section) contents.push(getSections(md, options));
32
1608
  if (contents.length) console.log(contents.join("\n\n"));
33
1609
  });
34
1610
  program.parse(process.argv);