Files
jinshen-website/app/utils/markdown.ts

22 lines
438 B
TypeScript

import MarkdownIt from 'markdown-it';
const md = new MarkdownIt({
html: true,
linkify: true,
typographer: true,
breaks: true,
})
export function renderMarkdown(content: string): string {
const dirtyHtml = md.render(content);
if (typeof window !== 'undefined') {
import('dompurify').then((DOMPurify => {
return DOMPurify.default.sanitize(dirtyHtml)
}))
}
return dirtyHtml
}