@leadertechie/md2html 0.1.0-alpha.4 → 0.1.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,869 @@
1
- export * from './types.js';
2
- export * from './parser.js';
3
- export * from './renderer.js';
4
- export * from './lit-renderer.js';
5
- export * from './pipeline.js';
6
- export { LitRenderer as HTMLRenderer } from './lit-renderer.js';
1
+ import { marked } from "marked";
2
+ class MarkdownParser {
3
+ constructor(options) {
4
+ this.imagePathPrefix = options?.imagePathPrefix || "";
5
+ this.imageBaseUrl = options?.imageBaseUrl || "";
6
+ }
7
+ processImagePath(src) {
8
+ if (src.startsWith("http") || src.startsWith("/")) {
9
+ return src;
10
+ }
11
+ let path = this.imagePathPrefix ? `${this.imagePathPrefix}${src}` : src;
12
+ if (this.imageBaseUrl && !path.startsWith("http")) {
13
+ path = `${this.imageBaseUrl}${path}`;
14
+ }
15
+ return path;
16
+ }
17
+ processInlineFormatting(text) {
18
+ return text.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/\*(.+?)\*/g, "<em>$1</em>");
19
+ }
20
+ parseTokens(tokens) {
21
+ const nodes = [];
22
+ for (const token of tokens) {
23
+ const node = this.parseToken(token);
24
+ if (node) {
25
+ nodes.push(node);
26
+ }
27
+ }
28
+ return nodes;
29
+ }
30
+ parseToken(token) {
31
+ switch (token.type) {
32
+ case "heading":
33
+ return {
34
+ type: "heading",
35
+ content: token.text,
36
+ attributes: { level: String(token.depth) }
37
+ };
38
+ case "paragraph":
39
+ const tokens = token.tokens || [];
40
+ const hasInlineImage = tokens.some((t2) => t2.type === "image");
41
+ if (hasInlineImage) {
42
+ const children = tokens.map((t2) => {
43
+ if (t2.type === "image") {
44
+ return {
45
+ type: "image",
46
+ src: this.processImagePath(t2.href),
47
+ alt: t2.text || ""
48
+ };
49
+ }
50
+ return {
51
+ type: "text",
52
+ content: this.processInlineFormatting(t2.text || "")
53
+ };
54
+ });
55
+ return {
56
+ type: "paragraph",
57
+ children
58
+ };
59
+ }
60
+ return {
61
+ type: "paragraph",
62
+ content: this.processInlineFormatting(token.text)
63
+ };
64
+ case "list":
65
+ return {
66
+ type: "list",
67
+ ordered: token.ordered,
68
+ children: token.items.map((item) => ({
69
+ type: "list-item",
70
+ content: this.processInlineFormatting(item.text)
71
+ }))
72
+ };
73
+ case "image":
74
+ return {
75
+ type: "image",
76
+ src: this.processImagePath(token.href),
77
+ alt: token.title || ""
78
+ };
79
+ case "code":
80
+ return {
81
+ type: "code",
82
+ content: token.text,
83
+ attributes: { lang: token.lang || "" }
84
+ };
85
+ case "hr":
86
+ return { type: "container", attributes: { tag: "hr" } };
87
+ case "blockquote":
88
+ return {
89
+ type: "container",
90
+ attributes: { tag: "blockquote" },
91
+ children: this.parseTokens(token.tokens || [])
92
+ };
93
+ case "html":
94
+ return { type: "container", content: token.raw };
95
+ default:
96
+ return null;
97
+ }
98
+ }
99
+ parse(markdown, options) {
100
+ const parseOptions = {
101
+ gfm: options?.gfm ?? true,
102
+ breaks: options?.breaks ?? false,
103
+ pedantic: options?.pedantic ?? false
104
+ };
105
+ const tokens = marked.lexer(markdown, parseOptions);
106
+ const content = this.parseTokens(tokens);
107
+ return {
108
+ title: "",
109
+ content
110
+ };
111
+ }
112
+ parseToNodes(markdown, options) {
113
+ return this.parse(markdown, options).content;
114
+ }
115
+ }
116
+ class HTMLRenderer {
117
+ constructor(config = {}) {
118
+ this.config = {
119
+ classPrefix: config.classPrefix || "",
120
+ customCSS: config.customCSS || "",
121
+ addHeadingIds: config.addHeadingIds ?? false
122
+ };
123
+ }
124
+ hasClassConfig() {
125
+ return this.config.classPrefix !== "" || this.config.addHeadingIds;
126
+ }
127
+ getClass(baseClass, nodeClass) {
128
+ if (!this.hasClassConfig()) {
129
+ return nodeClass || "";
130
+ }
131
+ const prefix = this.config.classPrefix;
132
+ const classes = [prefix ? `${prefix}${baseClass}` : baseClass];
133
+ if (nodeClass) classes.push(nodeClass);
134
+ return classes.join(" ");
135
+ }
136
+ generateHeadingId(content) {
137
+ if (!content) return "";
138
+ return content.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
139
+ }
140
+ renderWithClass(tag, content, baseClass, nodeClass, extraAttrs) {
141
+ const classAttr = this.hasClassConfig() && baseClass ? ` class="${this.getClass(baseClass, nodeClass)}"` : "";
142
+ return `<${tag}${classAttr}${extraAttrs || ""}>${content}</${tag}>`;
143
+ }
144
+ renderNode(node) {
145
+ switch (node.type) {
146
+ case "heading":
147
+ const level = node.attributes?.level || "2";
148
+ const headingId = this.config.addHeadingIds ? ` id="${this.generateHeadingId(node.content)}"` : "";
149
+ if (!this.hasClassConfig()) {
150
+ return `<h${level}${headingId}>${node.content || ""}</h${level}>`;
151
+ }
152
+ return `<h${level}${headingId} class="${this.getClass("heading")}">${node.content || ""}</h${level}>`;
153
+ case "paragraph":
154
+ if (node.children) {
155
+ const childrenHtml = node.children.map((child) => this.renderNode(child)).join("");
156
+ return this.renderWithClass("p", childrenHtml, "paragraph");
157
+ }
158
+ return this.renderWithClass("p", node.content || "", "paragraph");
159
+ case "list":
160
+ const tag = node.ordered ? "ol" : "ul";
161
+ const items = node.children?.map((child) => this.renderNode(child)).join("") || "";
162
+ return this.renderWithClass(tag, items, "list");
163
+ case "list-item":
164
+ return this.renderWithClass("li", node.content || "", "list-item");
165
+ case "image":
166
+ const src = node.src || node.attributes?.src || "";
167
+ const alt = node.alt || node.attributes?.alt || "";
168
+ const classStr = this.getClass("image", node.className || void 0);
169
+ return `<img src="${src}" alt="${alt}"${classStr ? ` class="${classStr}"` : ""}>`;
170
+ case "code":
171
+ const codeClass = this.hasClassConfig() ? ` class="${this.getClass("code")} language-${node.attributes?.lang || ""}"` : ` class="language-${node.attributes?.lang || ""}"`;
172
+ return `<pre><code${codeClass}>${node.content || ""}</code></pre>`;
173
+ case "container":
174
+ if (node.attributes?.tag === "hr") return "<hr>";
175
+ if (node.attributes?.tag === "blockquote") {
176
+ const children = node.children?.map((child) => this.renderNode(child)).join("") || "";
177
+ return this.renderWithClass("blockquote", children, "blockquote");
178
+ }
179
+ const containerChildren = node.children?.map((child) => this.renderNode(child)).join("") || "";
180
+ return this.renderWithClass("div", containerChildren, "container", node.className || void 0);
181
+ case "strong":
182
+ return `<strong>${node.content || ""}</strong>`;
183
+ case "emphasis":
184
+ return `<em>${node.content || ""}</em>`;
185
+ case "text":
186
+ default:
187
+ return node.content || "";
188
+ }
189
+ }
190
+ renderNodes(nodes) {
191
+ if (!nodes || nodes.length === 0) {
192
+ return "";
193
+ }
194
+ return nodes.map((node) => this.renderNode(node)).join("\n");
195
+ }
196
+ renderToHTMLString(nodes) {
197
+ return this.renderNodes(nodes);
198
+ }
199
+ render(markdown) {
200
+ return markdown;
201
+ }
202
+ getCustomCSS() {
203
+ return this.config.customCSS;
204
+ }
205
+ }
206
+ const t$2 = globalThis, e$4 = t$2.ShadowRoot && (void 0 === t$2.ShadyCSS || t$2.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, s$2 = /* @__PURE__ */ Symbol(), o$4 = /* @__PURE__ */ new WeakMap();
207
+ let n$2 = class n {
208
+ constructor(t2, e2, o2) {
209
+ if (this._$cssResult$ = true, o2 !== s$2) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
210
+ this.cssText = t2, this.t = e2;
211
+ }
212
+ get styleSheet() {
213
+ let t2 = this.o;
214
+ const s2 = this.t;
215
+ if (e$4 && void 0 === t2) {
216
+ const e2 = void 0 !== s2 && 1 === s2.length;
217
+ e2 && (t2 = o$4.get(s2)), void 0 === t2 && ((this.o = t2 = new CSSStyleSheet()).replaceSync(this.cssText), e2 && o$4.set(s2, t2));
218
+ }
219
+ return t2;
220
+ }
221
+ toString() {
222
+ return this.cssText;
223
+ }
224
+ };
225
+ const r$2 = (t2) => new n$2("string" == typeof t2 ? t2 : t2 + "", void 0, s$2), S$1 = (s2, o2) => {
226
+ if (e$4) s2.adoptedStyleSheets = o2.map((t2) => t2 instanceof CSSStyleSheet ? t2 : t2.styleSheet);
227
+ else for (const e2 of o2) {
228
+ const o3 = document.createElement("style"), n3 = t$2.litNonce;
229
+ void 0 !== n3 && o3.setAttribute("nonce", n3), o3.textContent = e2.cssText, s2.appendChild(o3);
230
+ }
231
+ }, c$2 = e$4 ? (t2) => t2 : (t2) => t2 instanceof CSSStyleSheet ? ((t3) => {
232
+ let e2 = "";
233
+ for (const s2 of t3.cssRules) e2 += s2.cssText;
234
+ return r$2(e2);
235
+ })(t2) : t2;
236
+ const { is: i$3, defineProperty: e$3, getOwnPropertyDescriptor: h$1, getOwnPropertyNames: r$1, getOwnPropertySymbols: o$3, getPrototypeOf: n$1 } = Object, a$1 = globalThis, c$1 = a$1.trustedTypes, l$1 = c$1 ? c$1.emptyScript : "", p$1 = a$1.reactiveElementPolyfillSupport, d$1 = (t2, s2) => t2, u$1 = { toAttribute(t2, s2) {
237
+ switch (s2) {
238
+ case Boolean:
239
+ t2 = t2 ? l$1 : null;
240
+ break;
241
+ case Object:
242
+ case Array:
243
+ t2 = null == t2 ? t2 : JSON.stringify(t2);
244
+ }
245
+ return t2;
246
+ }, fromAttribute(t2, s2) {
247
+ let i3 = t2;
248
+ switch (s2) {
249
+ case Boolean:
250
+ i3 = null !== t2;
251
+ break;
252
+ case Number:
253
+ i3 = null === t2 ? null : Number(t2);
254
+ break;
255
+ case Object:
256
+ case Array:
257
+ try {
258
+ i3 = JSON.parse(t2);
259
+ } catch (t3) {
260
+ i3 = null;
261
+ }
262
+ }
263
+ return i3;
264
+ } }, f$1 = (t2, s2) => !i$3(t2, s2), b$1 = { attribute: true, type: String, converter: u$1, reflect: false, useDefault: false, hasChanged: f$1 };
265
+ Symbol.metadata ??= /* @__PURE__ */ Symbol("metadata"), a$1.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
266
+ let y$1 = class y extends HTMLElement {
267
+ static addInitializer(t2) {
268
+ this._$Ei(), (this.l ??= []).push(t2);
269
+ }
270
+ static get observedAttributes() {
271
+ return this.finalize(), this._$Eh && [...this._$Eh.keys()];
272
+ }
273
+ static createProperty(t2, s2 = b$1) {
274
+ if (s2.state && (s2.attribute = false), this._$Ei(), this.prototype.hasOwnProperty(t2) && ((s2 = Object.create(s2)).wrapped = true), this.elementProperties.set(t2, s2), !s2.noAccessor) {
275
+ const i3 = /* @__PURE__ */ Symbol(), h2 = this.getPropertyDescriptor(t2, i3, s2);
276
+ void 0 !== h2 && e$3(this.prototype, t2, h2);
277
+ }
278
+ }
279
+ static getPropertyDescriptor(t2, s2, i3) {
280
+ const { get: e2, set: r2 } = h$1(this.prototype, t2) ?? { get() {
281
+ return this[s2];
282
+ }, set(t3) {
283
+ this[s2] = t3;
284
+ } };
285
+ return { get: e2, set(s3) {
286
+ const h2 = e2?.call(this);
287
+ r2?.call(this, s3), this.requestUpdate(t2, h2, i3);
288
+ }, configurable: true, enumerable: true };
289
+ }
290
+ static getPropertyOptions(t2) {
291
+ return this.elementProperties.get(t2) ?? b$1;
292
+ }
293
+ static _$Ei() {
294
+ if (this.hasOwnProperty(d$1("elementProperties"))) return;
295
+ const t2 = n$1(this);
296
+ t2.finalize(), void 0 !== t2.l && (this.l = [...t2.l]), this.elementProperties = new Map(t2.elementProperties);
297
+ }
298
+ static finalize() {
299
+ if (this.hasOwnProperty(d$1("finalized"))) return;
300
+ if (this.finalized = true, this._$Ei(), this.hasOwnProperty(d$1("properties"))) {
301
+ const t3 = this.properties, s2 = [...r$1(t3), ...o$3(t3)];
302
+ for (const i3 of s2) this.createProperty(i3, t3[i3]);
303
+ }
304
+ const t2 = this[Symbol.metadata];
305
+ if (null !== t2) {
306
+ const s2 = litPropertyMetadata.get(t2);
307
+ if (void 0 !== s2) for (const [t3, i3] of s2) this.elementProperties.set(t3, i3);
308
+ }
309
+ this._$Eh = /* @__PURE__ */ new Map();
310
+ for (const [t3, s2] of this.elementProperties) {
311
+ const i3 = this._$Eu(t3, s2);
312
+ void 0 !== i3 && this._$Eh.set(i3, t3);
313
+ }
314
+ this.elementStyles = this.finalizeStyles(this.styles);
315
+ }
316
+ static finalizeStyles(s2) {
317
+ const i3 = [];
318
+ if (Array.isArray(s2)) {
319
+ const e2 = new Set(s2.flat(1 / 0).reverse());
320
+ for (const s3 of e2) i3.unshift(c$2(s3));
321
+ } else void 0 !== s2 && i3.push(c$2(s2));
322
+ return i3;
323
+ }
324
+ static _$Eu(t2, s2) {
325
+ const i3 = s2.attribute;
326
+ return false === i3 ? void 0 : "string" == typeof i3 ? i3 : "string" == typeof t2 ? t2.toLowerCase() : void 0;
327
+ }
328
+ constructor() {
329
+ super(), this._$Ep = void 0, this.isUpdatePending = false, this.hasUpdated = false, this._$Em = null, this._$Ev();
330
+ }
331
+ _$Ev() {
332
+ this._$ES = new Promise((t2) => this.enableUpdating = t2), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), this.constructor.l?.forEach((t2) => t2(this));
333
+ }
334
+ addController(t2) {
335
+ (this._$EO ??= /* @__PURE__ */ new Set()).add(t2), void 0 !== this.renderRoot && this.isConnected && t2.hostConnected?.();
336
+ }
337
+ removeController(t2) {
338
+ this._$EO?.delete(t2);
339
+ }
340
+ _$E_() {
341
+ const t2 = /* @__PURE__ */ new Map(), s2 = this.constructor.elementProperties;
342
+ for (const i3 of s2.keys()) this.hasOwnProperty(i3) && (t2.set(i3, this[i3]), delete this[i3]);
343
+ t2.size > 0 && (this._$Ep = t2);
344
+ }
345
+ createRenderRoot() {
346
+ const t2 = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
347
+ return S$1(t2, this.constructor.elementStyles), t2;
348
+ }
349
+ connectedCallback() {
350
+ this.renderRoot ??= this.createRenderRoot(), this.enableUpdating(true), this._$EO?.forEach((t2) => t2.hostConnected?.());
351
+ }
352
+ enableUpdating(t2) {
353
+ }
354
+ disconnectedCallback() {
355
+ this._$EO?.forEach((t2) => t2.hostDisconnected?.());
356
+ }
357
+ attributeChangedCallback(t2, s2, i3) {
358
+ this._$AK(t2, i3);
359
+ }
360
+ _$ET(t2, s2) {
361
+ const i3 = this.constructor.elementProperties.get(t2), e2 = this.constructor._$Eu(t2, i3);
362
+ if (void 0 !== e2 && true === i3.reflect) {
363
+ const h2 = (void 0 !== i3.converter?.toAttribute ? i3.converter : u$1).toAttribute(s2, i3.type);
364
+ this._$Em = t2, null == h2 ? this.removeAttribute(e2) : this.setAttribute(e2, h2), this._$Em = null;
365
+ }
366
+ }
367
+ _$AK(t2, s2) {
368
+ const i3 = this.constructor, e2 = i3._$Eh.get(t2);
369
+ if (void 0 !== e2 && this._$Em !== e2) {
370
+ const t3 = i3.getPropertyOptions(e2), h2 = "function" == typeof t3.converter ? { fromAttribute: t3.converter } : void 0 !== t3.converter?.fromAttribute ? t3.converter : u$1;
371
+ this._$Em = e2;
372
+ const r2 = h2.fromAttribute(s2, t3.type);
373
+ this[e2] = r2 ?? this._$Ej?.get(e2) ?? r2, this._$Em = null;
374
+ }
375
+ }
376
+ requestUpdate(t2, s2, i3, e2 = false, h2) {
377
+ if (void 0 !== t2) {
378
+ const r2 = this.constructor;
379
+ if (false === e2 && (h2 = this[t2]), i3 ??= r2.getPropertyOptions(t2), !((i3.hasChanged ?? f$1)(h2, s2) || i3.useDefault && i3.reflect && h2 === this._$Ej?.get(t2) && !this.hasAttribute(r2._$Eu(t2, i3)))) return;
380
+ this.C(t2, s2, i3);
381
+ }
382
+ false === this.isUpdatePending && (this._$ES = this._$EP());
383
+ }
384
+ C(t2, s2, { useDefault: i3, reflect: e2, wrapped: h2 }, r2) {
385
+ i3 && !(this._$Ej ??= /* @__PURE__ */ new Map()).has(t2) && (this._$Ej.set(t2, r2 ?? s2 ?? this[t2]), true !== h2 || void 0 !== r2) || (this._$AL.has(t2) || (this.hasUpdated || i3 || (s2 = void 0), this._$AL.set(t2, s2)), true === e2 && this._$Em !== t2 && (this._$Eq ??= /* @__PURE__ */ new Set()).add(t2));
386
+ }
387
+ async _$EP() {
388
+ this.isUpdatePending = true;
389
+ try {
390
+ await this._$ES;
391
+ } catch (t3) {
392
+ Promise.reject(t3);
393
+ }
394
+ const t2 = this.scheduleUpdate();
395
+ return null != t2 && await t2, !this.isUpdatePending;
396
+ }
397
+ scheduleUpdate() {
398
+ return this.performUpdate();
399
+ }
400
+ performUpdate() {
401
+ if (!this.isUpdatePending) return;
402
+ if (!this.hasUpdated) {
403
+ if (this.renderRoot ??= this.createRenderRoot(), this._$Ep) {
404
+ for (const [t4, s3] of this._$Ep) this[t4] = s3;
405
+ this._$Ep = void 0;
406
+ }
407
+ const t3 = this.constructor.elementProperties;
408
+ if (t3.size > 0) for (const [s3, i3] of t3) {
409
+ const { wrapped: t4 } = i3, e2 = this[s3];
410
+ true !== t4 || this._$AL.has(s3) || void 0 === e2 || this.C(s3, void 0, i3, e2);
411
+ }
412
+ }
413
+ let t2 = false;
414
+ const s2 = this._$AL;
415
+ try {
416
+ t2 = this.shouldUpdate(s2), t2 ? (this.willUpdate(s2), this._$EO?.forEach((t3) => t3.hostUpdate?.()), this.update(s2)) : this._$EM();
417
+ } catch (s3) {
418
+ throw t2 = false, this._$EM(), s3;
419
+ }
420
+ t2 && this._$AE(s2);
421
+ }
422
+ willUpdate(t2) {
423
+ }
424
+ _$AE(t2) {
425
+ this._$EO?.forEach((t3) => t3.hostUpdated?.()), this.hasUpdated || (this.hasUpdated = true, this.firstUpdated(t2)), this.updated(t2);
426
+ }
427
+ _$EM() {
428
+ this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = false;
429
+ }
430
+ get updateComplete() {
431
+ return this.getUpdateComplete();
432
+ }
433
+ getUpdateComplete() {
434
+ return this._$ES;
435
+ }
436
+ shouldUpdate(t2) {
437
+ return true;
438
+ }
439
+ update(t2) {
440
+ this._$Eq &&= this._$Eq.forEach((t3) => this._$ET(t3, this[t3])), this._$EM();
441
+ }
442
+ updated(t2) {
443
+ }
444
+ firstUpdated(t2) {
445
+ }
446
+ };
447
+ y$1.elementStyles = [], y$1.shadowRootOptions = { mode: "open" }, y$1[d$1("elementProperties")] = /* @__PURE__ */ new Map(), y$1[d$1("finalized")] = /* @__PURE__ */ new Map(), p$1?.({ ReactiveElement: y$1 }), (a$1.reactiveElementVersions ??= []).push("2.1.2");
448
+ const t$1 = globalThis, i$2 = (t2) => t2, s$1 = t$1.trustedTypes, e$2 = s$1 ? s$1.createPolicy("lit-html", { createHTML: (t2) => t2 }) : void 0, h = "$lit$", o$2 = `lit$${Math.random().toFixed(9).slice(2)}$`, n2 = "?" + o$2, r = `<${n2}>`, l = document, c = () => l.createComment(""), a = (t2) => null === t2 || "object" != typeof t2 && "function" != typeof t2, u = Array.isArray, d = (t2) => u(t2) || "function" == typeof t2?.[Symbol.iterator], f = "[ \n\f\r]", v = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, _ = /-->/g, m = />/g, p = RegExp(`>|${f}(?:([^\\s"'>=/]+)(${f}*=${f}*(?:[^
449
+ \f\r"'\`<>=]|("|')|))|$)`, "g"), g = /'/g, $ = /"/g, y2 = /^(?:script|style|textarea|title)$/i, x = (t2) => (i3, ...s2) => ({ _$litType$: t2, strings: i3, values: s2 }), b = x(1), E = /* @__PURE__ */ Symbol.for("lit-noChange"), A = /* @__PURE__ */ Symbol.for("lit-nothing"), C = /* @__PURE__ */ new WeakMap(), P = l.createTreeWalker(l, 129);
450
+ function V(t2, i3) {
451
+ if (!u(t2) || !t2.hasOwnProperty("raw")) throw Error("invalid template strings array");
452
+ return void 0 !== e$2 ? e$2.createHTML(i3) : i3;
453
+ }
454
+ const N = (t2, i3) => {
455
+ const s2 = t2.length - 1, e2 = [];
456
+ let n3, l2 = 2 === i3 ? "<svg>" : 3 === i3 ? "<math>" : "", c2 = v;
457
+ for (let i4 = 0; i4 < s2; i4++) {
458
+ const s3 = t2[i4];
459
+ let a2, u2, d2 = -1, f2 = 0;
460
+ for (; f2 < s3.length && (c2.lastIndex = f2, u2 = c2.exec(s3), null !== u2); ) f2 = c2.lastIndex, c2 === v ? "!--" === u2[1] ? c2 = _ : void 0 !== u2[1] ? c2 = m : void 0 !== u2[2] ? (y2.test(u2[2]) && (n3 = RegExp("</" + u2[2], "g")), c2 = p) : void 0 !== u2[3] && (c2 = p) : c2 === p ? ">" === u2[0] ? (c2 = n3 ?? v, d2 = -1) : void 0 === u2[1] ? d2 = -2 : (d2 = c2.lastIndex - u2[2].length, a2 = u2[1], c2 = void 0 === u2[3] ? p : '"' === u2[3] ? $ : g) : c2 === $ || c2 === g ? c2 = p : c2 === _ || c2 === m ? c2 = v : (c2 = p, n3 = void 0);
461
+ const x2 = c2 === p && t2[i4 + 1].startsWith("/>") ? " " : "";
462
+ l2 += c2 === v ? s3 + r : d2 >= 0 ? (e2.push(a2), s3.slice(0, d2) + h + s3.slice(d2) + o$2 + x2) : s3 + o$2 + (-2 === d2 ? i4 : x2);
463
+ }
464
+ return [V(t2, l2 + (t2[s2] || "<?>") + (2 === i3 ? "</svg>" : 3 === i3 ? "</math>" : "")), e2];
465
+ };
466
+ class S {
467
+ constructor({ strings: t2, _$litType$: i3 }, e2) {
468
+ let r2;
469
+ this.parts = [];
470
+ let l2 = 0, a2 = 0;
471
+ const u2 = t2.length - 1, d2 = this.parts, [f2, v2] = N(t2, i3);
472
+ if (this.el = S.createElement(f2, e2), P.currentNode = this.el.content, 2 === i3 || 3 === i3) {
473
+ const t3 = this.el.content.firstChild;
474
+ t3.replaceWith(...t3.childNodes);
475
+ }
476
+ for (; null !== (r2 = P.nextNode()) && d2.length < u2; ) {
477
+ if (1 === r2.nodeType) {
478
+ if (r2.hasAttributes()) for (const t3 of r2.getAttributeNames()) if (t3.endsWith(h)) {
479
+ const i4 = v2[a2++], s2 = r2.getAttribute(t3).split(o$2), e3 = /([.?@])?(.*)/.exec(i4);
480
+ d2.push({ type: 1, index: l2, name: e3[2], strings: s2, ctor: "." === e3[1] ? I : "?" === e3[1] ? L : "@" === e3[1] ? z : H }), r2.removeAttribute(t3);
481
+ } else t3.startsWith(o$2) && (d2.push({ type: 6, index: l2 }), r2.removeAttribute(t3));
482
+ if (y2.test(r2.tagName)) {
483
+ const t3 = r2.textContent.split(o$2), i4 = t3.length - 1;
484
+ if (i4 > 0) {
485
+ r2.textContent = s$1 ? s$1.emptyScript : "";
486
+ for (let s2 = 0; s2 < i4; s2++) r2.append(t3[s2], c()), P.nextNode(), d2.push({ type: 2, index: ++l2 });
487
+ r2.append(t3[i4], c());
488
+ }
489
+ }
490
+ } else if (8 === r2.nodeType) if (r2.data === n2) d2.push({ type: 2, index: l2 });
491
+ else {
492
+ let t3 = -1;
493
+ for (; -1 !== (t3 = r2.data.indexOf(o$2, t3 + 1)); ) d2.push({ type: 7, index: l2 }), t3 += o$2.length - 1;
494
+ }
495
+ l2++;
496
+ }
497
+ }
498
+ static createElement(t2, i3) {
499
+ const s2 = l.createElement("template");
500
+ return s2.innerHTML = t2, s2;
501
+ }
502
+ }
503
+ function M(t2, i3, s2 = t2, e2) {
504
+ if (i3 === E) return i3;
505
+ let h2 = void 0 !== e2 ? s2._$Co?.[e2] : s2._$Cl;
506
+ const o2 = a(i3) ? void 0 : i3._$litDirective$;
507
+ return h2?.constructor !== o2 && (h2?._$AO?.(false), void 0 === o2 ? h2 = void 0 : (h2 = new o2(t2), h2._$AT(t2, s2, e2)), void 0 !== e2 ? (s2._$Co ??= [])[e2] = h2 : s2._$Cl = h2), void 0 !== h2 && (i3 = M(t2, h2._$AS(t2, i3.values), h2, e2)), i3;
508
+ }
509
+ class R {
510
+ constructor(t2, i3) {
511
+ this._$AV = [], this._$AN = void 0, this._$AD = t2, this._$AM = i3;
512
+ }
513
+ get parentNode() {
514
+ return this._$AM.parentNode;
515
+ }
516
+ get _$AU() {
517
+ return this._$AM._$AU;
518
+ }
519
+ u(t2) {
520
+ const { el: { content: i3 }, parts: s2 } = this._$AD, e2 = (t2?.creationScope ?? l).importNode(i3, true);
521
+ P.currentNode = e2;
522
+ let h2 = P.nextNode(), o2 = 0, n3 = 0, r2 = s2[0];
523
+ for (; void 0 !== r2; ) {
524
+ if (o2 === r2.index) {
525
+ let i4;
526
+ 2 === r2.type ? i4 = new k(h2, h2.nextSibling, this, t2) : 1 === r2.type ? i4 = new r2.ctor(h2, r2.name, r2.strings, this, t2) : 6 === r2.type && (i4 = new Z(h2, this, t2)), this._$AV.push(i4), r2 = s2[++n3];
527
+ }
528
+ o2 !== r2?.index && (h2 = P.nextNode(), o2++);
529
+ }
530
+ return P.currentNode = l, e2;
531
+ }
532
+ p(t2) {
533
+ let i3 = 0;
534
+ for (const s2 of this._$AV) void 0 !== s2 && (void 0 !== s2.strings ? (s2._$AI(t2, s2, i3), i3 += s2.strings.length - 2) : s2._$AI(t2[i3])), i3++;
535
+ }
536
+ }
537
+ class k {
538
+ get _$AU() {
539
+ return this._$AM?._$AU ?? this._$Cv;
540
+ }
541
+ constructor(t2, i3, s2, e2) {
542
+ this.type = 2, this._$AH = A, this._$AN = void 0, this._$AA = t2, this._$AB = i3, this._$AM = s2, this.options = e2, this._$Cv = e2?.isConnected ?? true;
543
+ }
544
+ get parentNode() {
545
+ let t2 = this._$AA.parentNode;
546
+ const i3 = this._$AM;
547
+ return void 0 !== i3 && 11 === t2?.nodeType && (t2 = i3.parentNode), t2;
548
+ }
549
+ get startNode() {
550
+ return this._$AA;
551
+ }
552
+ get endNode() {
553
+ return this._$AB;
554
+ }
555
+ _$AI(t2, i3 = this) {
556
+ t2 = M(this, t2, i3), a(t2) ? t2 === A || null == t2 || "" === t2 ? (this._$AH !== A && this._$AR(), this._$AH = A) : t2 !== this._$AH && t2 !== E && this._(t2) : void 0 !== t2._$litType$ ? this.$(t2) : void 0 !== t2.nodeType ? this.T(t2) : d(t2) ? this.k(t2) : this._(t2);
557
+ }
558
+ O(t2) {
559
+ return this._$AA.parentNode.insertBefore(t2, this._$AB);
560
+ }
561
+ T(t2) {
562
+ this._$AH !== t2 && (this._$AR(), this._$AH = this.O(t2));
563
+ }
564
+ _(t2) {
565
+ this._$AH !== A && a(this._$AH) ? this._$AA.nextSibling.data = t2 : this.T(l.createTextNode(t2)), this._$AH = t2;
566
+ }
567
+ $(t2) {
568
+ const { values: i3, _$litType$: s2 } = t2, e2 = "number" == typeof s2 ? this._$AC(t2) : (void 0 === s2.el && (s2.el = S.createElement(V(s2.h, s2.h[0]), this.options)), s2);
569
+ if (this._$AH?._$AD === e2) this._$AH.p(i3);
570
+ else {
571
+ const t3 = new R(e2, this), s3 = t3.u(this.options);
572
+ t3.p(i3), this.T(s3), this._$AH = t3;
573
+ }
574
+ }
575
+ _$AC(t2) {
576
+ let i3 = C.get(t2.strings);
577
+ return void 0 === i3 && C.set(t2.strings, i3 = new S(t2)), i3;
578
+ }
579
+ k(t2) {
580
+ u(this._$AH) || (this._$AH = [], this._$AR());
581
+ const i3 = this._$AH;
582
+ let s2, e2 = 0;
583
+ for (const h2 of t2) e2 === i3.length ? i3.push(s2 = new k(this.O(c()), this.O(c()), this, this.options)) : s2 = i3[e2], s2._$AI(h2), e2++;
584
+ e2 < i3.length && (this._$AR(s2 && s2._$AB.nextSibling, e2), i3.length = e2);
585
+ }
586
+ _$AR(t2 = this._$AA.nextSibling, s2) {
587
+ for (this._$AP?.(false, true, s2); t2 !== this._$AB; ) {
588
+ const s3 = i$2(t2).nextSibling;
589
+ i$2(t2).remove(), t2 = s3;
590
+ }
591
+ }
592
+ setConnected(t2) {
593
+ void 0 === this._$AM && (this._$Cv = t2, this._$AP?.(t2));
594
+ }
595
+ }
596
+ class H {
597
+ get tagName() {
598
+ return this.element.tagName;
599
+ }
600
+ get _$AU() {
601
+ return this._$AM._$AU;
602
+ }
603
+ constructor(t2, i3, s2, e2, h2) {
604
+ this.type = 1, this._$AH = A, this._$AN = void 0, this.element = t2, this.name = i3, this._$AM = e2, this.options = h2, s2.length > 2 || "" !== s2[0] || "" !== s2[1] ? (this._$AH = Array(s2.length - 1).fill(new String()), this.strings = s2) : this._$AH = A;
605
+ }
606
+ _$AI(t2, i3 = this, s2, e2) {
607
+ const h2 = this.strings;
608
+ let o2 = false;
609
+ if (void 0 === h2) t2 = M(this, t2, i3, 0), o2 = !a(t2) || t2 !== this._$AH && t2 !== E, o2 && (this._$AH = t2);
610
+ else {
611
+ const e3 = t2;
612
+ let n3, r2;
613
+ for (t2 = h2[0], n3 = 0; n3 < h2.length - 1; n3++) r2 = M(this, e3[s2 + n3], i3, n3), r2 === E && (r2 = this._$AH[n3]), o2 ||= !a(r2) || r2 !== this._$AH[n3], r2 === A ? t2 = A : t2 !== A && (t2 += (r2 ?? "") + h2[n3 + 1]), this._$AH[n3] = r2;
614
+ }
615
+ o2 && !e2 && this.j(t2);
616
+ }
617
+ j(t2) {
618
+ t2 === A ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t2 ?? "");
619
+ }
620
+ }
621
+ class I extends H {
622
+ constructor() {
623
+ super(...arguments), this.type = 3;
624
+ }
625
+ j(t2) {
626
+ this.element[this.name] = t2 === A ? void 0 : t2;
627
+ }
628
+ }
629
+ class L extends H {
630
+ constructor() {
631
+ super(...arguments), this.type = 4;
632
+ }
633
+ j(t2) {
634
+ this.element.toggleAttribute(this.name, !!t2 && t2 !== A);
635
+ }
636
+ }
637
+ class z extends H {
638
+ constructor(t2, i3, s2, e2, h2) {
639
+ super(t2, i3, s2, e2, h2), this.type = 5;
640
+ }
641
+ _$AI(t2, i3 = this) {
642
+ if ((t2 = M(this, t2, i3, 0) ?? A) === E) return;
643
+ const s2 = this._$AH, e2 = t2 === A && s2 !== A || t2.capture !== s2.capture || t2.once !== s2.once || t2.passive !== s2.passive, h2 = t2 !== A && (s2 === A || e2);
644
+ e2 && this.element.removeEventListener(this.name, this, s2), h2 && this.element.addEventListener(this.name, this, t2), this._$AH = t2;
645
+ }
646
+ handleEvent(t2) {
647
+ "function" == typeof this._$AH ? this._$AH.call(this.options?.host ?? this.element, t2) : this._$AH.handleEvent(t2);
648
+ }
649
+ }
650
+ class Z {
651
+ constructor(t2, i3, s2) {
652
+ this.element = t2, this.type = 6, this._$AN = void 0, this._$AM = i3, this.options = s2;
653
+ }
654
+ get _$AU() {
655
+ return this._$AM._$AU;
656
+ }
657
+ _$AI(t2) {
658
+ M(this, t2);
659
+ }
660
+ }
661
+ const B = t$1.litHtmlPolyfillSupport;
662
+ B?.(S, k), (t$1.litHtmlVersions ??= []).push("3.3.2");
663
+ const D = (t2, i3, s2) => {
664
+ const e2 = s2?.renderBefore ?? i3;
665
+ let h2 = e2._$litPart$;
666
+ if (void 0 === h2) {
667
+ const t3 = s2?.renderBefore ?? null;
668
+ e2._$litPart$ = h2 = new k(i3.insertBefore(c(), t3), t3, void 0, s2 ?? {});
669
+ }
670
+ return h2._$AI(t2), h2;
671
+ };
672
+ const s = globalThis;
673
+ let i$1 = class i extends y$1 {
674
+ constructor() {
675
+ super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
676
+ }
677
+ createRenderRoot() {
678
+ const t2 = super.createRenderRoot();
679
+ return this.renderOptions.renderBefore ??= t2.firstChild, t2;
680
+ }
681
+ update(t2) {
682
+ const r2 = this.render();
683
+ this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t2), this._$Do = D(r2, this.renderRoot, this.renderOptions);
684
+ }
685
+ connectedCallback() {
686
+ super.connectedCallback(), this._$Do?.setConnected(true);
687
+ }
688
+ disconnectedCallback() {
689
+ super.disconnectedCallback(), this._$Do?.setConnected(false);
690
+ }
691
+ render() {
692
+ return E;
693
+ }
694
+ };
695
+ i$1._$litElement$ = true, i$1["finalized"] = true, s.litElementHydrateSupport?.({ LitElement: i$1 });
696
+ const o$1 = s.litElementPolyfillSupport;
697
+ o$1?.({ LitElement: i$1 });
698
+ (s.litElementVersions ??= []).push("4.2.2");
699
+ const t = { CHILD: 2 }, e$1 = (t2) => (...e2) => ({ _$litDirective$: t2, values: e2 });
700
+ class i2 {
701
+ constructor(t2) {
702
+ }
703
+ get _$AU() {
704
+ return this._$AM._$AU;
705
+ }
706
+ _$AT(t2, e2, i3) {
707
+ this._$Ct = t2, this._$AM = e2, this._$Ci = i3;
708
+ }
709
+ _$AS(t2, e2) {
710
+ return this.update(t2, e2);
711
+ }
712
+ update(t2, e2) {
713
+ return this.render(...e2);
714
+ }
715
+ }
716
+ class e extends i2 {
717
+ constructor(i3) {
718
+ if (super(i3), this.it = A, i3.type !== t.CHILD) throw Error(this.constructor.directiveName + "() can only be used in child bindings");
719
+ }
720
+ render(r2) {
721
+ if (r2 === A || null == r2) return this._t = void 0, this.it = r2;
722
+ if (r2 === E) return r2;
723
+ if ("string" != typeof r2) throw Error(this.constructor.directiveName + "() called with a non-string value");
724
+ if (r2 === this.it) return this._t;
725
+ this.it = r2;
726
+ const s2 = [r2];
727
+ return s2.raw = s2, this._t = { _$litType$: this.constructor.resultType, strings: s2, values: [] };
728
+ }
729
+ }
730
+ e.directiveName = "unsafeHTML", e.resultType = 1;
731
+ const o = e$1(e);
732
+ class LitRenderer {
733
+ renderTextNode(node) {
734
+ if (node.type === "image") {
735
+ return b`<img src="${node.src}" alt="${node.alt || ""}" class="inline-image" style="max-width:100%;height:auto;">`;
736
+ }
737
+ return b`${o(node.content || "")}`;
738
+ }
739
+ renderNode(node) {
740
+ switch (node.type) {
741
+ case "heading": {
742
+ const level = node.attributes?.level || "2";
743
+ if (level === "1") return b`<h1>${o(node.content)}</h1>`;
744
+ if (level === "2") return b`<h2>${o(node.content)}</h2>`;
745
+ if (level === "3") return b`<h3>${o(node.content)}</h3>`;
746
+ return b`<h2>${o(node.content)}</h2>`;
747
+ }
748
+ case "paragraph":
749
+ if (node.children) {
750
+ return b`<p>${node.children.map((child) => this.renderTextNode(child))}</p>`;
751
+ }
752
+ return b`<p>${o(node.content)}</p>`;
753
+ case "list":
754
+ return b`<ul>${node.children?.map((child) => this.renderNode(child))}</ul>`;
755
+ case "list-item":
756
+ return b`<li>${o(node.content)}</li>`;
757
+ case "image":
758
+ return b`<img src="${node.src || node.attributes?.src}" alt="${node.alt || node.attributes?.alt || ""}" class="${node.className || ""}" style="max-width:100%;height:auto;">`;
759
+ case "container":
760
+ return b`<div class="${node.className || ""}" style="${node.attributes?.style || ""}">
761
+ ${node.children?.map((child) => this.renderNode(child))}
762
+ </div>`;
763
+ case "code":
764
+ return b`<pre><code class="language-${node.attributes?.lang || ""}">${node.content || ""}</code></pre>`;
765
+ case "text":
766
+ return b`${node.content}`;
767
+ default:
768
+ return b``;
769
+ }
770
+ }
771
+ renderNodes(nodes) {
772
+ if (!nodes || nodes.length === 0) {
773
+ return b``;
774
+ }
775
+ return b`${nodes.map((node) => this.renderNode(node))}`;
776
+ }
777
+ renderToHTMLString(nodes) {
778
+ if (!nodes || nodes.length === 0) {
779
+ return "";
780
+ }
781
+ return nodes.map((node) => this.nodeToHTMLString(node)).join("\n");
782
+ }
783
+ nodeToHTMLString(node) {
784
+ switch (node.type) {
785
+ case "heading":
786
+ const level = node.attributes?.level || "2";
787
+ return `<h${level}>${node.content}</h${level}>`;
788
+ case "paragraph":
789
+ return `<p>${node.content}</p>`;
790
+ case "list":
791
+ const items = node.children?.map((child) => this.nodeToHTMLString(child)).join("") || "";
792
+ return `<ul>${items}</ul>`;
793
+ case "list-item":
794
+ return `<li>${node.content}</li>`;
795
+ case "image":
796
+ return `<img src="${node.attributes?.src}" alt="${node.attributes?.alt}" class="${node.className || ""}">`;
797
+ case "container":
798
+ const childrenHTML = node.children?.map((child) => this.nodeToHTMLString(child)).join("") || "";
799
+ return `<div class="${node.className || ""}">${childrenHTML}</div>`;
800
+ case "text":
801
+ return node.content || "";
802
+ default:
803
+ return "";
804
+ }
805
+ }
806
+ }
807
+ class MarkdownPipeline {
808
+ constructor(config = {}) {
809
+ this.config = {
810
+ imagePathPrefix: config.imagePathPrefix || "",
811
+ imageBaseUrl: config.imageBaseUrl || "",
812
+ parseOptions: {
813
+ gfm: config.parseOptions?.gfm ?? true,
814
+ breaks: config.parseOptions?.breaks ?? false,
815
+ pedantic: config.parseOptions?.pedantic ?? false
816
+ },
817
+ styleOptions: {
818
+ classPrefix: config.styleOptions?.classPrefix || "",
819
+ customCSS: config.styleOptions?.customCSS || "",
820
+ addHeadingIds: config.styleOptions?.addHeadingIds ?? false
821
+ }
822
+ };
823
+ this.parser = new MarkdownParser({
824
+ imagePathPrefix: this.config.imagePathPrefix,
825
+ imageBaseUrl: this.config.imageBaseUrl
826
+ });
827
+ this.renderer = new HTMLRenderer(this.config.styleOptions);
828
+ }
829
+ parse(markdown) {
830
+ return this.parser.parseToNodes(markdown, this.config.parseOptions);
831
+ }
832
+ parseWithMetadata(markdown) {
833
+ return this.parser.parse(markdown, this.config.parseOptions);
834
+ }
835
+ render(nodes) {
836
+ return this.renderer.renderNodes(nodes);
837
+ }
838
+ renderMarkdown(markdown) {
839
+ const nodes = this.parse(markdown);
840
+ return this.render(nodes);
841
+ }
842
+ renderPage(title, nodes, options) {
843
+ const html = this.render(nodes);
844
+ return `<!DOCTYPE html>
845
+ <html lang="${options?.lang || "en"}">
846
+ <head>
847
+ <meta charset="${options?.charset || "UTF-8"}">
848
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
849
+ <title>${title}</title>
850
+ </head>
851
+ <body>
852
+ ${html}
853
+ </body>
854
+ </html>`;
855
+ }
856
+ getConfig() {
857
+ return { ...this.config };
858
+ }
859
+ getCustomCSS() {
860
+ return this.renderer.getCustomCSS();
861
+ }
862
+ }
863
+ export {
864
+ LitRenderer as HTMLRenderer,
865
+ LitRenderer,
866
+ MarkdownParser,
867
+ MarkdownPipeline
868
+ };
869
+ //# sourceMappingURL=index.js.map