diff --git a/frontend/src/utils/markdown.ts b/frontend/src/utils/markdown.ts new file mode 100644 index 0000000..f799b42 --- /dev/null +++ b/frontend/src/utils/markdown.ts @@ -0,0 +1,25 @@ +import MarkdownIt from 'markdown-it' +import hljs from 'highlight.js' + +const md = new MarkdownIt({ + html: false, + linkify: false, + breaks: true, + typographer: true, + quotes: '“”‘’', + highlight: (str: any, lang: any): string => { + if (lang && hljs.getLanguage(lang)) { + try { + return `
+` + } catch (e) { + console.error(e) + } + } + + return '${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}+
' + md.utils.escapeHtml(str) + ''
+ },
+})
+
+export default md