{% set theTocTree = toctree(includehidden=theme_sidebar_includehidden, collapse=False, maxdepth=2)
| replace('
', "", 1)
| replace('
', "Second ")
| replace('
', "Second ")
| replace('
', "")
| replace('
', "First ")
| replace('
', "First ")
| replace('
', "")
%}
{# Start by splitting the TocTree by 1st level children #}
{% set list = theTocTree.split("First ") %}
{% if parents|length >= 1 %}
{{ parents[0].title }}
{% else %}
{{ project }}
{% endif %}
{{ title }}
{# Skip the first section as it is a '\n' resulting from splitting the string #}
{% for section in list[1:] %}
{# Split each 1st level child into subSections that may contain a 2nd level children #}
{% set subSection = section.split("Second ") %}
{% set headerTarget = "heading" ~ loop.index %}
{% for item in subSection %}
{# first (and only) item is a 1st level child #}
{% if subSection|length == 1 %}
{{ item }}
{% elif loop.index == 1 %}
{{ item | striptags }}
{# all other children are 2nd level children #}
{% else %}