From fa4205fbad9711780409ddfcf062fc8fe5f98669 Mon Sep 17 00:00:00 2001 From: inter Date: Mon, 8 Sep 2025 16:37:41 +0800 Subject: [PATCH] Add File --- frontend/src/utils/markdown.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 frontend/src/utils/markdown.ts 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 `
+                  
${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}
+
` + } catch (e) { + console.error(e) + } + } + + return '
' + md.utils.escapeHtml(str) + '
' + }, +}) + +export default md