markdown.mjs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. var ne = Object.defineProperty;
  2. var ie = (a, n, t) => n in a ? ne(a, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[n] = t;
  3. var B = (a, n, t) => (ie(a, typeof n != "symbol" ? n + "" : n, t), t);
  4. function X() {
  5. return {
  6. async: !1,
  7. baseUrl: null,
  8. breaks: !1,
  9. extensions: null,
  10. gfm: !0,
  11. headerIds: !0,
  12. headerPrefix: "",
  13. highlight: null,
  14. hooks: null,
  15. langPrefix: "language-",
  16. mangle: !0,
  17. pedantic: !1,
  18. renderer: null,
  19. sanitize: !1,
  20. sanitizer: null,
  21. silent: !1,
  22. smartypants: !1,
  23. tokenizer: null,
  24. walkTokens: null,
  25. xhtml: !1
  26. };
  27. }
  28. let L = X();
  29. function se(a) {
  30. L = a;
  31. }
  32. const G = /[&<>"']/, re = new RegExp(G.source, "g"), W = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, le = new RegExp(W.source, "g"), ae = {
  33. "&": "&amp;",
  34. "<": "&lt;",
  35. ">": "&gt;",
  36. '"': "&quot;",
  37. "'": "&#39;"
  38. }, U = (a) => ae[a];
  39. function z(a, n) {
  40. if (n) {
  41. if (G.test(a))
  42. return a.replace(re, U);
  43. } else if (W.test(a))
  44. return a.replace(le, U);
  45. return a;
  46. }
  47. const oe = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
  48. function J(a) {
  49. return a.replace(oe, (n, t) => (t = t.toLowerCase(), t === "colon" ? ":" : t.charAt(0) === "#" ? t.charAt(1) === "x" ? String.fromCharCode(parseInt(t.substring(2), 16)) : String.fromCharCode(+t.substring(1)) : ""));
  50. }
  51. const ce = /(^|[^\[])\^/g;
  52. function S(a, n) {
  53. a = typeof a == "string" ? a : a.source, n = n || "";
  54. const t = {
  55. replace: (e, i) => (i = i.source || i, i = i.replace(ce, "$1"), a = a.replace(e, i), t),
  56. getRegex: () => new RegExp(a, n)
  57. };
  58. return t;
  59. }
  60. const he = /[^\w:]/g, ue = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
  61. function Z(a, n, t) {
  62. if (a) {
  63. let e;
  64. try {
  65. e = decodeURIComponent(J(t)).replace(he, "").toLowerCase();
  66. } catch {
  67. return null;
  68. }
  69. if (e.indexOf("javascript:") === 0 || e.indexOf("vbscript:") === 0 || e.indexOf("data:") === 0)
  70. return null;
  71. }
  72. n && !ue.test(t) && (t = de(n, t));
  73. try {
  74. t = encodeURI(t).replace(/%25/g, "%");
  75. } catch {
  76. return null;
  77. }
  78. return t;
  79. }
  80. const C = {}, pe = /^[^:]+:\/*[^/]*$/, fe = /^([^:]+:)[\s\S]*$/, ge = /^([^:]+:\/*[^/]*)[\s\S]*$/;
  81. function de(a, n) {
  82. C[" " + a] || (pe.test(a) ? C[" " + a] = a + "/" : C[" " + a] = D(a, "/", !0)), a = C[" " + a];
  83. const t = a.indexOf(":") === -1;
  84. return n.substring(0, 2) === "//" ? t ? n : a.replace(fe, "$1") + n : n.charAt(0) === "/" ? t ? n : a.replace(ge, "$1") + n : a + n;
  85. }
  86. const P = { exec: function() {
  87. } };
  88. function H(a, n) {
  89. const t = a.replace(/\|/g, (s, l, o) => {
  90. let h = !1, w = l;
  91. for (; --w >= 0 && o[w] === "\\"; )
  92. h = !h;
  93. return h ? "|" : " |";
  94. }), e = t.split(/ \|/);
  95. let i = 0;
  96. if (e[0].trim() || e.shift(), e.length > 0 && !e[e.length - 1].trim() && e.pop(), e.length > n)
  97. e.splice(n);
  98. else
  99. for (; e.length < n; )
  100. e.push("");
  101. for (; i < e.length; i++)
  102. e[i] = e[i].trim().replace(/\\\|/g, "|");
  103. return e;
  104. }
  105. function D(a, n, t) {
  106. const e = a.length;
  107. if (e === 0)
  108. return "";
  109. let i = 0;
  110. for (; i < e; ) {
  111. const s = a.charAt(e - i - 1);
  112. if (s === n && !t)
  113. i++;
  114. else if (s !== n && t)
  115. i++;
  116. else
  117. break;
  118. }
  119. return a.slice(0, e - i);
  120. }
  121. function ke(a, n) {
  122. if (a.indexOf(n[1]) === -1)
  123. return -1;
  124. const t = a.length;
  125. let e = 0, i = 0;
  126. for (; i < t; i++)
  127. if (a[i] === "\\")
  128. i++;
  129. else if (a[i] === n[0])
  130. e++;
  131. else if (a[i] === n[1] && (e--, e < 0))
  132. return i;
  133. return -1;
  134. }
  135. function me(a) {
  136. a && a.sanitize && !a.silent && console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options");
  137. }
  138. function j(a, n) {
  139. if (n < 1)
  140. return "";
  141. let t = "";
  142. for (; n > 1; )
  143. n & 1 && (t += a), n >>= 1, a += a;
  144. return t + a;
  145. }
  146. function F(a, n, t, e) {
  147. const i = n.href, s = n.title ? z(n.title) : null, l = a[1].replace(/\\([\[\]])/g, "$1");
  148. if (a[0].charAt(0) !== "!") {
  149. e.state.inLink = !0;
  150. const o = {
  151. type: "link",
  152. raw: t,
  153. href: i,
  154. title: s,
  155. text: l,
  156. tokens: e.inlineTokens(l)
  157. };
  158. return e.state.inLink = !1, o;
  159. }
  160. return {
  161. type: "image",
  162. raw: t,
  163. href: i,
  164. title: s,
  165. text: z(l)
  166. };
  167. }
  168. function xe(a, n) {
  169. const t = a.match(/^(\s+)(?:```)/);
  170. if (t === null)
  171. return n;
  172. const e = t[1];
  173. return n.split(`
  174. `).map((i) => {
  175. const s = i.match(/^\s+/);
  176. if (s === null)
  177. return i;
  178. const [l] = s;
  179. return l.length >= e.length ? i.slice(e.length) : i;
  180. }).join(`
  181. `);
  182. }
  183. class N {
  184. constructor(n) {
  185. this.options = n || L;
  186. }
  187. space(n) {
  188. const t = this.rules.block.newline.exec(n);
  189. if (t && t[0].length > 0)
  190. return {
  191. type: "space",
  192. raw: t[0]
  193. };
  194. }
  195. code(n) {
  196. const t = this.rules.block.code.exec(n);
  197. if (t) {
  198. const e = t[0].replace(/^ {1,4}/gm, "");
  199. return {
  200. type: "code",
  201. raw: t[0],
  202. codeBlockStyle: "indented",
  203. text: this.options.pedantic ? e : D(e, `
  204. `)
  205. };
  206. }
  207. }
  208. fences(n) {
  209. const t = this.rules.block.fences.exec(n);
  210. if (t) {
  211. const e = t[0], i = xe(e, t[3] || "");
  212. return {
  213. type: "code",
  214. raw: e,
  215. lang: t[2] ? t[2].trim().replace(this.rules.inline._escapes, "$1") : t[2],
  216. text: i
  217. };
  218. }
  219. }
  220. heading(n) {
  221. const t = this.rules.block.heading.exec(n);
  222. if (t) {
  223. let e = t[2].trim();
  224. if (/#$/.test(e)) {
  225. const i = D(e, "#");
  226. (this.options.pedantic || !i || / $/.test(i)) && (e = i.trim());
  227. }
  228. return {
  229. type: "heading",
  230. raw: t[0],
  231. depth: t[1].length,
  232. text: e,
  233. tokens: this.lexer.inline(e)
  234. };
  235. }
  236. }
  237. hr(n) {
  238. const t = this.rules.block.hr.exec(n);
  239. if (t)
  240. return {
  241. type: "hr",
  242. raw: t[0]
  243. };
  244. }
  245. blockquote(n) {
  246. const t = this.rules.block.blockquote.exec(n);
  247. if (t) {
  248. const e = t[0].replace(/^ *>[ \t]?/gm, ""), i = this.lexer.state.top;
  249. this.lexer.state.top = !0;
  250. const s = this.lexer.blockTokens(e);
  251. return this.lexer.state.top = i, {
  252. type: "blockquote",
  253. raw: t[0],
  254. tokens: s,
  255. text: e
  256. };
  257. }
  258. }
  259. list(n) {
  260. let t = this.rules.block.list.exec(n);
  261. if (t) {
  262. let e, i, s, l, o, h, w, x, b, c, r, m, g = t[1].trim();
  263. const y = g.length > 1, p = {
  264. type: "list",
  265. raw: "",
  266. ordered: y,
  267. start: y ? +g.slice(0, -1) : "",
  268. loose: !1,
  269. items: []
  270. };
  271. g = y ? `\\d{1,9}\\${g.slice(-1)}` : `\\${g}`, this.options.pedantic && (g = y ? g : "[*+-]");
  272. const k = new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);
  273. for (; n && (m = !1, !(!(t = k.exec(n)) || this.rules.block.hr.test(n))); ) {
  274. if (e = t[0], n = n.substring(e.length), x = t[2].split(`
  275. `, 1)[0].replace(/^\t+/, (T) => " ".repeat(3 * T.length)), b = n.split(`
  276. `, 1)[0], this.options.pedantic ? (l = 2, r = x.trimLeft()) : (l = t[2].search(/[^ ]/), l = l > 4 ? 1 : l, r = x.slice(l), l += t[1].length), h = !1, !x && /^ *$/.test(b) && (e += b + `
  277. `, n = n.substring(b.length + 1), m = !0), !m) {
  278. const T = new RegExp(`^ {0,${Math.min(3, l - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), $ = new RegExp(`^ {0,${Math.min(3, l - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), R = new RegExp(`^ {0,${Math.min(3, l - 1)}}(?:\`\`\`|~~~)`), A = new RegExp(`^ {0,${Math.min(3, l - 1)}}#`);
  279. for (; n && (c = n.split(`
  280. `, 1)[0], b = c, this.options.pedantic && (b = b.replace(/^ {1,4}(?=( {4})*[^ ])/g, " ")), !(R.test(b) || A.test(b) || T.test(b) || $.test(n))); ) {
  281. if (b.search(/[^ ]/) >= l || !b.trim())
  282. r += `
  283. ` + b.slice(l);
  284. else {
  285. if (h || x.search(/[^ ]/) >= 4 || R.test(x) || A.test(x) || $.test(x))
  286. break;
  287. r += `
  288. ` + b;
  289. }
  290. !h && !b.trim() && (h = !0), e += c + `
  291. `, n = n.substring(c.length + 1), x = b.slice(l);
  292. }
  293. }
  294. p.loose || (w ? p.loose = !0 : /\n *\n *$/.test(e) && (w = !0)), this.options.gfm && (i = /^\[[ xX]\] /.exec(r), i && (s = i[0] !== "[ ] ", r = r.replace(/^\[[ xX]\] +/, ""))), p.items.push({
  295. type: "list_item",
  296. raw: e,
  297. task: !!i,
  298. checked: s,
  299. loose: !1,
  300. text: r
  301. }), p.raw += e;
  302. }
  303. p.items[p.items.length - 1].raw = e.trimRight(), p.items[p.items.length - 1].text = r.trimRight(), p.raw = p.raw.trimRight();
  304. const _ = p.items.length;
  305. for (o = 0; o < _; o++)
  306. if (this.lexer.state.top = !1, p.items[o].tokens = this.lexer.blockTokens(p.items[o].text, []), !p.loose) {
  307. const T = p.items[o].tokens.filter((R) => R.type === "space"), $ = T.length > 0 && T.some((R) => /\n.*\n/.test(R.raw));
  308. p.loose = $;
  309. }
  310. if (p.loose)
  311. for (o = 0; o < _; o++)
  312. p.items[o].loose = !0;
  313. return p;
  314. }
  315. }
  316. html(n) {
  317. const t = this.rules.block.html.exec(n);
  318. if (t) {
  319. const e = {
  320. type: "html",
  321. raw: t[0],
  322. pre: !this.options.sanitizer && (t[1] === "pre" || t[1] === "script" || t[1] === "style"),
  323. text: t[0]
  324. };
  325. if (this.options.sanitize) {
  326. const i = this.options.sanitizer ? this.options.sanitizer(t[0]) : z(t[0]);
  327. e.type = "paragraph", e.text = i, e.tokens = this.lexer.inline(i);
  328. }
  329. return e;
  330. }
  331. }
  332. def(n) {
  333. const t = this.rules.block.def.exec(n);
  334. if (t) {
  335. const e = t[1].toLowerCase().replace(/\s+/g, " "), i = t[2] ? t[2].replace(/^<(.*)>$/, "$1").replace(this.rules.inline._escapes, "$1") : "", s = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline._escapes, "$1") : t[3];
  336. return {
  337. type: "def",
  338. tag: e,
  339. raw: t[0],
  340. href: i,
  341. title: s
  342. };
  343. }
  344. }
  345. table(n) {
  346. const t = this.rules.block.table.exec(n);
  347. if (t) {
  348. const e = {
  349. type: "table",
  350. header: H(t[1]).map((i) => ({ text: i })),
  351. align: t[2].replace(/^ *|\| *$/g, "").split(/ *\| */),
  352. rows: t[3] && t[3].trim() ? t[3].replace(/\n[ \t]*$/, "").split(`
  353. `) : []
  354. };
  355. if (e.header.length === e.align.length) {
  356. e.raw = t[0];
  357. let i = e.align.length, s, l, o, h;
  358. for (s = 0; s < i; s++)
  359. /^ *-+: *$/.test(e.align[s]) ? e.align[s] = "right" : /^ *:-+: *$/.test(e.align[s]) ? e.align[s] = "center" : /^ *:-+ *$/.test(e.align[s]) ? e.align[s] = "left" : e.align[s] = null;
  360. for (i = e.rows.length, s = 0; s < i; s++)
  361. e.rows[s] = H(e.rows[s], e.header.length).map((w) => ({ text: w }));
  362. for (i = e.header.length, l = 0; l < i; l++)
  363. e.header[l].tokens = this.lexer.inline(e.header[l].text);
  364. for (i = e.rows.length, l = 0; l < i; l++)
  365. for (h = e.rows[l], o = 0; o < h.length; o++)
  366. h[o].tokens = this.lexer.inline(h[o].text);
  367. return e;
  368. }
  369. }
  370. }
  371. lheading(n) {
  372. const t = this.rules.block.lheading.exec(n);
  373. if (t)
  374. return {
  375. type: "heading",
  376. raw: t[0],
  377. depth: t[2].charAt(0) === "=" ? 1 : 2,
  378. text: t[1],
  379. tokens: this.lexer.inline(t[1])
  380. };
  381. }
  382. paragraph(n) {
  383. const t = this.rules.block.paragraph.exec(n);
  384. if (t) {
  385. const e = t[1].charAt(t[1].length - 1) === `
  386. ` ? t[1].slice(0, -1) : t[1];
  387. return {
  388. type: "paragraph",
  389. raw: t[0],
  390. text: e,
  391. tokens: this.lexer.inline(e)
  392. };
  393. }
  394. }
  395. text(n) {
  396. const t = this.rules.block.text.exec(n);
  397. if (t)
  398. return {
  399. type: "text",
  400. raw: t[0],
  401. text: t[0],
  402. tokens: this.lexer.inline(t[0])
  403. };
  404. }
  405. escape(n) {
  406. const t = this.rules.inline.escape.exec(n);
  407. if (t)
  408. return {
  409. type: "escape",
  410. raw: t[0],
  411. text: z(t[1])
  412. };
  413. }
  414. tag(n) {
  415. const t = this.rules.inline.tag.exec(n);
  416. if (t)
  417. return !this.lexer.state.inLink && /^<a /i.test(t[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && /^<\/a>/i.test(t[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(t[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0]) && (this.lexer.state.inRawBlock = !1), {
  418. type: this.options.sanitize ? "text" : "html",
  419. raw: t[0],
  420. inLink: this.lexer.state.inLink,
  421. inRawBlock: this.lexer.state.inRawBlock,
  422. text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(t[0]) : z(t[0]) : t[0]
  423. };
  424. }
  425. link(n) {
  426. const t = this.rules.inline.link.exec(n);
  427. if (t) {
  428. const e = t[2].trim();
  429. if (!this.options.pedantic && /^</.test(e)) {
  430. if (!/>$/.test(e))
  431. return;
  432. const l = D(e.slice(0, -1), "\\");
  433. if ((e.length - l.length) % 2 === 0)
  434. return;
  435. } else {
  436. const l = ke(t[2], "()");
  437. if (l > -1) {
  438. const h = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + l;
  439. t[2] = t[2].substring(0, l), t[0] = t[0].substring(0, h).trim(), t[3] = "";
  440. }
  441. }
  442. let i = t[2], s = "";
  443. if (this.options.pedantic) {
  444. const l = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i);
  445. l && (i = l[1], s = l[3]);
  446. } else
  447. s = t[3] ? t[3].slice(1, -1) : "";
  448. return i = i.trim(), /^</.test(i) && (this.options.pedantic && !/>$/.test(e) ? i = i.slice(1) : i = i.slice(1, -1)), F(t, {
  449. href: i && i.replace(this.rules.inline._escapes, "$1"),
  450. title: s && s.replace(this.rules.inline._escapes, "$1")
  451. }, t[0], this.lexer);
  452. }
  453. }
  454. reflink(n, t) {
  455. let e;
  456. if ((e = this.rules.inline.reflink.exec(n)) || (e = this.rules.inline.nolink.exec(n))) {
  457. let i = (e[2] || e[1]).replace(/\s+/g, " ");
  458. if (i = t[i.toLowerCase()], !i) {
  459. const s = e[0].charAt(0);
  460. return {
  461. type: "text",
  462. raw: s,
  463. text: s
  464. };
  465. }
  466. return F(e, i, e[0], this.lexer);
  467. }
  468. }
  469. emStrong(n, t, e = "") {
  470. let i = this.rules.inline.emStrong.lDelim.exec(n);
  471. if (!i || i[3] && e.match(/[\p{L}\p{N}]/u))
  472. return;
  473. const s = i[1] || i[2] || "";
  474. if (!s || s && (e === "" || this.rules.inline.punctuation.exec(e))) {
  475. const l = i[0].length - 1;
  476. let o, h, w = l, x = 0;
  477. const b = i[0][0] === "*" ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
  478. for (b.lastIndex = 0, t = t.slice(-1 * n.length + l); (i = b.exec(t)) != null; ) {
  479. if (o = i[1] || i[2] || i[3] || i[4] || i[5] || i[6], !o)
  480. continue;
  481. if (h = o.length, i[3] || i[4]) {
  482. w += h;
  483. continue;
  484. } else if ((i[5] || i[6]) && l % 3 && !((l + h) % 3)) {
  485. x += h;
  486. continue;
  487. }
  488. if (w -= h, w > 0)
  489. continue;
  490. h = Math.min(h, h + w + x);
  491. const c = n.slice(0, l + i.index + (i[0].length - o.length) + h);
  492. if (Math.min(l, h) % 2) {
  493. const m = c.slice(1, -1);
  494. return {
  495. type: "em",
  496. raw: c,
  497. text: m,
  498. tokens: this.lexer.inlineTokens(m)
  499. };
  500. }
  501. const r = c.slice(2, -2);
  502. return {
  503. type: "strong",
  504. raw: c,
  505. text: r,
  506. tokens: this.lexer.inlineTokens(r)
  507. };
  508. }
  509. }
  510. }
  511. codespan(n) {
  512. const t = this.rules.inline.code.exec(n);
  513. if (t) {
  514. let e = t[2].replace(/\n/g, " ");
  515. const i = /[^ ]/.test(e), s = /^ /.test(e) && / $/.test(e);
  516. return i && s && (e = e.substring(1, e.length - 1)), e = z(e, !0), {
  517. type: "codespan",
  518. raw: t[0],
  519. text: e
  520. };
  521. }
  522. }
  523. br(n) {
  524. const t = this.rules.inline.br.exec(n);
  525. if (t)
  526. return {
  527. type: "br",
  528. raw: t[0]
  529. };
  530. }
  531. del(n) {
  532. const t = this.rules.inline.del.exec(n);
  533. if (t)
  534. return {
  535. type: "del",
  536. raw: t[0],
  537. text: t[2],
  538. tokens: this.lexer.inlineTokens(t[2])
  539. };
  540. }
  541. autolink(n, t) {
  542. const e = this.rules.inline.autolink.exec(n);
  543. if (e) {
  544. let i, s;
  545. return e[2] === "@" ? (i = z(this.options.mangle ? t(e[1]) : e[1]), s = "mailto:" + i) : (i = z(e[1]), s = i), {
  546. type: "link",
  547. raw: e[0],
  548. text: i,
  549. href: s,
  550. tokens: [
  551. {
  552. type: "text",
  553. raw: i,
  554. text: i
  555. }
  556. ]
  557. };
  558. }
  559. }
  560. url(n, t) {
  561. let e;
  562. if (e = this.rules.inline.url.exec(n)) {
  563. let i, s;
  564. if (e[2] === "@")
  565. i = z(this.options.mangle ? t(e[0]) : e[0]), s = "mailto:" + i;
  566. else {
  567. let l;
  568. do
  569. l = e[0], e[0] = this.rules.inline._backpedal.exec(e[0])[0];
  570. while (l !== e[0]);
  571. i = z(e[0]), e[1] === "www." ? s = "http://" + e[0] : s = e[0];
  572. }
  573. return {
  574. type: "link",
  575. raw: e[0],
  576. text: i,
  577. href: s,
  578. tokens: [
  579. {
  580. type: "text",
  581. raw: i,
  582. text: i
  583. }
  584. ]
  585. };
  586. }
  587. }
  588. inlineText(n, t) {
  589. const e = this.rules.inline.text.exec(n);
  590. if (e) {
  591. let i;
  592. return this.lexer.state.inRawBlock ? i = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(e[0]) : z(e[0]) : e[0] : i = z(this.options.smartypants ? t(e[0]) : e[0]), {
  593. type: "text",
  594. raw: e[0],
  595. text: i
  596. };
  597. }
  598. }
  599. }
  600. const d = {
  601. newline: /^(?: *(?:\n|$))+/,
  602. code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
  603. fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
  604. hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
  605. heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
  606. blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
  607. list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
  608. html: "^ {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|$))",
  609. def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
  610. table: P,
  611. lheading: /^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
  612. // regex template, placeholders will be replaced according to different paragraph
  613. // interruption rules of commonmark and the original markdown spec:
  614. _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
  615. text: /^[^\n]+/
  616. };
  617. d._label = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
  618. d._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
  619. d.def = S(d.def).replace("label", d._label).replace("title", d._title).getRegex();
  620. d.bullet = /(?:[*+-]|\d{1,9}[.)])/;
  621. d.listItemStart = S(/^( *)(bull) */).replace("bull", d.bullet).getRegex();
  622. d.list = S(d.list).replace(/bull/g, d.bullet).replace("hr", "\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def", "\\n+(?=" + d.def.source + ")").getRegex();
  623. d._tag = "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|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
  624. d._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
  625. d.html = S(d.html, "i").replace("comment", d._comment).replace("tag", d._tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
  626. d.paragraph = S(d._paragraph).replace("hr", d.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", d._tag).getRegex();
  627. d.blockquote = S(d.blockquote).replace("paragraph", d.paragraph).getRegex();
  628. d.normal = { ...d };
  629. d.gfm = {
  630. ...d.normal,
  631. table: "^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
  632. // Cells
  633. };
  634. d.gfm.table = S(d.gfm.table).replace("hr", d.hr).replace("heading", " {0,3}#{1,6} ").replace("blockquote", " {0,3}>").replace("code", " {4}[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", d._tag).getRegex();
  635. d.gfm.paragraph = S(d._paragraph).replace("hr", d.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("table", d.gfm.table).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", d._tag).getRegex();
  636. d.pedantic = {
  637. ...d.normal,
  638. html: S(
  639. `^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
  640. ).replace("comment", d._comment).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(),
  641. def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
  642. heading: /^(#{1,6})(.*)(?:\n+|$)/,
  643. fences: P,
  644. // fences not supported
  645. lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
  646. paragraph: S(d.normal._paragraph).replace("hr", d.hr).replace("heading", ` *#{1,6} *[^
  647. ]`).replace("lheading", d.lheading).replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").getRegex()
  648. };
  649. const u = {
  650. escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
  651. autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
  652. url: P,
  653. tag: "^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",
  654. // CDATA section
  655. link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
  656. reflink: /^!?\[(label)\]\[(ref)\]/,
  657. nolink: /^!?\[(ref)\](?:\[\])?/,
  658. reflinkSearch: "reflink|nolink(?!\\()",
  659. emStrong: {
  660. lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
  661. // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
  662. // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
  663. rDelimAst: /^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,
  664. rDelimUnd: /^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/
  665. // ^- Not allowed for _
  666. },
  667. code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
  668. br: /^( {2,}|\\)\n(?!\s*$)/,
  669. del: P,
  670. text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
  671. punctuation: /^([\spunctuation])/
  672. };
  673. u._punctuation = "!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~";
  674. u.punctuation = S(u.punctuation).replace(/punctuation/g, u._punctuation).getRegex();
  675. u.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
  676. u.escapedEmSt = /(?:^|[^\\])(?:\\\\)*\\[*_]/g;
  677. u._comment = S(d._comment).replace("(?:-->|$)", "-->").getRegex();
  678. u.emStrong.lDelim = S(u.emStrong.lDelim).replace(/punct/g, u._punctuation).getRegex();
  679. u.emStrong.rDelimAst = S(u.emStrong.rDelimAst, "g").replace(/punct/g, u._punctuation).getRegex();
  680. u.emStrong.rDelimUnd = S(u.emStrong.rDelimUnd, "g").replace(/punct/g, u._punctuation).getRegex();
  681. u._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
  682. u._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
  683. u._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])?)+(?![-_])/;
  684. u.autolink = S(u.autolink).replace("scheme", u._scheme).replace("email", u._email).getRegex();
  685. u._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
  686. u.tag = S(u.tag).replace("comment", u._comment).replace("attribute", u._attribute).getRegex();
  687. u._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
  688. u._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
  689. u._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
  690. u.link = S(u.link).replace("label", u._label).replace("href", u._href).replace("title", u._title).getRegex();
  691. u.reflink = S(u.reflink).replace("label", u._label).replace("ref", d._label).getRegex();
  692. u.nolink = S(u.nolink).replace("ref", d._label).getRegex();
  693. u.reflinkSearch = S(u.reflinkSearch, "g").replace("reflink", u.reflink).replace("nolink", u.nolink).getRegex();
  694. u.normal = { ...u };
  695. u.pedantic = {
  696. ...u.normal,
  697. strong: {
  698. start: /^__|\*\*/,
  699. middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
  700. endAst: /\*\*(?!\*)/g,
  701. endUnd: /__(?!_)/g
  702. },
  703. em: {
  704. start: /^_|\*/,
  705. middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
  706. endAst: /\*(?!\*)/g,
  707. endUnd: /_(?!_)/g
  708. },
  709. link: S(/^!?\[(label)\]\((.*?)\)/).replace("label", u._label).getRegex(),
  710. reflink: S(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", u._label).getRegex()
  711. };
  712. u.gfm = {
  713. ...u.normal,
  714. escape: S(u.escape).replace("])", "~|])").getRegex(),
  715. _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
  716. url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
  717. _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
  718. del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
  719. text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
  720. };
  721. u.gfm.url = S(u.gfm.url, "i").replace("email", u.gfm._extended_email).getRegex();
  722. u.breaks = {
  723. ...u.gfm,
  724. br: S(u.br).replace("{2,}", "*").getRegex(),
  725. text: S(u.gfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
  726. };
  727. function be(a) {
  728. return a.replace(/---/g, "—").replace(/--/g, "–").replace(/(^|[-\u2014/(\[{"\s])'/g, "$1‘").replace(/'/g, "’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1“").replace(/"/g, "”").replace(/\.{3}/g, "…");
  729. }
  730. function Q(a) {
  731. let n = "", t, e;
  732. const i = a.length;
  733. for (t = 0; t < i; t++)
  734. e = a.charCodeAt(t), Math.random() > 0.5 && (e = "x" + e.toString(16)), n += "&#" + e + ";";
  735. return n;
  736. }
  737. class E {
  738. constructor(n) {
  739. this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = n || L, this.options.tokenizer = this.options.tokenizer || new N(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
  740. inLink: !1,
  741. inRawBlock: !1,
  742. top: !0
  743. };
  744. const t = {
  745. block: d.normal,
  746. inline: u.normal
  747. };
  748. this.options.pedantic ? (t.block = d.pedantic, t.inline = u.pedantic) : this.options.gfm && (t.block = d.gfm, this.options.breaks ? t.inline = u.breaks : t.inline = u.gfm), this.tokenizer.rules = t;
  749. }
  750. /**
  751. * Expose Rules
  752. */
  753. static get rules() {
  754. return {
  755. block: d,
  756. inline: u
  757. };
  758. }
  759. /**
  760. * Static Lex Method
  761. */
  762. static lex(n, t) {
  763. return new E(t).lex(n);
  764. }
  765. /**
  766. * Static Lex Inline Method
  767. */
  768. static lexInline(n, t) {
  769. return new E(t).inlineTokens(n);
  770. }
  771. /**
  772. * Preprocessing
  773. */
  774. lex(n) {
  775. n = n.replace(/\r\n|\r/g, `
  776. `), this.blockTokens(n, this.tokens);
  777. let t;
  778. for (; t = this.inlineQueue.shift(); )
  779. this.inlineTokens(t.src, t.tokens);
  780. return this.tokens;
  781. }
  782. /**
  783. * Lexing
  784. */
  785. blockTokens(n, t = []) {
  786. this.options.pedantic ? n = n.replace(/\t/g, " ").replace(/^ +$/gm, "") : n = n.replace(/^( *)(\t+)/gm, (o, h, w) => h + " ".repeat(w.length));
  787. let e, i, s, l;
  788. for (; n; )
  789. if (!(this.options.extensions && this.options.extensions.block && this.options.extensions.block.some((o) => (e = o.call({ lexer: this }, n, t)) ? (n = n.substring(e.raw.length), t.push(e), !0) : !1))) {
  790. if (e = this.tokenizer.space(n)) {
  791. n = n.substring(e.raw.length), e.raw.length === 1 && t.length > 0 ? t[t.length - 1].raw += `
  792. ` : t.push(e);
  793. continue;
  794. }
  795. if (e = this.tokenizer.code(n)) {
  796. n = n.substring(e.raw.length), i = t[t.length - 1], i && (i.type === "paragraph" || i.type === "text") ? (i.raw += `
  797. ` + e.raw, i.text += `
  798. ` + e.text, this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : t.push(e);
  799. continue;
  800. }
  801. if (e = this.tokenizer.fences(n)) {
  802. n = n.substring(e.raw.length), t.push(e);
  803. continue;
  804. }
  805. if (e = this.tokenizer.heading(n)) {
  806. n = n.substring(e.raw.length), t.push(e);
  807. continue;
  808. }
  809. if (e = this.tokenizer.hr(n)) {
  810. n = n.substring(e.raw.length), t.push(e);
  811. continue;
  812. }
  813. if (e = this.tokenizer.blockquote(n)) {
  814. n = n.substring(e.raw.length), t.push(e);
  815. continue;
  816. }
  817. if (e = this.tokenizer.list(n)) {
  818. n = n.substring(e.raw.length), t.push(e);
  819. continue;
  820. }
  821. if (e = this.tokenizer.html(n)) {
  822. n = n.substring(e.raw.length), t.push(e);
  823. continue;
  824. }
  825. if (e = this.tokenizer.def(n)) {
  826. n = n.substring(e.raw.length), i = t[t.length - 1], i && (i.type === "paragraph" || i.type === "text") ? (i.raw += `
  827. ` + e.raw, i.text += `
  828. ` + e.raw, this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : this.tokens.links[e.tag] || (this.tokens.links[e.tag] = {
  829. href: e.href,
  830. title: e.title
  831. });
  832. continue;
  833. }
  834. if (e = this.tokenizer.table(n)) {
  835. n = n.substring(e.raw.length), t.push(e);
  836. continue;
  837. }
  838. if (e = this.tokenizer.lheading(n)) {
  839. n = n.substring(e.raw.length), t.push(e);
  840. continue;
  841. }
  842. if (s = n, this.options.extensions && this.options.extensions.startBlock) {
  843. let o = 1 / 0;
  844. const h = n.slice(1);
  845. let w;
  846. this.options.extensions.startBlock.forEach(function(x) {
  847. w = x.call({ lexer: this }, h), typeof w == "number" && w >= 0 && (o = Math.min(o, w));
  848. }), o < 1 / 0 && o >= 0 && (s = n.substring(0, o + 1));
  849. }
  850. if (this.state.top && (e = this.tokenizer.paragraph(s))) {
  851. i = t[t.length - 1], l && i.type === "paragraph" ? (i.raw += `
  852. ` + e.raw, i.text += `
  853. ` + e.text, this.inlineQueue.pop(), this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : t.push(e), l = s.length !== n.length, n = n.substring(e.raw.length);
  854. continue;
  855. }
  856. if (e = this.tokenizer.text(n)) {
  857. n = n.substring(e.raw.length), i = t[t.length - 1], i && i.type === "text" ? (i.raw += `
  858. ` + e.raw, i.text += `
  859. ` + e.text, this.inlineQueue.pop(), this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : t.push(e);
  860. continue;
  861. }
  862. if (n) {
  863. const o = "Infinite loop on byte: " + n.charCodeAt(0);
  864. if (this.options.silent) {
  865. console.error(o);
  866. break;
  867. } else
  868. throw new Error(o);
  869. }
  870. }
  871. return this.state.top = !0, t;
  872. }
  873. inline(n, t = []) {
  874. return this.inlineQueue.push({ src: n, tokens: t }), t;
  875. }
  876. /**
  877. * Lexing/Compiling
  878. */
  879. inlineTokens(n, t = []) {
  880. let e, i, s, l = n, o, h, w;
  881. if (this.tokens.links) {
  882. const x = Object.keys(this.tokens.links);
  883. if (x.length > 0)
  884. for (; (o = this.tokenizer.rules.inline.reflinkSearch.exec(l)) != null; )
  885. x.includes(o[0].slice(o[0].lastIndexOf("[") + 1, -1)) && (l = l.slice(0, o.index) + "[" + j("a", o[0].length - 2) + "]" + l.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
  886. }
  887. for (; (o = this.tokenizer.rules.inline.blockSkip.exec(l)) != null; )
  888. l = l.slice(0, o.index) + "[" + j("a", o[0].length - 2) + "]" + l.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
  889. for (; (o = this.tokenizer.rules.inline.escapedEmSt.exec(l)) != null; )
  890. l = l.slice(0, o.index + o[0].length - 2) + "++" + l.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex), this.tokenizer.rules.inline.escapedEmSt.lastIndex--;
  891. for (; n; )
  892. if (h || (w = ""), h = !1, !(this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some((x) => (e = x.call({ lexer: this }, n, t)) ? (n = n.substring(e.raw.length), t.push(e), !0) : !1))) {
  893. if (e = this.tokenizer.escape(n)) {
  894. n = n.substring(e.raw.length), t.push(e);
  895. continue;
  896. }
  897. if (e = this.tokenizer.tag(n)) {
  898. n = n.substring(e.raw.length), i = t[t.length - 1], i && e.type === "text" && i.type === "text" ? (i.raw += e.raw, i.text += e.text) : t.push(e);
  899. continue;
  900. }
  901. if (e = this.tokenizer.link(n)) {
  902. n = n.substring(e.raw.length), t.push(e);
  903. continue;
  904. }
  905. if (e = this.tokenizer.reflink(n, this.tokens.links)) {
  906. n = n.substring(e.raw.length), i = t[t.length - 1], i && e.type === "text" && i.type === "text" ? (i.raw += e.raw, i.text += e.text) : t.push(e);
  907. continue;
  908. }
  909. if (e = this.tokenizer.emStrong(n, l, w)) {
  910. n = n.substring(e.raw.length), t.push(e);
  911. continue;
  912. }
  913. if (e = this.tokenizer.codespan(n)) {
  914. n = n.substring(e.raw.length), t.push(e);
  915. continue;
  916. }
  917. if (e = this.tokenizer.br(n)) {
  918. n = n.substring(e.raw.length), t.push(e);
  919. continue;
  920. }
  921. if (e = this.tokenizer.del(n)) {
  922. n = n.substring(e.raw.length), t.push(e);
  923. continue;
  924. }
  925. if (e = this.tokenizer.autolink(n, Q)) {
  926. n = n.substring(e.raw.length), t.push(e);
  927. continue;
  928. }
  929. if (!this.state.inLink && (e = this.tokenizer.url(n, Q))) {
  930. n = n.substring(e.raw.length), t.push(e);
  931. continue;
  932. }
  933. if (s = n, this.options.extensions && this.options.extensions.startInline) {
  934. let x = 1 / 0;
  935. const b = n.slice(1);
  936. let c;
  937. this.options.extensions.startInline.forEach(function(r) {
  938. c = r.call({ lexer: this }, b), typeof c == "number" && c >= 0 && (x = Math.min(x, c));
  939. }), x < 1 / 0 && x >= 0 && (s = n.substring(0, x + 1));
  940. }
  941. if (e = this.tokenizer.inlineText(s, be)) {
  942. n = n.substring(e.raw.length), e.raw.slice(-1) !== "_" && (w = e.raw.slice(-1)), h = !0, i = t[t.length - 1], i && i.type === "text" ? (i.raw += e.raw, i.text += e.text) : t.push(e);
  943. continue;
  944. }
  945. if (n) {
  946. const x = "Infinite loop on byte: " + n.charCodeAt(0);
  947. if (this.options.silent) {
  948. console.error(x);
  949. break;
  950. } else
  951. throw new Error(x);
  952. }
  953. }
  954. return t;
  955. }
  956. }
  957. class q {
  958. constructor(n) {
  959. this.options = n || L;
  960. }
  961. code(n, t, e) {
  962. const i = (t || "").match(/\S*/)[0];
  963. if (this.options.highlight) {
  964. const s = this.options.highlight(n, i);
  965. s != null && s !== n && (e = !0, n = s);
  966. }
  967. return n = n.replace(/\n$/, "") + `
  968. `, i ? '<pre><code class="' + this.options.langPrefix + z(i) + '">' + (e ? n : z(n, !0)) + `</code></pre>
  969. ` : "<pre><code>" + (e ? n : z(n, !0)) + `</code></pre>
  970. `;
  971. }
  972. /**
  973. * @param {string} quote
  974. */
  975. blockquote(n) {
  976. return `<blockquote>
  977. ${n}</blockquote>
  978. `;
  979. }
  980. html(n) {
  981. return n;
  982. }
  983. /**
  984. * @param {string} text
  985. * @param {string} level
  986. * @param {string} raw
  987. * @param {any} slugger
  988. */
  989. heading(n, t, e, i) {
  990. if (this.options.headerIds) {
  991. const s = this.options.headerPrefix + i.slug(e);
  992. return `<h${t} id="${s}">${n}</h${t}>
  993. `;
  994. }
  995. return `<h${t}>${n}</h${t}>
  996. `;
  997. }
  998. hr() {
  999. return this.options.xhtml ? `<hr/>
  1000. ` : `<hr>
  1001. `;
  1002. }
  1003. list(n, t, e) {
  1004. const i = t ? "ol" : "ul", s = t && e !== 1 ? ' start="' + e + '"' : "";
  1005. return "<" + i + s + `>
  1006. ` + n + "</" + i + `>
  1007. `;
  1008. }
  1009. /**
  1010. * @param {string} text
  1011. */
  1012. listitem(n) {
  1013. return `<li>${n}</li>
  1014. `;
  1015. }
  1016. checkbox(n) {
  1017. return "<input " + (n ? 'checked="" ' : "") + 'disabled="" type="checkbox"' + (this.options.xhtml ? " /" : "") + "> ";
  1018. }
  1019. /**
  1020. * @param {string} text
  1021. */
  1022. paragraph(n) {
  1023. return `<p>${n}</p>
  1024. `;
  1025. }
  1026. /**
  1027. * @param {string} header
  1028. * @param {string} body
  1029. */
  1030. table(n, t) {
  1031. return t && (t = `<tbody>${t}</tbody>`), `<table>
  1032. <thead>
  1033. ` + n + `</thead>
  1034. ` + t + `</table>
  1035. `;
  1036. }
  1037. /**
  1038. * @param {string} content
  1039. */
  1040. tablerow(n) {
  1041. return `<tr>
  1042. ${n}</tr>
  1043. `;
  1044. }
  1045. tablecell(n, t) {
  1046. const e = t.header ? "th" : "td";
  1047. return (t.align ? `<${e} align="${t.align}">` : `<${e}>`) + n + `</${e}>
  1048. `;
  1049. }
  1050. /**
  1051. * span level renderer
  1052. * @param {string} text
  1053. */
  1054. strong(n) {
  1055. return `<strong>${n}</strong>`;
  1056. }
  1057. /**
  1058. * @param {string} text
  1059. */
  1060. em(n) {
  1061. return `<em>${n}</em>`;
  1062. }
  1063. /**
  1064. * @param {string} text
  1065. */
  1066. codespan(n) {
  1067. return `<code>${n}</code>`;
  1068. }
  1069. br() {
  1070. return this.options.xhtml ? "<br/>" : "<br>";
  1071. }
  1072. /**
  1073. * @param {string} text
  1074. */
  1075. del(n) {
  1076. return `<del>${n}</del>`;
  1077. }
  1078. /**
  1079. * @param {string} href
  1080. * @param {string} title
  1081. * @param {string} text
  1082. */
  1083. link(n, t, e) {
  1084. if (n = Z(this.options.sanitize, this.options.baseUrl, n), n === null)
  1085. return e;
  1086. let i = '<a href="' + n + '"';
  1087. return t && (i += ' title="' + t + '"'), i += ">" + e + "</a>", i;
  1088. }
  1089. /**
  1090. * @param {string} href
  1091. * @param {string} title
  1092. * @param {string} text
  1093. */
  1094. image(n, t, e) {
  1095. if (n = Z(this.options.sanitize, this.options.baseUrl, n), n === null)
  1096. return e;
  1097. let i = `<img src="${n}" alt="${e}"`;
  1098. return t && (i += ` title="${t}"`), i += this.options.xhtml ? "/>" : ">", i;
  1099. }
  1100. text(n) {
  1101. return n;
  1102. }
  1103. }
  1104. class K {
  1105. // no need for block level renderers
  1106. strong(n) {
  1107. return n;
  1108. }
  1109. em(n) {
  1110. return n;
  1111. }
  1112. codespan(n) {
  1113. return n;
  1114. }
  1115. del(n) {
  1116. return n;
  1117. }
  1118. html(n) {
  1119. return n;
  1120. }
  1121. text(n) {
  1122. return n;
  1123. }
  1124. link(n, t, e) {
  1125. return "" + e;
  1126. }
  1127. image(n, t, e) {
  1128. return "" + e;
  1129. }
  1130. br() {
  1131. return "";
  1132. }
  1133. }
  1134. class Y {
  1135. constructor() {
  1136. this.seen = {};
  1137. }
  1138. /**
  1139. * @param {string} value
  1140. */
  1141. serialize(n) {
  1142. return n.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig, "").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, "").replace(/\s/g, "-");
  1143. }
  1144. /**
  1145. * Finds the next safe (unique) slug to use
  1146. * @param {string} originalSlug
  1147. * @param {boolean} isDryRun
  1148. */
  1149. getNextSafeSlug(n, t) {
  1150. let e = n, i = 0;
  1151. if (this.seen.hasOwnProperty(e)) {
  1152. i = this.seen[n];
  1153. do
  1154. i++, e = n + "-" + i;
  1155. while (this.seen.hasOwnProperty(e));
  1156. }
  1157. return t || (this.seen[n] = i, this.seen[e] = 0), e;
  1158. }
  1159. /**
  1160. * Convert string to unique id
  1161. * @param {object} [options]
  1162. * @param {boolean} [options.dryrun] Generates the next unique slug without
  1163. * updating the internal accumulator.
  1164. */
  1165. slug(n, t = {}) {
  1166. const e = this.serialize(n);
  1167. return this.getNextSafeSlug(e, t.dryrun);
  1168. }
  1169. }
  1170. class I {
  1171. constructor(n) {
  1172. this.options = n || L, this.options.renderer = this.options.renderer || new q(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.textRenderer = new K(), this.slugger = new Y();
  1173. }
  1174. /**
  1175. * Static Parse Method
  1176. */
  1177. static parse(n, t) {
  1178. return new I(t).parse(n);
  1179. }
  1180. /**
  1181. * Static Parse Inline Method
  1182. */
  1183. static parseInline(n, t) {
  1184. return new I(t).parseInline(n);
  1185. }
  1186. /**
  1187. * Parse Loop
  1188. */
  1189. parse(n, t = !0) {
  1190. let e = "", i, s, l, o, h, w, x, b, c, r, m, g, y, p, k, _, T, $, R;
  1191. const A = n.length;
  1192. for (i = 0; i < A; i++) {
  1193. if (r = n[i], this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[r.type] && (R = this.options.extensions.renderers[r.type].call({ parser: this }, r), R !== !1 || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(r.type))) {
  1194. e += R || "";
  1195. continue;
  1196. }
  1197. switch (r.type) {
  1198. case "space":
  1199. continue;
  1200. case "hr": {
  1201. e += this.renderer.hr();
  1202. continue;
  1203. }
  1204. case "heading": {
  1205. e += this.renderer.heading(
  1206. this.parseInline(r.tokens),
  1207. r.depth,
  1208. J(this.parseInline(r.tokens, this.textRenderer)),
  1209. this.slugger
  1210. );
  1211. continue;
  1212. }
  1213. case "code": {
  1214. e += this.renderer.code(
  1215. r.text,
  1216. r.lang,
  1217. r.escaped
  1218. );
  1219. continue;
  1220. }
  1221. case "table": {
  1222. for (b = "", x = "", o = r.header.length, s = 0; s < o; s++)
  1223. x += this.renderer.tablecell(
  1224. this.parseInline(r.header[s].tokens),
  1225. { header: !0, align: r.align[s] }
  1226. );
  1227. for (b += this.renderer.tablerow(x), c = "", o = r.rows.length, s = 0; s < o; s++) {
  1228. for (w = r.rows[s], x = "", h = w.length, l = 0; l < h; l++)
  1229. x += this.renderer.tablecell(
  1230. this.parseInline(w[l].tokens),
  1231. { header: !1, align: r.align[l] }
  1232. );
  1233. c += this.renderer.tablerow(x);
  1234. }
  1235. e += this.renderer.table(b, c);
  1236. continue;
  1237. }
  1238. case "blockquote": {
  1239. c = this.parse(r.tokens), e += this.renderer.blockquote(c);
  1240. continue;
  1241. }
  1242. case "list": {
  1243. for (m = r.ordered, g = r.start, y = r.loose, o = r.items.length, c = "", s = 0; s < o; s++)
  1244. k = r.items[s], _ = k.checked, T = k.task, p = "", k.task && ($ = this.renderer.checkbox(_), y ? k.tokens.length > 0 && k.tokens[0].type === "paragraph" ? (k.tokens[0].text = $ + " " + k.tokens[0].text, k.tokens[0].tokens && k.tokens[0].tokens.length > 0 && k.tokens[0].tokens[0].type === "text" && (k.tokens[0].tokens[0].text = $ + " " + k.tokens[0].tokens[0].text)) : k.tokens.unshift({
  1245. type: "text",
  1246. text: $
  1247. }) : p += $), p += this.parse(k.tokens, y), c += this.renderer.listitem(p, T, _);
  1248. e += this.renderer.list(c, m, g);
  1249. continue;
  1250. }
  1251. case "html": {
  1252. e += this.renderer.html(r.text);
  1253. continue;
  1254. }
  1255. case "paragraph": {
  1256. e += this.renderer.paragraph(this.parseInline(r.tokens));
  1257. continue;
  1258. }
  1259. case "text": {
  1260. for (c = r.tokens ? this.parseInline(r.tokens) : r.text; i + 1 < A && n[i + 1].type === "text"; )
  1261. r = n[++i], c += `
  1262. ` + (r.tokens ? this.parseInline(r.tokens) : r.text);
  1263. e += t ? this.renderer.paragraph(c) : c;
  1264. continue;
  1265. }
  1266. default: {
  1267. const v = 'Token with "' + r.type + '" type was not found.';
  1268. if (this.options.silent) {
  1269. console.error(v);
  1270. return;
  1271. } else
  1272. throw new Error(v);
  1273. }
  1274. }
  1275. }
  1276. return e;
  1277. }
  1278. /**
  1279. * Parse Inline Tokens
  1280. */
  1281. parseInline(n, t) {
  1282. t = t || this.renderer;
  1283. let e = "", i, s, l;
  1284. const o = n.length;
  1285. for (i = 0; i < o; i++) {
  1286. if (s = n[i], this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[s.type] && (l = this.options.extensions.renderers[s.type].call({ parser: this }, s), l !== !1 || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(s.type))) {
  1287. e += l || "";
  1288. continue;
  1289. }
  1290. switch (s.type) {
  1291. case "escape": {
  1292. e += t.text(s.text);
  1293. break;
  1294. }
  1295. case "html": {
  1296. e += t.html(s.text);
  1297. break;
  1298. }
  1299. case "link": {
  1300. e += t.link(s.href, s.title, this.parseInline(s.tokens, t));
  1301. break;
  1302. }
  1303. case "image": {
  1304. e += t.image(s.href, s.title, s.text);
  1305. break;
  1306. }
  1307. case "strong": {
  1308. e += t.strong(this.parseInline(s.tokens, t));
  1309. break;
  1310. }
  1311. case "em": {
  1312. e += t.em(this.parseInline(s.tokens, t));
  1313. break;
  1314. }
  1315. case "codespan": {
  1316. e += t.codespan(s.text);
  1317. break;
  1318. }
  1319. case "br": {
  1320. e += t.br();
  1321. break;
  1322. }
  1323. case "del": {
  1324. e += t.del(this.parseInline(s.tokens, t));
  1325. break;
  1326. }
  1327. case "text": {
  1328. e += t.text(s.text);
  1329. break;
  1330. }
  1331. default: {
  1332. const h = 'Token with "' + s.type + '" type was not found.';
  1333. if (this.options.silent) {
  1334. console.error(h);
  1335. return;
  1336. } else
  1337. throw new Error(h);
  1338. }
  1339. }
  1340. }
  1341. return e;
  1342. }
  1343. }
  1344. class O {
  1345. constructor(n) {
  1346. this.options = n || L;
  1347. }
  1348. /**
  1349. * Process markdown before marked
  1350. */
  1351. preprocess(n) {
  1352. return n;
  1353. }
  1354. /**
  1355. * Process HTML after marked is finished
  1356. */
  1357. postprocess(n) {
  1358. return n;
  1359. }
  1360. }
  1361. B(O, "passThroughHooks", /* @__PURE__ */ new Set([
  1362. "preprocess",
  1363. "postprocess"
  1364. ]));
  1365. function we(a, n, t) {
  1366. return (e) => {
  1367. if (e.message += `
  1368. Please report this to https://github.com/markedjs/marked.`, a) {
  1369. const i = "<p>An error occurred:</p><pre>" + z(e.message + "", !0) + "</pre>";
  1370. if (n)
  1371. return Promise.resolve(i);
  1372. if (t) {
  1373. t(null, i);
  1374. return;
  1375. }
  1376. return i;
  1377. }
  1378. if (n)
  1379. return Promise.reject(e);
  1380. if (t) {
  1381. t(e);
  1382. return;
  1383. }
  1384. throw e;
  1385. };
  1386. }
  1387. function ee(a, n) {
  1388. return (t, e, i) => {
  1389. typeof e == "function" && (i = e, e = null);
  1390. const s = { ...e };
  1391. e = { ...f.defaults, ...s };
  1392. const l = we(e.silent, e.async, i);
  1393. if (typeof t > "u" || t === null)
  1394. return l(new Error("marked(): input parameter is undefined or null"));
  1395. if (typeof t != "string")
  1396. return l(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(t) + ", string expected"));
  1397. if (me(e), e.hooks && (e.hooks.options = e), i) {
  1398. const o = e.highlight;
  1399. let h;
  1400. try {
  1401. e.hooks && (t = e.hooks.preprocess(t)), h = a(t, e);
  1402. } catch (b) {
  1403. return l(b);
  1404. }
  1405. const w = function(b) {
  1406. let c;
  1407. if (!b)
  1408. try {
  1409. e.walkTokens && f.walkTokens(h, e.walkTokens), c = n(h, e), e.hooks && (c = e.hooks.postprocess(c));
  1410. } catch (r) {
  1411. b = r;
  1412. }
  1413. return e.highlight = o, b ? l(b) : i(null, c);
  1414. };
  1415. if (!o || o.length < 3 || (delete e.highlight, !h.length))
  1416. return w();
  1417. let x = 0;
  1418. f.walkTokens(h, function(b) {
  1419. b.type === "code" && (x++, setTimeout(() => {
  1420. o(b.text, b.lang, function(c, r) {
  1421. if (c)
  1422. return w(c);
  1423. r != null && r !== b.text && (b.text = r, b.escaped = !0), x--, x === 0 && w();
  1424. });
  1425. }, 0));
  1426. }), x === 0 && w();
  1427. return;
  1428. }
  1429. if (e.async)
  1430. return Promise.resolve(e.hooks ? e.hooks.preprocess(t) : t).then((o) => a(o, e)).then((o) => e.walkTokens ? Promise.all(f.walkTokens(o, e.walkTokens)).then(() => o) : o).then((o) => n(o, e)).then((o) => e.hooks ? e.hooks.postprocess(o) : o).catch(l);
  1431. try {
  1432. e.hooks && (t = e.hooks.preprocess(t));
  1433. const o = a(t, e);
  1434. e.walkTokens && f.walkTokens(o, e.walkTokens);
  1435. let h = n(o, e);
  1436. return e.hooks && (h = e.hooks.postprocess(h)), h;
  1437. } catch (o) {
  1438. return l(o);
  1439. }
  1440. };
  1441. }
  1442. function f(a, n, t) {
  1443. return ee(E.lex, I.parse)(a, n, t);
  1444. }
  1445. f.options = f.setOptions = function(a) {
  1446. return f.defaults = { ...f.defaults, ...a }, se(f.defaults), f;
  1447. };
  1448. f.getDefaults = X;
  1449. f.defaults = L;
  1450. f.use = function(...a) {
  1451. const n = f.defaults.extensions || { renderers: {}, childTokens: {} };
  1452. a.forEach((t) => {
  1453. const e = { ...t };
  1454. if (e.async = f.defaults.async || e.async || !1, t.extensions && (t.extensions.forEach((i) => {
  1455. if (!i.name)
  1456. throw new Error("extension name required");
  1457. if (i.renderer) {
  1458. const s = n.renderers[i.name];
  1459. s ? n.renderers[i.name] = function(...l) {
  1460. let o = i.renderer.apply(this, l);
  1461. return o === !1 && (o = s.apply(this, l)), o;
  1462. } : n.renderers[i.name] = i.renderer;
  1463. }
  1464. if (i.tokenizer) {
  1465. if (!i.level || i.level !== "block" && i.level !== "inline")
  1466. throw new Error("extension level must be 'block' or 'inline'");
  1467. n[i.level] ? n[i.level].unshift(i.tokenizer) : n[i.level] = [i.tokenizer], i.start && (i.level === "block" ? n.startBlock ? n.startBlock.push(i.start) : n.startBlock = [i.start] : i.level === "inline" && (n.startInline ? n.startInline.push(i.start) : n.startInline = [i.start]));
  1468. }
  1469. i.childTokens && (n.childTokens[i.name] = i.childTokens);
  1470. }), e.extensions = n), t.renderer) {
  1471. const i = f.defaults.renderer || new q();
  1472. for (const s in t.renderer) {
  1473. const l = i[s];
  1474. i[s] = (...o) => {
  1475. let h = t.renderer[s].apply(i, o);
  1476. return h === !1 && (h = l.apply(i, o)), h;
  1477. };
  1478. }
  1479. e.renderer = i;
  1480. }
  1481. if (t.tokenizer) {
  1482. const i = f.defaults.tokenizer || new N();
  1483. for (const s in t.tokenizer) {
  1484. const l = i[s];
  1485. i[s] = (...o) => {
  1486. let h = t.tokenizer[s].apply(i, o);
  1487. return h === !1 && (h = l.apply(i, o)), h;
  1488. };
  1489. }
  1490. e.tokenizer = i;
  1491. }
  1492. if (t.hooks) {
  1493. const i = f.defaults.hooks || new O();
  1494. for (const s in t.hooks) {
  1495. const l = i[s];
  1496. O.passThroughHooks.has(s) ? i[s] = (o) => {
  1497. if (f.defaults.async)
  1498. return Promise.resolve(t.hooks[s].call(i, o)).then((w) => l.call(i, w));
  1499. const h = t.hooks[s].call(i, o);
  1500. return l.call(i, h);
  1501. } : i[s] = (...o) => {
  1502. let h = t.hooks[s].apply(i, o);
  1503. return h === !1 && (h = l.apply(i, o)), h;
  1504. };
  1505. }
  1506. e.hooks = i;
  1507. }
  1508. if (t.walkTokens) {
  1509. const i = f.defaults.walkTokens;
  1510. e.walkTokens = function(s) {
  1511. let l = [];
  1512. return l.push(t.walkTokens.call(this, s)), i && (l = l.concat(i.call(this, s))), l;
  1513. };
  1514. }
  1515. f.setOptions(e);
  1516. });
  1517. };
  1518. f.walkTokens = function(a, n) {
  1519. let t = [];
  1520. for (const e of a)
  1521. switch (t = t.concat(n.call(f, e)), e.type) {
  1522. case "table": {
  1523. for (const i of e.header)
  1524. t = t.concat(f.walkTokens(i.tokens, n));
  1525. for (const i of e.rows)
  1526. for (const s of i)
  1527. t = t.concat(f.walkTokens(s.tokens, n));
  1528. break;
  1529. }
  1530. case "list": {
  1531. t = t.concat(f.walkTokens(e.items, n));
  1532. break;
  1533. }
  1534. default:
  1535. f.defaults.extensions && f.defaults.extensions.childTokens && f.defaults.extensions.childTokens[e.type] ? f.defaults.extensions.childTokens[e.type].forEach(function(i) {
  1536. t = t.concat(f.walkTokens(e[i], n));
  1537. }) : e.tokens && (t = t.concat(f.walkTokens(e.tokens, n)));
  1538. }
  1539. return t;
  1540. };
  1541. f.parseInline = ee(E.lexInline, I.parseInline);
  1542. f.Parser = I;
  1543. f.parser = I.parse;
  1544. f.Renderer = q;
  1545. f.TextRenderer = K;
  1546. f.Lexer = E;
  1547. f.lexer = E.lex;
  1548. f.Tokenizer = N;
  1549. f.Slugger = Y;
  1550. f.Hooks = O;
  1551. f.parse = f;
  1552. f.options;
  1553. f.setOptions;
  1554. f.use;
  1555. f.walkTokens;
  1556. f.parseInline;
  1557. I.parse;
  1558. E.lex;
  1559. /*!
  1560. * The reveal.js markdown plugin. Handles parsing of
  1561. * markdown inside of presentations as well as loading
  1562. * of external markdown documents.
  1563. */
  1564. const _e = `\r?
  1565. ---\r?
  1566. `, ye = null, $e = "^s*notes?:", Se = "\\.element\\s*?(.+?)$", Te = "\\.slide:\\s*?(\\S.+?)$", V = "__SCRIPT_END__", M = /\[\s*((\d*):)?\s*([\s\d,|-]*)\]/, Re = {
  1567. "&": "&amp;",
  1568. "<": "&lt;",
  1569. ">": "&gt;",
  1570. '"': "&quot;",
  1571. "'": "&#39;"
  1572. }, Ae = () => {
  1573. let a;
  1574. function n(c) {
  1575. let m = (c.querySelector("[data-template]") || c.querySelector("script") || c).textContent;
  1576. m = m.replace(new RegExp(V, "g"), "<\/script>");
  1577. const g = m.match(/^\n?(\s*)/)[1].length, y = m.match(/^\n?(\t*)/)[1].length;
  1578. return y > 0 ? m = m.replace(new RegExp("\\n?\\t{" + y + "}(.*)", "g"), function(p, k) {
  1579. return `
  1580. ` + k;
  1581. }) : g > 1 && (m = m.replace(new RegExp("\\n? {" + g + "}(.*)", "g"), function(p, k) {
  1582. return `
  1583. ` + k;
  1584. })), m;
  1585. }
  1586. function t(c) {
  1587. const r = c.attributes, m = [];
  1588. for (let g = 0, y = r.length; g < y; g++) {
  1589. const p = r[g].name, k = r[g].value;
  1590. /data\-(markdown|separator|vertical|notes)/gi.test(p) || (k ? m.push(p + '="' + k + '"') : m.push(p));
  1591. }
  1592. return m.join(" ");
  1593. }
  1594. function e(c) {
  1595. var m;
  1596. const r = (m = a == null ? void 0 : a.getConfig) == null ? void 0 : m.call(a).markdown;
  1597. return c = c || {}, c.separator = c.separator || (r == null ? void 0 : r.separator) || _e, c.verticalSeparator = c.verticalSeparator || (r == null ? void 0 : r.verticalSeparator) || ye, c.notesSeparator = c.notesSeparator || (r == null ? void 0 : r.notesSeparator) || $e, c.attributes = c.attributes || "", c;
  1598. }
  1599. function i(c, r) {
  1600. r = e(r);
  1601. const m = c.split(new RegExp(r.notesSeparator, "mgi"));
  1602. return m.length === 2 && (c = m[0] + '<aside class="notes">' + f(m[1].trim()) + "</aside>"), c = c.replace(/<\/script>/g, V), '<script type="text/template">' + c + "<\/script>";
  1603. }
  1604. function s(c, r) {
  1605. r = e(r);
  1606. const m = new RegExp(r.separator + (r.verticalSeparator ? "|" + r.verticalSeparator : ""), "mg"), g = new RegExp(r.separator);
  1607. let y, p = 0, k, _ = !0, T, $ = [];
  1608. for (; y = m.exec(c); )
  1609. k = g.test(y[0]), !k && _ && $.push([]), T = c.substring(p, y.index), k && _ ? $.push(T) : $[$.length - 1].push(T), p = m.lastIndex, _ = k;
  1610. (_ ? $ : $[$.length - 1]).push(c.substring(p));
  1611. let R = "";
  1612. for (let A = 0, v = $.length; A < v; A++)
  1613. $[A] instanceof Array ? (R += "<section " + r.attributes + ">", $[A].forEach(function(te) {
  1614. R += "<section data-markdown>" + i(te, r) + "</section>";
  1615. }), R += "</section>") : R += "<section " + r.attributes + " data-markdown>" + i($[A], r) + "</section>";
  1616. return R;
  1617. }
  1618. function l(c) {
  1619. return new Promise(function(r) {
  1620. const m = [];
  1621. [].slice.call(c.querySelectorAll("section[data-markdown]:not([data-markdown-parsed])")).forEach(function(g, y) {
  1622. g.getAttribute("data-markdown").length ? m.push(o(g).then(
  1623. // Finished loading external file
  1624. function(p, k) {
  1625. g.outerHTML = s(p.responseText, {
  1626. separator: g.getAttribute("data-separator"),
  1627. verticalSeparator: g.getAttribute("data-separator-vertical"),
  1628. notesSeparator: g.getAttribute("data-separator-notes"),
  1629. attributes: t(g)
  1630. });
  1631. },
  1632. // Failed to load markdown
  1633. function(p, k) {
  1634. g.outerHTML = '<section data-state="alert">ERROR: The attempt to fetch ' + k + " failed with HTTP status " + p.status + ".Check your browser's JavaScript console for more details.<p>Remember that you need to serve the presentation HTML from a HTTP server.</p></section>";
  1635. }
  1636. )) : g.outerHTML = s(n(g), {
  1637. separator: g.getAttribute("data-separator"),
  1638. verticalSeparator: g.getAttribute("data-separator-vertical"),
  1639. notesSeparator: g.getAttribute("data-separator-notes"),
  1640. attributes: t(g)
  1641. });
  1642. }), Promise.all(m).then(r);
  1643. });
  1644. }
  1645. function o(c) {
  1646. return new Promise(function(r, m) {
  1647. const g = new XMLHttpRequest(), y = c.getAttribute("data-markdown"), p = c.getAttribute("data-charset");
  1648. p !== null && p !== "" && g.overrideMimeType("text/html; charset=" + p), g.onreadystatechange = (function(k, _) {
  1649. _.readyState === 4 && (_.status >= 200 && _.status < 300 || _.status === 0 ? r(_, y) : m(_, y));
  1650. }).bind(this, c, g), g.open("GET", y, !0);
  1651. try {
  1652. g.send();
  1653. } catch (k) {
  1654. console.warn("Failed to get the Markdown file " + y + ". Make sure that the presentation and the file are served by a HTTP server and the file can be found there. " + k), r(g, y);
  1655. }
  1656. });
  1657. }
  1658. function h(c, r, m) {
  1659. const g = new RegExp(m, "mg"), y = new RegExp('([^"= ]+?)="([^"]+?)"|(data-[^"= ]+?)(?=[" ])', "mg");
  1660. let p = c.nodeValue, k, _;
  1661. if (k = g.exec(p)) {
  1662. const T = k[1];
  1663. for (p = p.substring(0, k.index) + p.substring(g.lastIndex), c.nodeValue = p; _ = y.exec(T); )
  1664. _[2] ? r.setAttribute(_[1], _[2]) : r.setAttribute(_[3], "");
  1665. return !0;
  1666. }
  1667. return !1;
  1668. }
  1669. function w(c, r, m, g, y) {
  1670. if (r !== null && r.childNodes !== void 0 && r.childNodes.length > 0) {
  1671. let p = r;
  1672. for (let k = 0; k < r.childNodes.length; k++) {
  1673. const _ = r.childNodes[k];
  1674. if (k > 0) {
  1675. let $ = k - 1;
  1676. for (; $ >= 0; ) {
  1677. const R = r.childNodes[$];
  1678. if (typeof R.setAttribute == "function" && R.tagName !== "BR") {
  1679. p = R;
  1680. break;
  1681. }
  1682. $ = $ - 1;
  1683. }
  1684. }
  1685. let T = c;
  1686. _.nodeName === "section" && (T = _, p = _), (typeof _.setAttribute == "function" || _.nodeType === Node.COMMENT_NODE) && w(T, _, p, g, y);
  1687. }
  1688. }
  1689. r.nodeType === Node.COMMENT_NODE && h(r, m, g) === !1 && h(r, c, y);
  1690. }
  1691. function x() {
  1692. const c = a.getRevealElement().querySelectorAll("[data-markdown]:not([data-markdown-parsed])");
  1693. return [].slice.call(c).forEach(function(r) {
  1694. r.setAttribute("data-markdown-parsed", !0);
  1695. const m = r.querySelector("aside.notes"), g = n(r);
  1696. r.innerHTML = f(g), w(
  1697. r,
  1698. r,
  1699. null,
  1700. r.getAttribute("data-element-attributes") || r.parentNode.getAttribute("data-element-attributes") || Se,
  1701. r.getAttribute("data-attributes") || r.parentNode.getAttribute("data-attributes") || Te
  1702. ), m && r.appendChild(m);
  1703. }), Promise.resolve();
  1704. }
  1705. function b(c) {
  1706. return c.replace(/([&<>'"])/g, (r) => Re[r]);
  1707. }
  1708. return {
  1709. id: "markdown",
  1710. /**
  1711. * Starts processing and converting Markdown within the
  1712. * current reveal.js deck.
  1713. */
  1714. init: function(c) {
  1715. a = c;
  1716. let { renderer: r, animateLists: m, ...g } = a.getConfig().markdown || {};
  1717. return r || (r = new f.Renderer(), r.code = (y, p) => {
  1718. let k = "", _ = "";
  1719. if (M.test(p)) {
  1720. let T = p.match(M)[2];
  1721. T && (k = `data-ln-start-from="${T.trim()}"`), _ = p.match(M)[3].trim(), _ = `data-line-numbers="${_}"`, p = p.replace(M, "").trim();
  1722. }
  1723. return y = b(y), `<pre><code ${_} ${k} class="${p}">${y}</code></pre>`;
  1724. }), m === !0 && (r.listitem = (y) => `<li class="fragment">${y}</li>`), f.setOptions({
  1725. renderer: r,
  1726. ...g
  1727. }), l(a.getRevealElement()).then(x);
  1728. },
  1729. // TODO: Do these belong in the API?
  1730. processSlides: l,
  1731. convertSlides: x,
  1732. slidify: s,
  1733. marked: f
  1734. };
  1735. };
  1736. export {
  1737. Ae as default
  1738. };