8000 Fixed table of contents breaking when class is set on h1 · squidfunk/mkdocs-material@8d75231 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d75231

Browse files
committed
Fixed table of contents breaking when class is set on h1
1 parent f9f8c3a commit 8d75231

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

material/assets/stylesheets/main.962e687c.min.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/stylesheets/main.962e687c.min.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/partials/nav-item.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
<li class="{{ class }}">
4040
{% set toc = page.toc %}
4141
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
42-
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
43-
{% set toc = (toc | first).children %}
42+
{% set first = toc | first %}
43+
{% if first is defined and first.level == 1 %}
44+
{% set toc = first.children %}
4445
{% endif %}
45-
{% if toc | first is defined %}
46+
{% if toc is iterable %}
4647
<label class="md-nav__link md-nav__link--active" for="__toc">
4748
{{ nav_item.title }}
4849
<span class="md-nav__icon md-icon"></span>
@@ -51,7 +52,7 @@
5152
<a href="{{ nav_item.url | url }}" class="md-nav__link md-nav__link--active">
5253
{{ nav_item.title }}
5354
</a>
54-
{% if toc | first is defined %}
55+
{% if toc is iterable %}
5556
{% include "partials/toc.html" %}
5657
{% endif %}
5758
</li>

material/partials/toc.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
{% import "partials/language.html" as lang with context %}
55
<nav class="md-nav md-nav--secondary" aria-label="{{ lang.t('toc.title') }}">
66
{% set toc = page.toc %}
7-
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
8-
{% set toc = (toc | first).children %}
7+
{% set first = toc | first %}
8+
{% if first is defined and first.level == 1 %}
9+
{% set toc = first.children %}
910
{% endif %}
10-
{% if toc | first is defined %}
11+
{% if toc is iterable %}
1112
<label class="md-nav__title" for="__toc">
1213
<span class="md-nav__icon md-icon"></span>
1314
{{ lang.t("toc.title") }}

src/partials/nav-item.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@
101101
/>
102102

103103
<!-- Hack: see partials/toc.html for more information -->
104-
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
105-
{% set toc = (toc | first).children %}
104+
{% set first = toc | first %}
105+
{% if first is defined and first.level == 1 %}
106+
{% set toc = first.children %}
106107
{% endif %}
107108

108109
<!-- Render table of contents, if not empty -->
109-
{% if toc | first is defined %}
110+
{% if toc is iterable %}
110111
<label class="md-nav__link md-nav__link--active" for="__toc">
111112
{{ nav_item.title }}
112113
<span class="md-nav__icon md-icon"></span>
@@ -120,7 +121,7 @@
120121
</a>
121122

122123
<!-- Show table of contents -->
123-
{% if toc | first is defined %}
124+
{% if toc is iterable %}
124125
{% include "partials/toc.html" %}
125126
{% endif %}
126127
</li>

src/partials/toc.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
to the current page that is located just above the anchor. Therefore we
3333
directly continue with the children of the anchor.
3434
-->
35-
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
36-
{% set toc = (toc | first).children %}
35+
{% set first = toc | first %}
36+
{% if first is defined and first.level == 1 %}
37+
{% set toc = first.children %}
3738
{% endif %}
3839

3940
<!-- Render item list -->
40-
{% if toc | first is defined %}
41+
{% if toc is iterable %}
4142
<label class="md-nav__title" for="__toc">
4243
<span class="md-nav__icon md-icon"></span>
4344
{{ lang.t("toc.title") }}

0 commit comments

Comments
 (0)
0