diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 5866b0e297..906827ff32 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -678,6 +678,11 @@ General configuration :term:`object` names (for object types where a "module" of some kind is defined), e.g. for :rst:dir:`py:function` directives. Default is ``True``. +.. confval:: toc_object_entries + + Create table of contents entries for domain objects (e.g. functions, classes, + attributes, etc.). Default is ``True``. + .. confval:: toc_object_entries_show_parents A string that determines how domain objects (e.g. functions, classes, diff --git a/sphinx/config.py b/sphinx/config.py index 45df6bb005..2906a32857 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -106,6 +106,7 @@ class Config: 'default_role': (None, 'env', [str]), 'add_function_parentheses': (True, 'env', []), 'add_module_names': (True, 'env', []), + 'toc_object_entries': (True, 'env', [bool]), 'toc_object_entries_show_parents': ('domain', 'env', ENUM('domain', 'all', 'hide')), 'trim_footnote_reference_space': (False, 'env', []), diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index 2c8bdcdc51..e59cb1295d 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -239,8 +239,12 @@ def run(self) -> List[Node]: finally: # Private attributes for ToC generation. Will be modified or removed # without notice. - signode['_toc_parts'] = self._object_hierarchy_parts(signode) - signode['_toc_name'] = self._toc_entry_name(signode) + if self.env.app.config.toc_object_entries: + signode['_toc_parts'] = self._object_hierarchy_parts(signode) + signode['_toc_name'] = self._toc_entry_name(signode) + else: + signode['_toc_parts'] = () + signode['_toc_name'] = '' if name not in self.names: self.names.append(name) if not noindex: