comarkserv 0.1.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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +389 -0
  3. package/dist/THIRD_PARTY_LICENSES.md +932 -0
  4. package/dist/build-CsToYJrU.mjs +2 -0
  5. package/dist/build-Cv5aO0CB.mjs +205 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +894 -0
  8. package/dist/cloudflared-6f_lzz4F.mjs +181 -0
  9. package/dist/dist-B-IALNns.mjs +2 -0
  10. package/dist/dist-BK-bpLWg.mjs +2 -0
  11. package/dist/dist-BQzCbTko.mjs +1693 -0
  12. package/dist/dist-BWcWG5YB.mjs +671 -0
  13. package/dist/dist-BiVw4ojz.mjs +592 -0
  14. package/dist/dist-BnmL9jeq.mjs +538 -0
  15. package/dist/dist-BtedNLrc.mjs +276 -0
  16. package/dist/dist-BvdNTrap.mjs +2710 -0
  17. package/dist/dist-ByijHttv.mjs +69 -0
  18. package/dist/dist-C2E4zSX1.mjs +347 -0
  19. package/dist/dist-CWYRQLUT.mjs +2 -0
  20. package/dist/dist-CXQ7eTfT.mjs +417 -0
  21. package/dist/dist-CfsjQ0o8.mjs +905 -0
  22. package/dist/dist-CsTXDvwi.mjs +300 -0
  23. package/dist/dist-CtONMLh4.mjs +283 -0
  24. package/dist/dist-DMftjyxU.mjs +370 -0
  25. package/dist/dist-Dr9uTCX7.mjs +2 -0
  26. package/dist/dist-Dxvc11TH.mjs +339 -0
  27. package/dist/dist-GmbcGEAc.mjs +3 -0
  28. package/dist/dist-V1rkISnf.mjs +220 -0
  29. package/dist/dist-ZoN94PJ0.mjs +76 -0
  30. package/dist/dist-fh99cWMN.mjs +524 -0
  31. package/dist/editor-CHDyOp-8.mjs +721 -0
  32. package/dist/index.d.mts +301 -0
  33. package/dist/index.mjs +6 -0
  34. package/dist/languages-C0kEygG_.mjs +119 -0
  35. package/dist/markdown-BqKed1Vq.mjs +710 -0
  36. package/dist/markdown-DWuqfzps.mjs +2 -0
  37. package/dist/rolldown-runtime-CMFfr-1z.mjs +26 -0
  38. package/dist/server-Dkjk_D1Y.mjs +2628 -0
  39. package/dist/terminal-aKr5Xlp3.mjs +169 -0
  40. package/dist/themes-mEufQ_3e.mjs +2194 -0
  41. package/dist/twinkleplop.production-Coccf2Q9.mjs +2 -0
  42. package/dist/twinkleplop.production-DekYmX6O.mjs +4697 -0
  43. package/dist/twinkleplop.tokens-CgBUTCSg.mjs +76 -0
  44. package/package.json +133 -0
