/**
 * Markdown → HTML renderer used by the install server.
 *
 * Built on `marked` with GFM enabled and a slugged-heading hook so internal
 * `#anchor` links work the same as on the marketing SPA (which already uses
 * `rehype-slug` + `rehype-autolink-headings`).
 */
import { Marked } from "marked";
function toSlug(text) {
    return text
        .toLowerCase()
        .replace(/[^a-z0-9\s-]/g, "")
        .replace(/\s+/g, "-")
        .replace(/-+/g, "-")
        .replace(/^-|-$/g, "");
}
function createMarked() {
    const m = new Marked({
        gfm: true,
        breaks: false,
    });
    m.use({
        renderer: {
            heading(token) {
                // `this` here is the Renderer instance from marked.
                const text = this.parser.parseInline(token.tokens);
                const plain = text.replace(/<[^>]+>/g, "");
                const slug = toSlug(plain);
                const id = slug || `heading-${token.depth}`;
                return `<h${token.depth} id="${id}"><a class="doc-anchor" href="#${id}" aria-hidden="true">#</a> ${text}</h${token.depth}>\n`;
            },
        },
    });
    return m;
}
const marked = createMarked();
/**
 * Render markdown body (no front-matter) to HTML. MDX-only constructs are
 * NOT supported here; pages flagged `interactive: true` should fall back to a
 * link to the canonical SPA URL when served from the install.
 */
export function renderMarkdownBodyToHtml(body) {
    return marked.parse(body, { async: false });
}
export function _docHeadingSlug(text) {
    return toSlug(text);
}
//# sourceMappingURL=render_html.js.map