Skip to content

Commit 610d8c0

Browse files
committed
Fixed #5: Page without headlines renders empty list in table of contents
1 parent ba72ddb commit 610d8c0

File tree

3 files changed

+39
-48
lines changed

3 files changed

+39
-48
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mkdocs-material-0.x.x (2016-xx-xx)
22

33
* Fixed #3: Ordered lists within an unordered list have ::before content
44
* Fixed #4: Click on Logo/Title without Github-Repository: "None"
5+
* Fixed #5: Page without headlines renders empty list in table of contents
56
* Moved Modernizr to top to ensure basic usability in IE8
67

78
mkdocs-material-0.1.2 (2016-02-16)

material/nav.html

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,21 @@
1313
{{ nav_item.title }}
1414
</a>
1515
{% if nav_item == current_page %}
16-
<ul>
17-
{% for toc_item in toc %}
18-
{% if h1 %}
19-
{% for toc_item in toc_item.children %}
20-
<li class="anchor">
21-
<a title="{{ toc_item.title }}" href="{{ toc_item.url }}">
22-
{{ toc_item.title }}
23-
</a>
24-
</li>
25-
{% endfor %}
26-
{% else %}
27-
<li class="anchor">
28-
<a title="{{ toc_item.title }}" href="{{ toc_item.url }}">
29-
{{ toc_item.title }}
30-
</a>
31-
</li>
32-
{% endif %}
33-
{% endfor %}
34-
</ul>
16+
{% if h1 %}
17+
{% set toc_item = toc | first %}
18+
{% set toc = toc_item.children %}
19+
{% endif %}
20+
{% if toc %}
21+
<ul>
22+
{% for toc_item in toc %}
23+
<li class="anchor">
24+
<a title="{{ toc_item.title }}" href="{{ toc_item.url }}">
25+
{{ toc_item.title }}
26+
</a>
27+
</li>
28+
{% endfor %}
29+
</ul>
30+
{% endif %}
3531
{% endif %}
3632
</li>
3733
{% endif %}

src/nav.html

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,32 @@
2121

2222
<!-- Expand active pages -->
2323
{% if nav_item == current_page %}
24-
<ul>
2524

26-
<!-- Render anchors of active page -->
27-
{% for toc_item in toc %}
25+
<!--
26+
The top-level anchor must be skipped if the article contains a h1
27+
headline, since it would be redundant to the link to the current page
28+
that is located just above the anchor. Therefore we directly continue
29+
with the children of the anchor.
30+
-->
31+
{% if h1 %}
32+
{% set toc_item = toc | first %}
33+
{% set toc = toc_item.children %}
34+
{% endif %}
2835

29-
<!--
30-
The top-level anchor must be skipped if the article contains a h1
31-
headline, since it would be redundant to the link to the current
32-
page that is located just above the anchor. Therefore we directly
33-
continue with the children of the anchor.
34-
-->
35-
{% if h1 %}
36-
{% for toc_item in toc_item.children %}
36+
<!-- Render anchors of active page -->
37+
{% if toc %}
38+
<ul>
39+
{% for toc_item in toc %}
3740

38-
<!-- Render anchor -->
39-
<li class="anchor">
40-
<a title="{{ toc_item.title }}" href="{{ toc_item.url }}">
41-
{{ toc_item.title }}
42-
</a>
43-
</li>
44-
{% endfor %}
45-
{% else %}
46-
47-
<!-- Render anchor -->
48-
<li class="anchor">
49-
<a title="{{ toc_item.title }}" href="{{ toc_item.url }}">
50-
{{ toc_item.title }}
51-
</a>
52-
</li>
53-
{% endif %}
54-
{% endfor %}
55-
</ul>
41+
<!-- Render anchor -->
42+
<li class="anchor">
43+
<a title="{{ toc_item.title }}" href="{{ toc_item.url }}">
44+
{{ toc_item.title }}
45+
</a>
46+
</li>
47+
{% endfor %}
48+
</ul>
49+
{% endif %}
5650
{% endif %}
5751
</li>
5852
{% endif %}

0 commit comments

Comments
 (0)