You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

18 lines
537 B

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 } })
}