diff --git a/apps/docs/README.md b/apps/docs/README.md
index 4f1de0e..f624a71 100644
--- a/apps/docs/README.md
+++ b/apps/docs/README.md
@@ -13,6 +13,8 @@ pnpm docs:preview
English pages live at the documentation root. Every user-facing page has a matching Chinese page under `zh-CN`. `pnpm docs:check` verifies this route parity before building the site.
+The check also validates the security-patched Markdown parser through VitePress's actual renderer. The local integration patch and its removal criteria are documented in [Dependency patches](../../patches/README.md).
+
The generated `.vitepress/dist` directory is local build output and must not be edited or committed. Publishing the site, configuring `d.i0c.cc`, or changing DNS remains a separate external operation.
## Vercel deployment
diff --git a/apps/docs/README.zh-CN.md b/apps/docs/README.zh-CN.md
index bb8904a..d532dff 100644
--- a/apps/docs/README.zh-CN.md
+++ b/apps/docs/README.zh-CN.md
@@ -15,6 +15,8 @@ pnpm docs:preview
生成的 `.vitepress/dist` 属于本地构建产物,不应直接编辑或提交。发布站点、配置 `d.i0c.cc` 或修改 DNS 均属于独立的外部操作。
+该检查还通过 VitePress 实际渲染器验证已修补的 Markdown 解析器。本地集成补丁及其移除条件见[依赖补丁说明](../../patches/README.md)。
+
## Vercel 部署
创建独立的 Vercel 项目,并把 Root Directory 设为 `apps/docs`。仓库内的 [vercel.json](vercel.json) 使用 Corepack 管理的 pnpm 从仓库根安装工作区、执行 `corepack pnpm build`,并发布 `.vitepress/dist`。文档站不需要在仓库根目录放置 Vercel 配置。
diff --git a/apps/docs/package.json b/apps/docs/package.json
index 346b736..b95630c 100644
--- a/apps/docs/package.json
+++ b/apps/docs/package.json
@@ -12,7 +12,7 @@
"scripts": {
"assets:check": "corepack pnpm --dir ../.. assets:check",
"dev": "corepack pnpm assets:check && vitepress dev .",
- "check": "corepack pnpm assets:check && node scripts/check-locales.mjs && vitepress build .",
+ "check": "corepack pnpm assets:check && node scripts/check-locales.mjs && node --test scripts/markdown-security.test.mjs && vitepress build .",
"build": "corepack pnpm assets:check && vitepress build .",
"preview": "vitepress preview ."
},
diff --git a/apps/docs/scripts/markdown-security.test.mjs b/apps/docs/scripts/markdown-security.test.mjs
new file mode 100644
index 0000000..5762ff0
--- /dev/null
+++ b/apps/docs/scripts/markdown-security.test.mjs
@@ -0,0 +1,92 @@
+import assert from "node:assert/strict"
+import { createRequire } from "node:module"
+import path from "node:path"
+import test from "node:test"
+import { fileURLToPath, pathToFileURL } from "node:url"
+import { isMainThread, parentPort, Worker, workerData } from "node:worker_threads"
+
+const docsRoot = fileURLToPath(new URL("../", import.meta.url))
+
+if (!isMainThread) {
+ const require = createRequire(import.meta.url)
+ const requireFromVitePress = createRequire(require.resolve("vitepress"))
+ const packagePath = requireFromVitePress.resolve("markdown-it/package.json")
+ assert.equal(requireFromVitePress("markdown-it/package.json").version, "14.3.3")
+ const { default: MarkdownIt } = await import(
+ pathToFileURL(path.join(path.dirname(packagePath), "index.mjs")).href
+ )
+ const { createMarkdownRenderer } = await import("vitepress")
+ const md = await createMarkdownRenderer(docsRoot, {
+ typographer: true,
+ highlight: (code) => code,
+ })
+ assert.equal(md.constructor, MarkdownIt, "VitePress must use the patched parser")
+ parentPort.postMessage(md.render(workerData))
+} else {
+ function render(markdown) {
+ return new Promise((resolve, reject) => {
+ const worker = new Worker(new URL(import.meta.url), {
+ workerData: markdown,
+ resourceLimits: { maxOldGenerationSizeMb: 256 },
+ })
+ const timer = setTimeout(() => {
+ void worker.terminate()
+ reject(new Error("VitePress rendering exceeded the 15 second limit"))
+ }, 15_000)
+ worker.once("message", (html) => {
+ clearTimeout(timer)
+ resolve(html)
+ })
+ worker.once("error", (error) => {
+ clearTimeout(timer)
+ reject(error)
+ })
+ worker.once("exit", (code) => {
+ clearTimeout(timer)
+ if (code !== 0) reject(new Error(`Markdown worker exited with ${code}`))
+ })
+ })
+ }
+
+ test("VitePress preserves its plugins with the external security-patched parser", async () => {
+ const html = await render([
+ "# Nami 文档",
+ "",
+ "::: tip",
+ "**English** and 中文 with [reference][guide].",
+ ":::",
+ "",
+ "| Runtime | 状态 |",
+ "| --- | --- |",
+ "| Cloudflare | Ready |",
+ "",
+ "`inline code` and HTML.",
+ "",
+ "[guide]: https://example.com/guide",
+ ].join("\n"))
+ assert.match(html, /header-anchor/)
+ assert.match(html, /Nami 文档/)
+ assert.match(html, /tip custom-block/)
+ assert.match(html, /English<\/strong>/)
+ assert.match(html, //)
+ assert.match(html, /href="https:\/\/example\.com\/guide"/)
+ assert.match(html, /inline code<\/code>/)
+ assert.match(html, /HTML<\/span>/)
+ })
+
+ // Adapted from markdown-it's MIT-licensed 14.3.3 pathological tests:
+ // https://github.com/markdown-it/markdown-it/blob/14.3.3/test/markdown-it/pathological.test.mjs
+ const pathologicalCases = [
+ ["unclosed inline HTML", "" + "