From 7456ba369c7518704fe39b5585a3084a65d98a3a Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 7 Jul 2020 22:56:53 +0900 Subject: [PATCH] Close #7902: html theme: Add a new option globaltoc_maxdepth --- CHANGES | 2 ++ _docutils | 1 + doc/usage/theming.rst | 6 ++++++ sphinx/builders/html/__init__.py | 2 ++ sphinx/themes/basic/globaltoc.html | 2 +- sphinx/themes/basic/theme.conf | 1 + 6 files changed, 13 insertions(+), 1 deletion(-) create mode 120000 _docutils diff --git a/CHANGES b/CHANGES index 1935d6d0902..b084768d173 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,8 @@ Features added * #7888: napoleon: Add aliases Warn and Raise. * C, added :rst:dir:`c:alias` directive for inserting copies of existing declarations. +* #7902: html theme: Add a new option :confval:`globaltoc_maxdepth` to control + the behavior of globaltoc in sidebar * #7052: add ``:noindexentry:`` to the Python, C, C++, and Javascript domains. Update the documentation to better reflect the relationship between this option and the ``:noindex:`` option. diff --git a/_docutils b/_docutils new file mode 120000 index 00000000000..bf3cbf1afb7 --- /dev/null +++ b/_docutils @@ -0,0 +1 @@ +.tox/py37/lib/python3.7/site-packages/docutils \ No newline at end of file diff --git a/doc/usage/theming.rst b/doc/usage/theming.rst index 792a4a53d6a..5474e9620d7 100644 --- a/doc/usage/theming.rst +++ b/doc/usage/theming.rst @@ -172,6 +172,12 @@ These themes are: .. versionadded:: 3.1 + - **globaltoc_maxdepth** (int): The maximum depth of the toctree in + ``globaltoc.html`` (see :confval:`html_sidebars`). Set it to -1 to allow + unlimited depth. Defaults to the max depth selected in the toctree directive. + + .. versionadded:: 3.2 + **alabaster** `Alabaster theme`_ is a modified "Kr" Sphinx theme from @kennethreitz (especially as used in his Requests project), which was itself originally diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index c0c4f847590..69349549e0c 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -886,6 +886,8 @@ def index_page(self, pagename: str, doctree: nodes.document, title: str) -> None def _get_local_toctree(self, docname: str, collapse: bool = True, **kwargs: Any) -> str: if 'includehidden' not in kwargs: kwargs['includehidden'] = False + if kwargs.get('maxdepth') == '': + kwargs.pop('maxdepth') return self.render_partial(TocTree(self.env).get_toctree_for( docname, self, collapse, **kwargs))['fragment'] diff --git a/sphinx/themes/basic/globaltoc.html b/sphinx/themes/basic/globaltoc.html index 2f16655cf5e..1b2f9baeefd 100644 --- a/sphinx/themes/basic/globaltoc.html +++ b/sphinx/themes/basic/globaltoc.html @@ -8,4 +8,4 @@ :license: BSD, see LICENSE for details. #}

{{ _('Table of Contents') }}

-{{ toctree(includehidden=theme_globaltoc_includehidden, collapse=theme_globaltoc_collapse) }} +{{ toctree(includehidden=theme_globaltoc_includehidden, collapse=theme_globaltoc_collapse, maxdepth=theme_globaltoc_maxdepth) }} diff --git a/sphinx/themes/basic/theme.conf b/sphinx/themes/basic/theme.conf index 3c289d5dca7..ff378cab406 100644 --- a/sphinx/themes/basic/theme.conf +++ b/sphinx/themes/basic/theme.conf @@ -12,3 +12,4 @@ body_max_width = 800 navigation_with_keys = False globaltoc_collapse = true globaltoc_includehidden = false +globaltoc_maxdepth =