From 5582ab29703ad6ef5d480a953db2d49746411d28 Mon Sep 17 00:00:00 2001 From: Nyako Shigure Date: Thu, 3 Sep 2026 20:53:36 +0800 Subject: [PATCH 1/2] docs(site): render Markdown task lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 📝 Documentation ## Render documentation checklists as checkbox lists - Convert valid task-list markers into disabled checkbox inputs during the VitePress build - Style task items without duplicate list bullets - Preserve support for unchecked and checked task markers without adding a dependency --- docs/.vitepress/config.mts | 32 ++++++++++++++++++++++++++++++-- docs/.vitepress/theme/custom.css | 13 +++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 5b6a51acd..c87d5ea39 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -209,9 +209,37 @@ export default defineConfig({ // Ignore dead links for source code references and placeholder pages ignoreDeadLinks: true, - // Enable LaTeX math rendering + // Enable LaTeX math rendering and GitHub-style task lists markdown: { - math: true + math: true, + config(md) { + md.core.ruler.after('inline', 'task-lists', (state) => { + for (let index = 2; index < state.tokens.length; index++) { + const inlineToken = state.tokens[index] + const marker = inlineToken.content.match(/^\[([ xX])\]\s+/) + const firstChild = inlineToken.children?.[0] + + if ( + inlineToken.type !== 'inline' || + state.tokens[index - 1].type !== 'paragraph_open' || + state.tokens[index - 2].type !== 'list_item_open' || + !marker || + firstChild?.type !== 'text' + ) { + continue + } + + inlineToken.content = inlineToken.content.slice(marker[0].length) + firstChild.content = firstChild.content.slice(marker[0].length) + + const checkbox = new state.Token('html_inline', '', 0) + const checked = marker[1].toLowerCase() === 'x' + checkbox.content = ` ` + inlineToken.children?.unshift(checkbox) + state.tokens[index - 2].attrJoin('class', 'task-list-item') + } + }) + } }, // 多语言配置 diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css index 798ff6d02..bb2ddc8f0 100644 --- a/docs/.vitepress/theme/custom.css +++ b/docs/.vitepress/theme/custom.css @@ -161,6 +161,19 @@ background: rgba(0, 0, 0, 0.9) !important; } +/** + * Component: Task List + * -------------------------------------------------------------------------- */ + +.vp-doc li.task-list-item { + list-style: none; +} + +.vp-doc .task-list-item-checkbox { + margin: 0 0.5em 0 -1.4em; + vertical-align: middle; +} + /** * ASCII Art Background — Dark Home Page * -------------------------------------------------------------------------- */ From 8effd206e061edf6e69334e6c266f748f55ab396 Mon Sep 17 00:00:00 2001 From: Nyako Shigure Date: Thu, 3 Sep 2026 21:07:09 +0800 Subject: [PATCH 2/2] docs(site): use task list plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 📝 Documentation ## Adopt the VitePress-recommended Markdown-it plugin - Replace the local task-list renderer with markdown-it-task-lists - Keep the existing scoped task-list styling - Use the established dependency recommended in VitePress issue discussions Co-authored-by: Nyakku Shigure --- docs/.vitepress/config.mts | 28 ++-------------------------- package.json | 1 + 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index c87d5ea39..c1afd6b95 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -1,3 +1,4 @@ +import taskLists from 'markdown-it-task-lists' import { defineConfig } from 'vitepress' // https://vitepress.dev/reference/site-config @@ -213,32 +214,7 @@ export default defineConfig({ markdown: { math: true, config(md) { - md.core.ruler.after('inline', 'task-lists', (state) => { - for (let index = 2; index < state.tokens.length; index++) { - const inlineToken = state.tokens[index] - const marker = inlineToken.content.match(/^\[([ xX])\]\s+/) - const firstChild = inlineToken.children?.[0] - - if ( - inlineToken.type !== 'inline' || - state.tokens[index - 1].type !== 'paragraph_open' || - state.tokens[index - 2].type !== 'list_item_open' || - !marker || - firstChild?.type !== 'text' - ) { - continue - } - - inlineToken.content = inlineToken.content.slice(marker[0].length) - firstChild.content = firstChild.content.slice(marker[0].length) - - const checkbox = new state.Token('html_inline', '', 0) - const checked = marker[1].toLowerCase() === 'x' - checkbox.content = ` ` - inlineToken.children?.unshift(checkbox) - state.tokens[index - 2].attrJoin('class', 'task-list-item') - } - }) + md.use(taskLists) } }, diff --git a/package.json b/package.json index 9b468b106..744842b34 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "devDependencies": { "@types/node": "^20.19.37", + "markdown-it-task-lists": "^2.1.1", "medium-zoom": "^1.1.0", "mermaid": "^10.0.0", "swagger-ui-dist": "^5.32.1",