import MarkdownIt from 'markdown-it' import DOMPurify from 'isomorphic-dompurify' import { stripFrontMatter } from './markdown-front-matter' const md = new MarkdownIt({ html: false, linkify: true, typographer: false, breaks: true, }) /** 将 Markdown 转为可安全用于 `v-html` 的 HTML(禁用源码中的原始 HTML)。 */ export function renderSafeMarkdown(src: string): string { if (!src.trim()) { return '' } return DOMPurify.sanitize(md.render(stripFrontMatter(src)), { USE_PROFILES: { html: true } }) }