/** * -------------------------------------------------------------------- * docmd : the zero-config documentation engine. * * @package @docmd/core (and ecosystem) * @website https://docmd.io * @repository https://github.com/docmd-io/docmd * @license MIT * @copyright Copyright (c) 2025-present docmd.io * * [docmd-source] - Please do not remove this header. * -------------------------------------------------------------------- */ import { createMarkdownProcessor, processContent } from '@docmd/parser/dist/markdown-processor.js'; import { markdownSetup as mathMarkdownSetup } from '@docmd/plugin-math'; import { markdownSetup as mermaidMarkdownSetup } from '@docmd/plugin-mermaid'; // @ts-expect-error virtual module import templates from 'virtual:docmd-templates'; // Expose the compile function to the window.docmd global async function compile(markdown: string, config: any = {}) { const defaults: any = { siteTitle: 'Live Preview', theme: { appearance: 'light', name: 'default', codeHighlight: true }, layout: { spa: false }, ...config }; // 1. Process Markdown with Plugin Support const md = createMarkdownProcessor(defaults, (parser) => { // Math (KaTeX) mathMarkdownSetup(parser); // Mermaid (container ::: mermaid and fence ```mermaid) mermaidMarkdownSetup(parser); }); const result = processContent(markdown, md, defaults); if (!result) return '

Error parsing markdown

'; // Since we are in the browser, we assume assets are served at ./assets/ const assetsRoot = './assets'; const appearance = defaults.theme.appearance || 'light'; // Theme init script — handles DOCMD_APPEARANCE + safe localStorage const themeInitScript = templates['partials/theme-init.js'] || ''; // KaTeX stylesheet (theme tokens come from docmd-main.css) const katexCss = ``; // Mermaid init — runs in the preview iframe, picks up the current theme const mermaidScript = ` `; // Minimal interactivity for the preview iframe. docmd-main.js is not // loaded here (we stripped the chrome), so tab switching has to be // wired here. Collapsibles use native
, so they need no JS. const interactivityScript = ` ${katexCss} ${result.htmlContent} ${interactivityScript} ${mermaidScript} `; } import { highlightDocmd } from './docmd-highlighter.js'; export { compile, highlightDocmd as highlight };