Skip to content

fix(counter): scope heading counters and fix cascading resets - #2

Merged
taoky merged 1 commit into
ustclug:masterfrom
Minsecrus:fix/heading-counter-scope
Dec 1, 2026
Merged

taoky merged 1 commit into
ustclug:masterfrom
Minsecrus:fix/heading-counter-scope

Conversation

@Minsecrus

Copy link
Copy Markdown

修复 src/templates/assets/stylesheets/ustclug/_counter.scss 中全局标题自动编号的两处问题:

  1. 全局裸 h1–h6 选择器误伤非正文大纲标题并污染外部计数器

    • 在 Linux101-docs 的 Appendix/markdown.md 中,提示框(.admonition)内用于演示效果的 <h1>/<h2>/<h6> 会被自动加上 2 this is H2、2.1.0.0.1 this is H6 等编号,并把提示框后原本的 1.2 段落 顶成 2.2 段落。
    • 主题自带的搜索结果弹窗(.md-search-result__article)也会用 <h2> 渲染小节结果,同样会被裸 h2::before 加上无关编号。
    • 将选择器收窄至 .md-content__inner > h1~h6(并在 .md-content__inner 上初始化计数器),仅对正文容器直接子标题编号。
  2. 跳级标题下计数器不自增(卡死在 .0.1)

    • 原样式仅重置紧邻的下一级计数器(如 h2 只 counter-reset: h3),且把 counter-increment 写在 ::before 伪元素上。当页面跳过某级标题(例如 h2 后直接接多个 h4,如 Linux101-docs 原 Spec/slide.md)时,外层作用域不存在 h4 计数器,每个 h4::before 都会临时创建仅作用于该伪元素的 h4=1,导致连续多个 h4 全都显示为 1.0.1。
    • 将 counter-increment 移回标题元素本身,并让各级标题级联重置所有更低级计数器(如 > h2 { counter-reset: h3 h4 h5 h6; counter-increment: h2; })。

构建产物说明:

  • 按 FORK.md 运行 npm run build:all 重新生成 material/。
  • 因 0a541db(Merge upstream tag 9.8.1)合入上游 e325895 升级后的构建依赖时未全量重编 material/,本次完整构建顺带刷新了 palette、bundle、custom 的产物 hash(iconsearch_index.json 内容与 HEAD 一致,无变更)。

本地验证:

  • npm test(11/11)、npm run check(tsc / stylelint / eslint)、npm run build:all 均通过。
  • 将本地构建包安装到 Linux101-docs 中预览确认:/Appendix/markdown/ 示例框不再带编号且后续恢复 1.2 段落,搜索下拉结果的小节标题也不再带假编号。

问题排查、修改与本地验证使用了 Google Antigravity(Gemini 模型)辅助,所有改动均已人工核对并在本地浏览器确认效果。

@taoky
taoky merged commit 031f5fd into ustclug:master Dec 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants