Skip to content

Commit

Permalink
add support for globaltoc_includeinternal, closes bashtage#86
Browse files Browse the repository at this point in the history
  • Loading branch information
infinity0 committed Dec 4, 2020
1 parent 3c3d153 commit 110495d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Configuration Options
If true, TOC entries that are not ancestors of the current page are collapsed.
``globaltoc_includehidden``
If true, the global TOC tree will also contain hidden entries.
``globaltoc_includeinternal``
If false, the global TOC tree will not contain internal section headings
``theme_color``
The theme color for mobile browsers. Hex Color without the leading #.
``color_primary``
Expand Down
9 changes: 9 additions & 0 deletions sphinx_material/sphinx_material/globaltoc.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{% set toctree = toctree(maxdepth=theme_globaltoc_depth|toint, collapse=theme_globaltoc_collapse|tobool, includehidden=theme_globaltoc_includehidden|tobool) %}
{% set toc_nodes = derender_toc(toc, True, pagename) if display_toc else [] %}
{% if toctree and sidebars and 'globaltoc.html' in sidebars %}
{% set toctree_nodes = derender_toc(toctree, False) %}
<ul class="md-nav__list">
{%- for item in toctree_nodes recursive %}
{#
note: since toc_nodes only contains entries to the current page ("#xxx"), it
is not necessary to encode complex control logic in the below "if" statement
supporting theme_globaltoc_includeinternal to check that we are indeed in a
subtree of the current page
#}
{% if (theme_globaltoc_includeinternal|tobool) or (item not in (toc_nodes[0].children if toc_nodes else [])) %}
<li class="md-nav__item">
{% if "caption" in item %}
<span class="md-nav__link caption">{{ item.caption }}</span>
Expand All @@ -22,6 +30,7 @@
{%- endif %}
{% endif %}
</li>
{% endif %}
{%- endfor %}
</ul>
{# TODO: Fallback to toc? #}
Expand Down
4 changes: 3 additions & 1 deletion sphinx_material/sphinx_material/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ globaltoc_depth = 1
globaltoc_collapse = true
# If true, the global TOC tree will also contain hidden entries
globaltoc_includehidden = true
# If false, the global TOC tree will not contain internal section headings
globaltoc_includeinternal = true

# Colors
# The theme color for mobile browsers. Hex color.
Expand Down Expand Up @@ -109,4 +111,4 @@ version_json = "versions.json"
# Table classes to _not_ strip. Must be a list. Classes on this list are *not*
# removed from tables. All other classes are removed, and only tables with outclasses
# are styled by default.
table_classes =
table_classes =

0 comments on commit 110495d

Please sign in to comment.