From 3e2dac7c19db1b8575cfca9f7dfb7287ae792c37 Mon Sep 17 00:00:00 2001 From: Keldos Date: Wed, 8 Jan 2025 17:06:29 +0800 Subject: [PATCH 1/2] fix: fix incorrect numbering of headers when exporting HTML --- src/scss/heading.scss | 24 ++++++++++++------------ src/scss/toc.scss | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/scss/heading.scss b/src/scss/heading.scss index 793c6e1..b67142c 100644 --- a/src/scss/heading.scss +++ b/src/scss/heading.scss @@ -54,21 +54,21 @@ $theme: "" !default; // 下面是标题自动编号,初始化计数器。使用多级编号,编号后加空格模仿LaTeX // 首先全局进行一次reset,这样即使不添加h1标题也可以使用较低级别的标题 - counter-reset: h2 h3 h4 h5 h6; + counter-reset: heading-h2 heading-h3 heading-h4 heading-h5 heading-h6; h1 { - counter-reset: h2 h3 h4 h5 h6; + counter-set: heading-h2 0 heading-h3 0 heading-h4 0 heading-h5 0 heading-h6 0; } h2 { - counter-reset: h3 h4 h5 h6; + counter-set: heading-h3 0 heading-h4 0 heading-h5 0 heading-h6 0; } h3 { - counter-reset: h4 h5 h6; + counter-set: heading-h4 0 heading-h5 0 heading-h6 0; } h4 { - counter-reset: h5 h6; + counter-set: heading-h5 0 heading-h6 0; } h5 { - counter-reset: h6; + counter-set: heading-h6 0; } h2:before { @@ -110,31 +110,31 @@ h6.md-focus.md-heading:before { } @mixin heading-with-count($heading) { - counter-increment: #{$heading}; + counter-increment: heading-#{$heading}; margin-right: 1.2em; } %h2-with-count { - content: counter(h2); + content: counter(heading-h2); @include heading-with-count(h2); } %h3-with-count { - content: counter(h2) "." counter(h3); + content: counter(heading-h2) "." counter(heading-h3); @include heading-with-count(h3); } %h4-with-count { - content: counter(h2) "." counter(h3) "." counter(h4); + content: counter(heading-h2) "." counter(heading-h3) "." counter(heading-h4); @include heading-with-count(h4); } %h5-with-count { - content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5); + content: counter(heading-h2) "." counter(heading-h3) "." counter(heading-h4) "." counter(heading-h5); @include heading-with-count(h5); } %h6-with-count { - content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6); + content: counter(heading-h2) "." counter(heading-h3) "." counter(heading-h4) "." counter(heading-h5) "." counter(heading-h6); @include heading-with-count(h6); } diff --git a/src/scss/toc.scss b/src/scss/toc.scss index 692beba..dcef626 100644 --- a/src/scss/toc.scss +++ b/src/scss/toc.scss @@ -8,7 +8,7 @@ $theme: "" !default; .md-toc-content { margin-left: 2em; /* 修复缺失上级标题时无法递增 */ - counter-reset: toc-h2 toc-h3 toc-h4; + counter-set: toc-h2 0 toc-h3 0 toc-h4 0; break-after: page; } .md-toc-inner { @@ -45,19 +45,19 @@ $theme: "" !default; .md-toc-content { .md-toc-h1 { display: var(--toc-show-title); - counter-reset: toc-h2 toc-h3 toc-h4 toc-h5 toc-h6; + counter-set: toc-h2 0 toc-h3 0 toc-h4 0 toc-h5 0 toc-h6 0; } .md-toc-h2 { - counter-reset: toc-h3 toc-h4 toc-h5 toc-h6; + counter-set: toc-h3 0 toc-h4 0 toc-h5 0 toc-h6 0; } .md-toc-h3 { - counter-reset: toc-h4 toc-h5 toc-h6; + counter-set: toc-h4 0 toc-h5 0 toc-h6 0; } .md-toc-h4 { - counter-reset: toc-h5 toc-h6; + counter-set: toc-h5 0 toc-h6 0; } .md-toc-h5 { - counter-reset: toc-h6; + counter-set: toc-h6 0; } .md-toc-h2:before { counter-increment: toc-h2; From 02a205eb70e421e9b6ea403a8725ccc75a975caa Mon Sep 17 00:00:00 2001 From: Keldos Date: Fri, 10 Jan 2025 14:57:29 +0800 Subject: [PATCH 2/2] fix: use `counter-reset` to create toc counter at first place --- src/scss/toc.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scss/toc.scss b/src/scss/toc.scss index dcef626..f5bceb9 100644 --- a/src/scss/toc.scss +++ b/src/scss/toc.scss @@ -8,7 +8,7 @@ $theme: "" !default; .md-toc-content { margin-left: 2em; /* 修复缺失上级标题时无法递增 */ - counter-set: toc-h2 0 toc-h3 0 toc-h4 0; + counter-reset: toc-h2 toc-h3 toc-h4 toc-h5 toc-h6; break-after: page; } .md-toc-inner {