Repository navigation
fix(docs): 修复脚注区块被渲染两次的问题 - #56
Merged
Merged
Conversation
VitePress 自 v2.0.0-alpha.19 起已内置脚注支持:其自带的 @mdit/plugin-footnote 由 `markdown.footnote` 控制且默认为 true,引用式 `[^1]` 与行内 `^[...]` 均可直接使用。 项目此前额外注册的 markdown-it-footnote 会与之同时向 markdown-it 注册 footnote 核心规则,两者都会在解析完成后追加脚注区块,导致同一页面的脚注被渲染两次 (如 /qa/faq/)。 移除该冗余插件及其类型依赖,改由 VitePress 原生处理;自定义的「附注」标题保留。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
/qa/faq/页面的脚注区块被渲染了两次,页面底部出现两个「附注」小节:原因
VitePress 自
v2.0.0-alpha.19起已内置脚注渲染:它依赖@mdit/plugin-footnote,由markdown.footnote选项控制且默认为true,引用式[^1]与行内^[...]语法均可直接使用。而项目在
docs/.vitepress/config.mts中又通过md.use(markdownItFootnote)额外注册了markdown-it-footnote。两者会各自注册 footnote 相关的 core 规则(footnote_tail/footnoteTail),且共用同一个env.footnotes,因此解析结束后各追加一次脚注区块,最终输出两份。该问题在升级到 alpha.19+ 之后才会出现 —— 本仓库在 #53 升级到
2.0.0-alpha.20后即可复现。修改
移除冗余的
markdown-it-footnote:docs/.vitepress/config.mts:删除 import 与md.use(markdownItFootnote)package.json/pnpm-lock.yaml:移除markdown-it-footnote与@types/markdown-it-footnote保留了自定义的
footnote_block_open渲染规则,以继续显示「附注」标题(该标题由 e6cd314 特意添加,VitePress 原生输出不带标题)。验证
pnpm docs:build通过,/qa/faq/页面:<h3>附注</h3>class="footnotes"脚注改为 VitePress 原生输出,锚点双向可用:
输出使用的
footnotes/footnote-item/footnote-ref/footnote-backref类名均为 VitePress 主题vp-doc.css已有的样式,无需额外 CSS。