import { n as __exportAll } from "./chunk-B-1-B7_t.js";
import { computed, createElementBlock, defineComponent, normalizeClass, openBlock } from "vue";
//#region src/components/compositions/elements/display/MarkdownDisplay.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["innerHTML"];
var MarkdownDisplay_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "MarkdownDisplay",
	props: {
		value: {},
		classList: {}
	},
	setup(__props) {
		/**
		* Props-driven markdown display.
		*
		* Renders a tiny, dependency-free markdown subset (headings, bold,
		* italic, code, fenced code, links, lists). Output is sanitised by
		* escaping HTML in the raw source before transformation. For
		* real-world rich markdown, swap in `marked` or `markdown-it`.
		*/
		const props = __props;
		const content = computed(() => {
			if (props.value === void 0 || props.value === null) return "";
			return String(props.value);
		});
		const rootClass = computed(() => {
			const cl = props.classList;
			if (!cl) return "";
			return Array.isArray(cl) ? cl.join(" ") : cl;
		});
		function escapeHtml(input) {
			return input.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
		}
		function renderMarkdown(src) {
			if (!src) return "";
			let text = escapeHtml(src);
			text = text.replace(/```([\s\S]*?)```/g, (_, code) => {
				return `<pre class="bg-muted rounded p-3 overflow-auto"><code class="font-mono text-sm">${code.trim()}</code></pre>`;
			});
			text = text.replace(/`([^`\n]+)`/g, "<code class=\"font-mono bg-muted px-1 rounded text-sm\">$1</code>");
			text = text.replace(/^######\s+(.+)$/gm, "<h6 class=\"text-base font-semibold\">$1</h6>");
			text = text.replace(/^#####\s+(.+)$/gm, "<h5 class=\"text-lg font-semibold\">$1</h5>");
			text = text.replace(/^####\s+(.+)$/gm, "<h4 class=\"text-xl font-semibold\">$1</h4>");
			text = text.replace(/^###\s+(.+)$/gm, "<h3 class=\"text-2xl font-semibold\">$1</h3>");
			text = text.replace(/^##\s+(.+)$/gm, "<h2 class=\"text-3xl font-semibold\">$1</h2>");
			text = text.replace(/^#\s+(.+)$/gm, "<h1 class=\"text-4xl font-bold\">$1</h1>");
			text = text.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
			text = text.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g, "$1<em>$2</em>");
			text = text.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, "<a href=\"$2\" class=\"text-primary underline\" target=\"_blank\" rel=\"noreferrer\">$1</a>");
			text = text.replace(/^\s*[-*+]\s+(.+)$/gm, "<li>$1</li>");
			text = text.replace(/^\s*\d+\.\s+(.+)$/gm, "<li>$1</li>");
			text = text.replace(/(<li>[\s\S]*?<\/li>)(?!\s*<li>)/g, "<ul class=\"list-disc pl-6\">$1</ul>");
			text = text.split(/\n{2,}/).map((block) => {
				if (/^<(h\d|ul|ol|pre|blockquote|li)/.test(block.trim())) return block;
				const trimmed = block.trim();
				return trimmed ? `<p class="leading-7">${trimmed.replace(/\n/g, "<br />")}</p>` : "";
			}).join("\n");
			return text;
		}
		const html = computed(() => renderMarkdown(content.value));
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock("div", {
				class: normalizeClass(["prose prose-sm max-w-none", rootClass.value]),
				"data-testid": "markdown-display",
				innerHTML: html.value
			}, null, 10, _hoisted_1);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/display/MarkdownDisplay.vue
var MarkdownDisplay_exports = /* @__PURE__ */ __exportAll({ default: () => MarkdownDisplay_default });
var MarkdownDisplay_default = MarkdownDisplay_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { MarkdownDisplay_exports as n, MarkdownDisplay_default as t };

//# sourceMappingURL=MarkdownDisplay-D0Hu97Hl.js.map