From 75826961d46a5452e64128c18f7f61f97e641d07 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:44:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(docs):=20=E6=B7=BB=E5=8A=A0=20Markdown=20?= =?UTF-8?q?=E8=BD=AC=E4=B9=89=E6=8F=92=E4=BB=B6=E8=A7=A3=E5=86=B3=20HTML?= =?UTF-8?q?=20=E6=A0=87=E7=AD=BE=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 VitePress 配置中集成 markdown-escape-plugin - 实现代码块保护机制避免代码中的 < > 符号被转义 - 添加预处理器确保代码块内容不被 HTML 转义影响 - 通过占位符机制实现代码块的临时替换和恢复 - 提供完整的代码块解析和转义处理流程 --- docs/.vitepress/config.mts | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 276bcf8..d999b03 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -1,12 +1,15 @@ import { defineConfig } from 'vitepress' export default defineConfig({ + title: 'GFramework', description: '面向游戏开发场景的模块化 C# 框架', /** GitHub Pages / 子路径部署 */ base: '/GFramework/', - + vite: { + plugins: [markdownEscapePlugin()] + }, /** 多语言 */ locales: { root: { @@ -167,3 +170,35 @@ export default defineConfig({ } } }) +import { defineConfig } from 'vitepress' + +function markdownEscapePlugin() { + return { + name: 'markdown-escape-plugin', + enforce: 'pre', // 在 vitepress 之前执行 + transform(code: string, id: string) { + if (!id.endsWith('.md')) return + + const codeBlocks: string[] = [] + + // 1️⃣ 替换代码块 + const replaced = code.replace(/```[\s\S]*?```/g, (match) => { + const index = codeBlocks.length + codeBlocks.push(match) + return `__CODE_BLOCK_${index}__` + }) + + // 2️⃣ 转义普通文本中的 < > + let escaped = replaced + .replace(//g, '>') + + // 3️⃣ 恢复代码块 + codeBlocks.forEach((block, index) => { + escaped = escaped.replace(`__CODE_BLOCK_${index}__`, block) + }) + + return escaped + } + } +}