From 73b9dcf0cd8b204391f65eeadf1434eeecf7dabb Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 7 Aug 2025 20:07:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=93=8D=E4=BD=9Cldrs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend_nuxt/components/Dropdown.vue | 7 +-- frontend_nuxt/components/MenuComponent.vue | 4 -- frontend_nuxt/main.js | 4 +- frontend_nuxt/nuxt.config.ts | 13 ++++- frontend_nuxt/package-lock.json | 64 ++++++++++++++++++++++ frontend_nuxt/package.json | 6 +- frontend_nuxt/pages/index.vue | 61 ++++++++++++++------- frontend_nuxt/plugins/ldrs.client.ts | 12 ++++ frontend_nuxt/utils/markdown.js | 23 +++++++- 9 files changed, 158 insertions(+), 36 deletions(-) create mode 100644 frontend_nuxt/plugins/ldrs.client.ts 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) {