/** * Markdown to PDF renderer for document export. * * Converts markdown content to styled HTML via `marked`, then renders * the HTML to a PDF buffer using Playwright headless Chromium. * The HTML template uses print-friendly styling that matches the * document editor typography. */ import { marked } from "marked"; import { ensureChromiumHeadlessShell, importPlaywright, } from "../../tools/browser/runtime-check.js"; // --------------------------------------------------------------------------- // Print template // --------------------------------------------------------------------------- const FONT_STACK = `"DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`; function wrapInPrintTemplate(innerHtml: string): string { return `
${innerHtml} `; } // --------------------------------------------------------------------------- // Public API // --------------------------------------------------------------------------- /** * Convert a markdown string to a PDF buffer. * * Parses markdown to HTML via `marked`, wraps it in a print-friendly * template, then renders to PDF using Playwright headless Chromium. * The browser is always closed in a `finally` block. */ export async function renderMarkdownToPDF( title: string, markdown: string, ): Promise