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 }}"> <li class="{{ class }}">
{% set toc = page.toc %} {% set toc = page.toc %}
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__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 first = toc | first %}
{% set toc = (toc | first).children %} {% if first is defined and first.level == 1 %}
{% set toc = first.children %}
{% endif %} {% endif %}
{% if toc | first is defined %} {% if toc is iterable %}
<label class="md-nav__link md-nav__link--active" for="__toc"> <label class="md-nav__link md-nav__link--active" for="__toc">
{{ nav_item.title }} {{ nav_item.title }}
<span class="md-nav__icon md-icon"></span> <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"> <a href="{{ nav_item.url | url }}" class="md-nav__link md-nav__link--active">
{{ nav_item.title }} {{ nav_item.title }}
</a> </a>
{% if toc | first is defined %} {% if toc is iterable %}
{% include "partials/toc.html" %} {% include "partials/toc.html" %}
{% endif %} {% endif %}
</li> </li>

View File

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

View File

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

View File

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