'use strict'; const unified = require('unified'); const remarkGfm = require('remark-gfm'); const remarkParse = require('remark-parse'); const remarkBreaks = require('remark-breaks'); const remarkMath = require('remark-math'); const remarkRehype = require('remark-rehype'); const rehypeKatex = require('rehype-katex'); const rehypeStringify = require('rehype-stringify'); const unistUtilVisit = require('unist-util-visit'); const remarkDolanRaw = () => { return (tree) => { unistUtilVisit.visit(tree, "code", (node) => { if (node.lang === "raw") { node.type = "html"; } }); }; }; function getRenderer(options = {}) { const renderer = unified.unified().use(remarkParse).use(remarkBreaks).use(remarkGfm).use(remarkMath).use(remarkDolanRaw); options.modifyRemark?.(renderer); renderer.use(remarkRehype, { allowDangerousHtml: true }).use(rehypeKatex); options.modifyRehype?.(renderer); renderer.use(rehypeStringify, { allowDangerousHtml: true }); return renderer; } const defaultRenderer = getRenderer(); async function renderMarkdown(md) { return String(await defaultRenderer.process(md)); } function renderMarkdownSync(md) { return String(defaultRenderer.processSync(md)); } exports.defaultRenderer = defaultRenderer; exports.getRenderer = getRenderer; exports.renderMarkdown = renderMarkdown; exports.renderMarkdownSync = renderMarkdownSync;