Fixed table of contents breaking when class is set on h1

This commit is contained in:
squidfunk 2021-04-15 21:21:33 +02:00
parent f9f8c3afdb
commit 8d752312aa
6 changed files with 21 additions and 14 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,10 +39,11 @@
<li class="{{ class }}">
{% set toc = page.toc %}
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
{% set toc = (toc | first).children %}
{% set first = toc | first %}
{% if first is defined and first.level == 1 %}
{% set toc = first.children %}
{% endif %}
{% if toc | first is defined %}
{% if toc is iterable %}
<label class="md-nav__link md-nav__link--active" for="__toc">
{{ nav_item.title }}
<span class="md-nav__icon md-icon"></span>
@ -51,7 +52,7 @@
<a href="{{ nav_item.url | url }}" class="md-nav__link md-nav__link--active">
{{ nav_item.title }}
</a>
{% if toc | first is defined %}
{% if toc is iterable %}
{% include "partials/toc.html" %}
{% endif %}
</li>

View File

@ -4,10 +4,11 @@
{% import "partials/language.html" as lang with context %}
<nav class="md-nav md-nav--secondary" aria-label="{{ lang.t('toc.title') }}">
{% set toc = page.toc %}
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
{% set toc = (toc | first).children %}
{% set first = toc | first %}
{% if first is defined and first.level == 1 %}
{% set toc = first.children %}
{% endif %}
{% if toc | first is defined %}
{% if toc is iterable %}
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
{{ lang.t("toc.title") }}

View File

@ -101,12 +101,13 @@
/>
<!-- Hack: see partials/toc.html for more information -->
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
{% set toc = (toc | first).children %}
{% set first = toc | first %}
{% if first is defined and first.level == 1 %}
{% set toc = first.children %}
{% endif %}
<!-- Render table of contents, if not empty -->
{% if toc | first is defined %}
{% if toc is iterable %}
<label class="md-nav__link md-nav__link--active" for="__toc">
{{ nav_item.title }}
<span class="md-nav__icon md-icon"></span>
@ -120,7 +121,7 @@
</a>
<!-- Show table of contents -->
{% if toc | first is defined %}
{% if toc is iterable %}
{% include "partials/toc.html" %}
{% endif %}
</li>

View File

@ -32,12 +32,13 @@
to the current page that is located just above the anchor. Therefore we
directly continue with the children of the anchor.
-->
{% if toc | first is defined and "\x3ch1 id=" in page.content %}
{% set toc = (toc | first).children %}
{% set first = toc | first %}
{% if first is defined and first.level == 1 %}
{% set toc = first.children %}
{% endif %}
<!-- Render item list -->
{% if toc | first is defined %}
{% if toc is iterable %}
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
{{ lang.t("toc.title") }}