diff --git a/frontend_nuxt/components/Dropdown.vue b/frontend_nuxt/components/Dropdown.vue index ef495c829..61d2040ef 100644 --- a/frontend_nuxt/components/Dropdown.vue +++ b/frontend_nuxt/components/Dropdown.vue @@ -147,11 +147,8 @@ diff --git a/frontend_nuxt/plugins/ldrs.client.ts b/frontend_nuxt/plugins/ldrs.client.ts new file mode 100644 index 000000000..66d8221c7 --- /dev/null +++ b/frontend_nuxt/plugins/ldrs.client.ts @@ -0,0 +1,12 @@ +// plugins/ldrs.client.ts +import { defineNuxtPlugin } from '#app' + +export default defineNuxtPlugin(async () => { + // 动态引入,防止打包时把 ldrs 拉进 SSR bundle + const { hatch, helix, spiral } = await import('ldrs') + + // 想用几个就注册几个 + hatch.register() + helix.register() + spiral.register() +}) diff --git a/frontend_nuxt/utils/markdown.js b/frontend_nuxt/utils/markdown.js index fc49b20c5..1f45c7761 100644 --- a/frontend_nuxt/utils/markdown.js +++ b/frontend_nuxt/utils/markdown.js @@ -1,5 +1,26 @@ +import MarkdownIt from 'markdown-it' +import hljs from 'highlight.js' +import 'highlight.js/styles/github.css' + +const md = new MarkdownIt({ + html: false, + linkify: true, + breaks: true, + highlight: (str, lang) => { + let code = '' + if (lang && hljs.getLanguage(lang)) { + code = hljs.highlight(str, { language: lang, ignoreIllegals: true }).value + } else { + code = hljs.highlightAuto(str).value + } + return `
${code}`
+ }
+})
+
+// todo: 简单用正则操作一下,后续体验不佳可以采用 striptags
export function stripMarkdown(text) {
- return text ? text.replace(/[#_*`>\-\[\]\(\)!]/g, '') : ''
+ const html = md.render(text)
+ return html.replace(/<\/?[^>]+>/g, '')
}
export function stripMarkdownLength(text, length) {