zola/docs/content/documentation/content/table-of-contents.md
eaon 28523ac9ad
Allow emitting newlines and whitespace in shortcodes and introduce markdown shortcodes (#1085)
* Replace hack for newline support in shortcodes with new hack

* Be a bit more space efficient/accurate with naming

* Boil newline/whitespace shortcode test down to the essentials

* Make sure the new \n and \s chars in old tests are properly represented

* Support markdown templates and shortcodes

* Refactoring .md/.html shortcode behaviour

* Add test for markdown shortcodes

* Add an html output test for markdown based shortcodes

* Add documentation for Markdown based shortcodes
2020-07-29 20:20:43 +02:00

1.1 KiB

+++ title = "Table of Contents" weight = 60 +++

Each page/section will automatically generate a table of contents for itself based on the headers generated with markdown.

It is available in the template through the page.toc or section.toc variable. You can view the template variables documentation for information on its structure.

Here is an example of using that field to render a two-level table of contents:

<ul>
{% for h1 in page.toc %}
    <li>
        <a href="{{h1.permalink | safe}}">{{ h1.title }}</a>
        {% if h1.children %}
            <ul>
                {% for h2 in h1.children %}
                    <li>
                        <a href="{{h2.permalink | safe}}">{{ h2.title }}</a>
                    </li>
                {% endfor %}
            </ul>
        {% endif %}
    </li>
{% endfor %}
</ul>

While headers are neatly ordered in this example, it will work just as well with disjoint headers.

Note that all existing HTML tags from the title will NOT be present in the table of contents to avoid various issues.