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.
 
 
 

17 lines
460 B

import MarkdownIt from 'markdown-it'
import DOMPurify from 'isomorphic-dompurify'
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(src), { USE_PROFILES: { html: true } })
}