@@ -0,0 +1,710 @@
1
+ import { a as resolveLanguage, c as errorBlock, l as isElement, n as languageAliases, o as supportedLanguages, r as loadLanguage, s as childrenOf, t as getLoadedLanguage, u as stringAttr } from "./languages-C0kEygG_.mjs";
2
+ import { G as ge } from "./twinkleplop.production-DekYmX6O.mjs";
3
+ import { createMarkdownParser } from "comark";
4
+ import { escapeHtml, textContent } from "comark/utils";
5
+ import emoji from "comark/plugins/emoji";
6
+ import footnotes from "comark/plugins/footnotes";
7
+ import math from "comark/plugins/math";
8
+ import mermaid from "comark/plugins/mermaid";
9
+ import toc from "comark/plugins/toc";
10
+ import { renderHtmlFromDocument } from "@comark/html";
11
+ //#region src/components.ts
12
+ const ALERT_TITLES = {
13
+ note: "Note",
14
+ tip: "Tip",
15
+ important: "Important",
16
+ warning: "Warning",
17
+ caution: "Caution"
18
+ };
19
+ const ALERT_COMPONENTS = {
20
+ note: "note",
21
+ info: "note",
22
+ callout: "note",
23
+ tip: "tip",
24
+ success: "tip",
25
+ important: "important",
26
+ warning: "warning",
27
+ caution: "caution",
28
+ danger: "caution"
29
+ };
30
+ const ICON_PATHS = {
31
+ note: "<circle cx=\"12\" cy=\"12\" r=\"9\"/><path d=\"M12 16v-4M12 8h.01\"/>",
32
+ tip: "<path d=\"M9 18h6M10 21h4M12 3a6 6 0 0 0-4 10.5c.6.6 1 1.4 1 2.5h6c0-1.1.4-1.9 1-2.5A6 6 0 0 0 12 3Z\"/>",
33
+ important: "<path d=\"M4 4h16v12H8l-4 4Z\"/><path d=\"M12 7v4M12 13.5h.01\"/>",
34
+ warning: "<path d=\"M12 3 2 20h20Z\"/><path d=\"M12 9v5M12 17h.01\"/>",
35
+ caution: "<path d=\"M8 3h8l5 5v8l-5 5H8l-5-5V8Z\"/><path d=\"M12 8v5M12 16h.01\"/>"
36
+ };
37
+ const INLINE_TAGS = /* @__PURE__ */ new Set([
38
+ "a",
39
+ "abbr",
40
+ "b",
41
+ "br",
42
+ "code",
43
+ "del",
44
+ "em",
45
+ "i",
46
+ "img",
47
+ "input",
48
+ "kbd",
49
+ "mark",
50
+ "math",
51
+ "s",
52
+ "small",
53
+ "span",
54
+ "strong",
55
+ "sub",
56
+ "sup",
57
+ "u"
58
+ ]);
59
+ function icon(type) {
60
+ return `<svg class="cms-icon" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${ICON_PATHS[type]}</svg>`;
61
+ }
62
+ function isInline(node) {
63
+ return typeof node === "string" || isElement(node) && INLINE_TAGS.has(node[0]);
64
+ }
65
+ async function renderBody(node, state) {
66
+ const children = childrenOf(node);
67
+ const html = await state.flow(node, state);
68
+ return children.length > 0 && children.every(isInline) ? `<p>${html.trim()}</p>` : html;
69
+ }
70
+ function toAlertType(value) {
71
+ if (typeof value !== "string") return void 0;
72
+ const key = value.toLowerCase();
73
+ if (Object.hasOwn(ALERT_TITLES, key)) return key;
74
+ return Object.hasOwn(ALERT_COMPONENTS, key) ? ALERT_COMPONENTS[key] : void 0;
75
+ }
76
+ async function alert(type, node, state) {
77
+ const title = stringAttr(node[1], "title") ?? ALERT_TITLES[type];
78
+ const body = await renderBody(node, state);
79
+ return `<div class="cms-alert cms-alert-${type}"><p class="cms-alert-title">${icon(type)}${escapeHtml(title)}</p>${body}</div>`;
80
+ }
81
+ const githubAlert = {
82
+ match: (node) => node[0] === "blockquote" && toAlertType(node[1].as) !== void 0,
83
+ handler: (node, state) => alert(toAlertType(node[1].as) ?? "note", node, state)
84
+ };
85
+ const alertComponent = (node, state) => {
86
+ return alert(toAlertType(node[0] === "alert" ? node[1].type : node[0]) ?? "note", node, state);
87
+ };
88
+ const codeGroup = async (node, state) => {
89
+ const panels = childrenOf(node).filter(isElement);
90
+ const tabs = [];
91
+ const bodies = [];
92
+ for (const [index, panel] of panels.entries()) {
93
+ const attrs = panel[1];
94
+ const label = stringAttr(attrs, "filename") ?? stringAttr(attrs, "language") ?? `Tab ${index + 1}`;
95
+ const selected = index === 0;
96
+ const { filename: _filename, ...rest } = attrs;
97
+ tabs.push(`<button role="tab" aria-selected="${selected}">${escapeHtml(label)}</button>`);
98
+ bodies.push(`<div role="tabpanel"${selected ? "" : " hidden"}>${await state.render([
99
+ panel[0],
100
+ rest,
101
+ ...childrenOf(panel)
102
+ ])}</div>`);
103
+ }
104
+ return `<div class="cms-code-group"><div class="cms-tabs" role="tablist">${tabs.join("")}</div>${bodies.join("")}</div>`;
105
+ };
106
+ const details = async (node, state) => {
107
+ const summary = stringAttr(node[1], "summary") ?? "Details";
108
+ const body = await renderBody(node, state);
109
+ return `<details><summary>${escapeHtml(summary)}</summary>${body}</details>`;
110
+ };
111
+ let katex;
112
+ function loadKatex() {
113
+ katex ??= import("katex").then((module) => module.default);
114
+ return katex;
115
+ }
116
+ const math$1 = async ([, attrs]) => {
117
+ const content = stringAttr(attrs, "content") ?? "";
118
+ const inline = (stringAttr(attrs, "class") ?? "").includes("inline");
119
+ const html = (await loadKatex()).renderToString(content, {
120
+ displayMode: !inline,
121
+ throwOnError: false,
122
+ output: "htmlAndMathml"
123
+ });
124
+ return inline ? `<span class="cms-math">${html}</span>` : `<div class="cms-math cms-math-block">${html}</div>`;
125
+ };
126
+ const FONT_IMPORT = /@import url\([^)]*fonts\.googleapis\.com[^)]*\);?/g;
127
+ const MERMAID_CACHE_SIZE = 256;
128
+ const mermaidCache = /* @__PURE__ */ new Map();
129
+ const mermaid$1 = async ([, attrs]) => {
130
+ const content = stringAttr(attrs, "content") ?? "";
131
+ const cached = mermaidCache.get(content);
132
+ if (cached) return cached;
133
+ let html;
134
+ try {
135
+ const { renderMermaidSVG } = await import("beautiful-mermaid");
136
+ html = `<figure class="cms-mermaid">${renderMermaidSVG(content, {
137
+ bg: "var(--cms-bg)",
138
+ fg: "var(--cms-fg)",
139
+ transparent: true
140
+ }).replace(FONT_IMPORT, "")}</figure>`;
141
+ } catch (error) {
142
+ return errorBlock(content, error);
143
+ }
144
+ if (mermaidCache.size >= MERMAID_CACHE_SIZE) mermaidCache.delete(mermaidCache.keys().next().value ?? "");
145
+ mermaidCache.set(content, html);
146
+ return html;
147
+ };
148
+ function createComponents() {
149
+ const components = {
150
+ githubAlert,
151
+ alert: alertComponent,
152
+ "code-group": codeGroup,
153
+ details,
154
+ math: math$1,
155
+ mermaid: mermaid$1
156
+ };
157
+ for (const name of Object.keys(ALERT_COMPONENTS)) components[name] = alertComponent;
158
+ return components;
159
+ }
160
+ /** Loads the libraries that the features of a page need, before the page renders. */
161
+ async function preloadFeatures(features) {
162
+ if (features.math) await loadKatex();
163
+ }
164
+ //#endregion
165
+ //#region node_modules/.pnpm/@twinkleplop+markdown-core@0.1.4/node_modules/@twinkleplop/markdown-core/dist/index.js
166
+ var t = 123;
167
+ var n = 125;
168
+ var r = 91;
169
+ var i = 93;
170
+ var a = 47;
171
+ var o = 92;
172
+ var s = 35;
173
+ var c = 32;
174
+ var l = 9;
175
+ var u = 34;
176
+ var d = 39;
177
+ function p(e, t) {
178
+ let n = {
179
+ line_groups: [],
180
+ word_groups: [],
181
+ twoslash: !1
182
+ };
183
+ for (let r of h(e)) for (let e of m) if (e(r, n, t)) break;
184
+ return n;
185
+ }
186
+ var m = [
187
+ g,
188
+ _,
189
+ v,
190
+ y,
191
+ b,
192
+ x,
193
+ S
194
+ ];
195
+ function h(e) {
196
+ let s = [], f = 0;
197
+ for (; f < e.length;) {
198
+ let p = e.charCodeAt(f);
199
+ if (p === c || p === l) {
200
+ f++;
201
+ continue;
202
+ }
203
+ let m = f, h = 0, g = 0, _ = !1;
204
+ for (; f < e.length;) {
205
+ let s = e.charCodeAt(f);
206
+ if (h !== 0) s === h && (h = 0), f++;
207
+ else if (_) s === o ? f += 2 : (s === a && (_ = !1), f++);
208
+ else if (s === u || s === d) h = s, f++;
209
+ else if (s === t || s === r) g++, f++;
210
+ else if (s === n || s === i) g > 0 && g--, f++;
211
+ else if (s === a && f === m) _ = !0, f++;
212
+ else if (g === 0 && (s === c || s === l)) break;
213
+ else f++;
214
+ }
215
+ s.push(e.slice(m, f));
216
+ }
217
+ return s;
218
+ }
219
+ function g(e, n) {
220
+ if (e.charCodeAt(0) !== t) return !1;
221
+ let r = e.indexOf("}");
222
+ if (r === -1) return !1;
223
+ let i = T(e.slice(1, r));
224
+ if (i === null) return !1;
225
+ let a = w(e.slice(r + 1));
226
+ return a === null ? !1 : (n.line_groups.push(a === "" ? { lines: i } : {
227
+ lines: i,
228
+ id: a
229
+ }), !0);
230
+ }
231
+ function _(e, t) {
232
+ if (e.charCodeAt(0) !== a) return !1;
233
+ let n = "", r = 1, i = !1;
234
+ for (; r < e.length; r++) {
235
+ let t = e.charCodeAt(r);
236
+ if (t === o && r + 1 < e.length) n += e[r + 1], r++;
237
+ else if (t === a) {
238
+ i = !0;
239
+ break;
240
+ } else n += e[r];
241
+ }
242
+ if (!i || n.length === 0) return !1;
243
+ let c = e.slice(r + 1);
244
+ if (c.length === 0) return t.word_groups.push({ text: n }), !0;
245
+ if (c.charCodeAt(0) === s) {
246
+ let e = w(c);
247
+ return e === null || e === "" ? !1 : (t.word_groups.push({
248
+ text: n,
249
+ id: e
250
+ }), !0);
251
+ }
252
+ let l = E(c);
253
+ return l === null ? !1 : (t.word_groups.push({
254
+ text: n,
255
+ from: l[0],
256
+ to: l[1]
257
+ }), !0);
258
+ }
259
+ function v(e, t) {
260
+ if (e === ":no-line-numbers") return t.line_numbers = !1, !0;
261
+ if (e === ":line-numbers") return t.line_numbers = { start: 1 }, !0;
262
+ if (e.startsWith(":line-numbers=")) {
263
+ let n = D(e.slice(14));
264
+ return n === -1 ? !1 : (t.line_numbers = { start: n }, !0);
265
+ }
266
+ return !1;
267
+ }
268
+ function y(e, t) {
269
+ if (e === "showLineNumbers") return t.line_numbers = { start: 1 }, !0;
270
+ if (e.startsWith("showLineNumbers{") && e.endsWith("}")) {
271
+ let n = D(e.slice(16, e.length - 1));
272
+ return n === -1 ? !1 : (t.line_numbers = { start: n }, !0);
273
+ }
274
+ return !1;
275
+ }
276
+ function b(e, t, n) {
277
+ if (e.charCodeAt(0) !== r || e.charCodeAt(e.length - 1) !== i) return !1;
278
+ let a = e.slice(1, e.length - 1);
279
+ return a.length === 0 ? !1 : (C(t, a, n), !0);
280
+ }
281
+ function x(e, t, n) {
282
+ let r = e.indexOf("=");
283
+ if (r <= 0) return !1;
284
+ let i = e.slice(0, r);
285
+ if (i !== "title" && i !== "caption") return !1;
286
+ let a = O(e.slice(r + 1));
287
+ return a === null ? !1 : (i === "title" ? C(t, a, n) : t.caption === void 0 ? t.caption = a : n("two caption conventions"), !0);
288
+ }
289
+ function S(e, t) {
290
+ return e === "twoslash" ? (t.twoslash = !0, !0) : !1;
291
+ }
292
+ function C(e, t, n) {
293
+ e.title !== void 0 && n("two title conventions"), e.title = t;
294
+ }
295
+ function w(e) {
296
+ if (e.length === 0) return "";
297
+ if (e.charCodeAt(0) !== s) return null;
298
+ let t = e.slice(1);
299
+ return t.length === 0 ? null : t;
300
+ }
301
+ function T(e) {
302
+ if (e.trim().length === 0) return null;
303
+ let t = [];
304
+ for (let n of e.split(",")) {
305
+ let e = E(n.trim());
306
+ if (e === null) return null;
307
+ t.push(e[0] === e[1] ? e[0] : e);
308
+ }
309
+ return t;
310
+ }
311
+ function E(e) {
312
+ let t = e.indexOf("-");
313
+ if (t === -1) {
314
+ let t = D(e);
315
+ return t === -1 ? null : [t, t];
316
+ }
317
+ let n = D(e.slice(0, t)), r = D(e.slice(t + 1));
318
+ return n === -1 || r === -1 ? null : [n, r];
319
+ }
320
+ function D(e) {
321
+ if (e.length === 0) return -1;
322
+ let t = 0;
323
+ for (let n = 0; n < e.length; n++) {
324
+ let r = e.charCodeAt(n);
325
+ if (r < 48 || r > 57) return -1;
326
+ t = t * 10 + (r - 48);
327
+ }
328
+ return t;
329
+ }
330
+ function O(e) {
331
+ if (e.length < 2) return null;
332
+ let t = e.charCodeAt(0);
333
+ return t !== u && t !== d || e.charCodeAt(e.length - 1) !== t ? null : e.slice(1, e.length - 1);
334
+ }
335
+ function k(e, t) {
336
+ if (typeof e != "object" || !e || Array.isArray(e)) throw TypeError("languages must be an object mapping a fence name to a highlighter");
337
+ let n = Object.keys(e), r = /* @__PURE__ */ new Map();
338
+ for (let t of n) r.set(t, A(e, t));
339
+ if (t !== void 0 && !r.has(t)) throw Error(`default_language "${t}" is not in languages`);
340
+ return r;
341
+ }
342
+ function A(e, t) {
343
+ let n = [t], r = e[t];
344
+ for (; typeof r == "string";) {
345
+ if (n.includes(r)) throw Error(`alias cycle in languages: ${[...n, r].join(" -> ")}`);
346
+ if (!(r in e)) throw Error(`languages.${n[n.length - 1]} aliases "${r}", which is not in languages`);
347
+ n.push(r), r = e[r];
348
+ }
349
+ if (typeof r == "function") return { highlight: r };
350
+ if (typeof r == "object" && r && typeof r.highlight == "function") {
351
+ let { highlight: e, twoslash: n } = r;
352
+ if (n !== void 0 && typeof n != "function") throw TypeError(`languages.${t}.twoslash must be a function`);
353
+ return n === void 0 ? { highlight: e } : {
354
+ highlight: e,
355
+ twoslash: n
356
+ };
357
+ }
358
+ throw TypeError(`languages.${t} must be a highlight function, { highlight, twoslash }, or the name of another entry`);
359
+ }
360
+ var j = {
361
+ tokens: /* @__PURE__ */ new Uint32Array(),
362
+ token_types: []
363
+ };
364
+ var M = "highlight";
365
+ var N = "highlighted-word";
366
+ function P(e) {
367
+ if (typeof e != "object" || !e) throw TypeError("the plugin options must be an object with a `languages` registry");
368
+ let t = k(e.languages, e.default_language), n = e.default_language, r = e.on_unknown_language ?? "throw", i = e.twoslash ?? "meta", a = e.inline ?? !1, o = e.line_numbers, s = e.parse_meta, c = e.render ?? {};
369
+ function l(e, i, a, o) {
370
+ let c = (e ?? "").trim() || n;
371
+ if (c === void 0 || c === "") return null;
372
+ let l = i ?? "", f = Y(c, o), m = p(l, f), h = J(a), g = t.get(c);
373
+ if (g === void 0 && r === "throw") throw Error(`unknown fence language "${c}"${X(o)}`);
374
+ let _ = d(c, m, h, f);
375
+ return s !== void 0 && (_ = s(l, _) ?? _), L(c, m, I(u(c, g, m, f), h, _, c, o));
376
+ }
377
+ function u(e, t, n, r) {
378
+ return t === void 0 ? F : n.twoslash ? (t.twoslash === void 0 && r(`"${e}" has no twoslash highlighter`), t.twoslash) : i === "always" && t.twoslash !== void 0 ? t.twoslash : t.highlight;
379
+ }
380
+ function d(e, t, n, r) {
381
+ let i = c.overlays === void 0 ? [] : [...c.overlays], a = /* @__PURE__ */ new Map(), s = [];
382
+ R(t, n, i, a, r), z(t, n, i, s);
383
+ let l = {
384
+ ...c,
385
+ class_name: Z(c.class_name ?? "twinkleplop", "language-" + Q(e)),
386
+ attributes: {
387
+ ...c.attributes,
388
+ "data-language": e
389
+ },
390
+ line_numbers: U(t, o, c.line_numbers)
391
+ };
392
+ return i.length > 0 && (l.overlays = i), a.size > 0 && (l.line = W(a, c.line)), s.length > 0 && (l.token = G(s, c.token)), l;
393
+ }
394
+ function f(e, n) {
395
+ if (a === !1) return null;
396
+ let i = q(e);
397
+ if (i === null) return null;
398
+ let { name: o, code: s } = i, l = t.get(o);
399
+ if (l === void 0 && r === "throw") throw Error(`unknown inline code language "${o}"${X(n)}`);
400
+ let u = I(l === void 0 ? F : l.highlight, s, {
401
+ ...c,
402
+ structure: "inline"
403
+ }, o, n);
404
+ return `<code class="twinkleplop-inline language-${Q(o)}">${u}</code>`;
405
+ }
406
+ return {
407
+ inline: a !== !1,
408
+ fence: l,
409
+ inline_code: f
410
+ };
411
+ }
412
+ function F(t, n) {
413
+ return ge(t, j, n);
414
+ }
415
+ function I(e, t, n, r, i) {
416
+ try {
417
+ return e(t, n);
418
+ } catch (e) {
419
+ let t = X(i);
420
+ if (t !== "" && e instanceof Error) {
421
+ let n = ` (\`${r}\` fence${t})`;
422
+ e.message.endsWith(n) || (e.message += n);
423
+ }
424
+ throw e;
425
+ }
426
+ }
427
+ function L(e, t, n) {
428
+ let { title: r, caption: i } = t;
429
+ if (r === void 0 && i === void 0) return n;
430
+ let a = `<figure class="twinkleplop-block" data-language="${Q(e)}">\n`;
431
+ return r !== void 0 && (a += `<figcaption class="twinkleplop-title">${Q(r)}</figcaption>\n`), a += n, i !== void 0 && (a += `\n<figcaption class="twinkleplop-caption">${Q(i)}</figcaption>`), a + "\n</figure>";
432
+ }
433
+ function R(e, t, n, r, i) {
434
+ if (e.line_groups.length === 0) return;
435
+ let a = H(t);
436
+ for (let t of e.line_groups) {
437
+ for (let e of t.lines) {
438
+ if (typeof e == "number") {
439
+ V(e, a, i), t.id !== void 0 && r.set(e, t.id);
440
+ continue;
441
+ }
442
+ let [n, o] = e;
443
+ if (V(n, a, i), V(o, a, i), o < n && i(`line range ${n}-${o} runs backwards`), t.id !== void 0) for (let e = n; e <= o; e++) r.set(e, t.id);
444
+ }
445
+ n.push({
446
+ lines: t.lines,
447
+ class: M
448
+ });
449
+ }
450
+ }
451
+ function z(e, t, n, r) {
452
+ for (let i of e.word_groups) {
453
+ let e = B(t, i.text), a = i.from ?? 1, o = Math.min(i.to ?? e.length, e.length);
454
+ for (let t = a; t <= o; t++) {
455
+ let a = e[t - 1], o = a + i.text.length;
456
+ n.push({
457
+ start: a,
458
+ end: o,
459
+ class: N
460
+ }), i.id !== void 0 && r.push({
461
+ start: a,
462
+ end: o,
463
+ id: i.id
464
+ });
465
+ }
466
+ }
467
+ }
468
+ function B(e, t) {
469
+ let n = [], r = 0;
470
+ for (;;) {
471
+ let i = e.indexOf(t, r);
472
+ if (i === -1) return n;
473
+ n.push(i), r = i + t.length;
474
+ }
475
+ }
476
+ function V(e, t, n) {
477
+ (e < 1 || e > t) && n(`line ${e} is beyond the fence's ${t} line${t === 1 ? "" : "s"}`);
478
+ }
479
+ function H(e) {
480
+ let t = 1;
481
+ for (let n = 0; n < e.length; n++) e.charCodeAt(n) === 10 && t++;
482
+ return t;
483
+ }
484
+ function U(e, t, n) {
485
+ return e.line_numbers === void 0 ? t === void 0 ? n : t : e.line_numbers;
486
+ }
487
+ function W(e, t) {
488
+ return (n, r) => {
489
+ let i = e.get(r), a = t?.(n, r);
490
+ return i === void 0 ? a : K(a, { attrs: { "data-highlighted-line-id": i } });
491
+ };
492
+ }
493
+ function G(e, t) {
494
+ return (n, r, i) => {
495
+ let a = t?.(n, r, i);
496
+ for (let t of e) if (r >= t.start && i <= t.end) return K(a, { attrs: { "data-chars-id": t.id } });
497
+ return a;
498
+ };
499
+ }
500
+ function K(e, t) {
501
+ return e == null ? t : {
502
+ class: Z(e.class ?? "", t.class ?? ""),
503
+ attrs: {
504
+ ...e.attrs,
505
+ ...t.attrs
506
+ }
507
+ };
508
+ }
509
+ function q(e) {
510
+ if (!e.endsWith("}")) return null;
511
+ let t = e.lastIndexOf("{:");
512
+ if (t === -1) return null;
513
+ let n = e.slice(t + 2, e.length - 1);
514
+ if (n.length === 0) return null;
515
+ for (let e = 0; e < n.length; e++) {
516
+ let t = n.charCodeAt(e);
517
+ if (t === 32 || t === 9 || t === 123 || t === 125) return null;
518
+ }
519
+ return {
520
+ name: n,
521
+ code: e.slice(0, t)
522
+ };
523
+ }
524
+ function J(e) {
525
+ return e.endsWith("\n") ? e.slice(0, e.length - 1) : e;
526
+ }
527
+ function Y(e, t) {
528
+ return (n) => {
529
+ throw Error(`${n} (\`${e}\` fence${X(t)})`);
530
+ };
531
+ }
532
+ function X(e) {
533
+ if (e === void 0) return "";
534
+ let { file: t, line: n } = e;
535
+ return t !== void 0 && n !== void 0 ? ` at ${t}:${n}` : t === void 0 ? n === void 0 ? "" : ` at line ${n}` : ` at ${t}`;
536
+ }
537
+ function Z(e, t) {
538
+ return e.length === 0 ? t : t.length === 0 ? e : e + " " + t;
539
+ }
540
+ function Q(e) {
541
+ let t = "", n = 0;
542
+ for (let r = 0; r < e.length; r++) {
543
+ let i = e.charCodeAt(r), a = null;
544
+ i === 38 ? a = "&amp;" : i === 60 ? a = "&lt;" : i === 62 ? a = "&gt;" : i === 34 ? a = "&quot;" : i === 39 && (a = "&#39;"), a !== null && (r > n && (t += e.slice(n, r)), t += a, n = r + 1);
545
+ }
546
+ return n === 0 ? e : t + e.slice(n);
547
+ }
548
+ //#endregion
549
+ //#region src/highlight.ts
550
+ const INLINE_LANGUAGE = /\{:([^{}\s]+)\}$/;
551
+ function createRegistry() {
552
+ const registry = { ...languageAliases };
553
+ for (const id of supportedLanguages) registry[id] = lazyHighlight(id);
554
+ return registry;
555
+ }
556
+ function lazyHighlight(id) {
557
+ return (code, render) => {
558
+ const highlight = getLoadedLanguage(id);
559
+ if (!highlight) throw new Error(`The "${id}" grammar is not loaded`);
560
+ return highlight(code, render);
561
+ };
562
+ }
563
+ function fenceLanguage(attrs) {
564
+ return stringAttr(attrs, "language")?.trim().toLowerCase() ?? "";
565
+ }
566
+ function fenceMeta(attrs) {
567
+ const parts = [];
568
+ if (Array.isArray(attrs.highlights) && attrs.highlights.length > 0) parts.push(`{${attrs.highlights.join(",")}}`);
569
+ const filename = stringAttr(attrs, "filename");
570
+ if (filename) parts.push(`[${filename}]`);
571
+ const meta = stringAttr(attrs, "meta")?.trim();
572
+ if (meta) parts.push(meta);
573
+ return parts.length > 0 ? parts.join(" ") : void 0;
574
+ }
575
+ function codeText(node) {
576
+ if (!isElement(node) || node[0] !== "code") return "";
577
+ return childrenOf(node).filter((child) => typeof child === "string").join("");
578
+ }
579
+ function inlineText(node) {
580
+ return node.length === 3 && typeof node[2] === "string" ? node[2] : void 0;
581
+ }
582
+ function plainBlock(code) {
583
+ return `<pre class="twinkleplop"><code>${escapeHtml(code)}</code></pre>`;
584
+ }
585
+ /** Returns the ids of the known grammars that code blocks and inline code in the nodes use. */
586
+ function collectLanguages(nodes) {
587
+ const found = /* @__PURE__ */ new Set();
588
+ const walk = (node, parent) => {
589
+ if (!isElement(node)) return;
590
+ const [tag, attrs] = node;
591
+ if (tag === "pre") {
592
+ const id = resolveLanguage(fenceLanguage(attrs));
593
+ if (id) found.add(id);
594
+ return;
595
+ }
596
+ if (tag === "code" && parent?.[0] !== "pre") {
597
+ const match = INLINE_LANGUAGE.exec(inlineText(node) ?? "");
598
+ const id = resolveLanguage(match?.[1]);
599
+ if (id) found.add(id);
600
+ return;
601
+ }
602
+ for (const child of childrenOf(node)) walk(child, node);
603
+ };
604
+ for (const node of nodes) walk(node);
605
+ return found;
606
+ }
607
+ function createCodeHighlighter(options = {}) {
608
+ const renderer = P({
609
+ languages: createRegistry(),
610
+ on_unknown_language: "plain",
611
+ inline: "tailing-curly-colon",
612
+ line_numbers: options.lineNumbers ?? false
613
+ });
614
+ const pre = async ([, attrs, code]) => {
615
+ const source = codeText(code);
616
+ const name = fenceLanguage(attrs);
617
+ const id = resolveLanguage(name);
618
+ if (id) await loadLanguage(id);
619
+ try {
620
+ return renderer.fence(name || "text", fenceMeta(attrs), source) ?? plainBlock(source);
621
+ } catch (error) {
622
+ return errorBlock(source, error);
623
+ }
624
+ };
625
+ return {
626
+ preload: async (nodes) => {
627
+ await Promise.all([...collectLanguages(nodes)].map((id) => loadLanguage(id)));
628
+ },
629
+ components: {
630
+ pre,
631
+ inlineCode: {
632
+ match: (node) => node[0] === "code" && INLINE_LANGUAGE.test(inlineText(node) ?? ""),
633
+ handler: async (node) => {
634
+ const text = inlineText(node) ?? "";
635
+ const id = resolveLanguage(INLINE_LANGUAGE.exec(text)?.[1]);
636
+ if (id) await loadLanguage(id);
637
+ try {
638
+ const html = renderer.inline_code(text);
639
+ return html ? html.replace("class=\"twinkleplop-inline", "class=\"twinkleplop twinkleplop-inline") : `<code>${escapeHtml(text)}</code>`;
640
+ } catch {
641
+ return `<code>${escapeHtml(text)}</code>`;
642
+ }
643
+ }
644
+ }
645
+ }
646
+ };
647
+ }
648
+ //#endregion
649
+ //#region src/markdown.ts
650
+ function scan(nodes, transformLink) {
651
+ const result = {
652
+ features: {
653
+ math: false,
654
+ mermaid: false
655
+ },
656
+ firstHeading: void 0
657
+ };
658
+ const walk = (node) => {
659
+ if (!isElement(node)) return;
660
+ const [tag, attrs] = node;
661
+ if (tag === "math") result.features.math = true;
662
+ else if (tag === "mermaid") result.features.mermaid = true;
663
+ else if (tag === "h1") result.firstHeading ??= node;
664
+ else if (tag === "a" && transformLink && typeof attrs.href === "string") attrs.href = transformLink(attrs.href);
665
+ for (const child of childrenOf(node)) walk(child);
666
+ };
667
+ for (const node of nodes) walk(node);
668
+ return result;
669
+ }
670
+ function stringOrUndefined(value) {
671
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
672
+ }
673
+ function createMarkdownRenderer(options = {}) {
674
+ const parse = createMarkdownParser({ plugins: [
675
+ toc({
676
+ depth: 2,
677
+ searchDepth: 3
678
+ }),
679
+ footnotes(),
680
+ emoji(),
681
+ math(),
682
+ mermaid(),
683
+ ...options.plugins ?? []
684
+ ] });
685
+ const highlighter = createCodeHighlighter({ lineNumbers: options.lineNumbers });
686
+ const components = {
687
+ ...highlighter.components,
688
+ ...createComponents(),
689
+ ...options.components
690
+ };
691
+ return async (source, renderOptions = {}) => {
692
+ const doc = await parse(source);
693
+ const transformLink = renderOptions.transformLink ?? options.transformLink;
694
+ const { features, firstHeading } = scan(doc.nodes, transformLink);
695
+ await Promise.all([highlighter.preload(doc.nodes), preloadFeatures(features)]);
696
+ const html = await renderHtmlFromDocument(doc, { components });
697
+ const frontmatter = doc.frontmatter ?? {};
698
+ const meta = doc.meta ?? {};
699
+ return {
700
+ html,
701
+ title: stringOrUndefined(frontmatter.title) ?? stringOrUndefined(firstHeading && textContent(firstHeading)),
702
+ description: stringOrUndefined(frontmatter.description),
703
+ frontmatter,
704
+ toc: meta.toc?.links ?? [],
705
+ features
706
+ };
707
+ };
708
+ }
709
+ //#endregion
710
+ export { collectLanguages as n, createCodeHighlighter as r, createMarkdownRenderer as t };
@@ -0,0 +1,2 @@
1
+ import { t as createMarkdownRenderer } from "./markdown-BqKed1Vq.mjs";
2
+ export { createMarkdownRenderer };