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.
22 lines
641 B
22 lines
641 B
import { marked } from 'marked'
|
|
import { markedHighlight } from 'marked-highlight'
|
|
import hljs from 'highlight.js'
|
|
import DOMPurify from 'dompurify'
|
|
import 'highlight.js/styles/github-dark.css'
|
|
|
|
marked.use(
|
|
markedHighlight({
|
|
langPrefix: 'hljs language-',
|
|
highlight(code: string, lang: string) {
|
|
if (lang && hljs.getLanguage(lang)) {
|
|
return hljs.highlight(code, { language: lang }).value
|
|
}
|
|
return hljs.highlightAuto(code).value
|
|
}
|
|
})
|
|
)
|
|
|
|
export function renderMarkdown(content: string): string {
|
|
const rawHtml = marked.parse(content, { async: false }) as string
|
|
return DOMPurify.sanitize(rawHtml)
|
|
}
|