Skip to content

Commit

Permalink
Implement nocontentsentry flag
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Sep 29, 2022
1 parent 66da829 commit 3fbe4ac
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 23 deletions.
44 changes: 26 additions & 18 deletions doc/usage/restructuredtext/domains.rst
Expand Up @@ -42,11 +42,15 @@ Basic Markup
Most domains provide a number of :dfn:`object description directives`, used to
describe specific objects provided by modules. Each directive requires one or
more signatures to provide basic information about what is being described, and
the content should be the description. A domain will typically keep an
internal index of all entities to aid cross-referencing. Typically it will
also add entries in the shown general index.
the content should be the description.

A domain will typically keep an internal index of all entities to aid
cross-referencing.
Typically it will also add entries in the shown general index.
If you want to suppress the addition of an entry in the shown index, you can
give the directive option flag ``:noindexentry:``.
If you want to exclude the object description from the table of contents, you
can give the directive option flag ``:nocontentsentry:``.
If you want to typeset an object description, without even making it available
for cross-referencing, you can give the directive option flag ``:noindex:``
(which implies ``:noindexentry:``).
Expand All @@ -57,6 +61,10 @@ options.
The directive option ``noindexentry`` in the Python, C, C++, and Javascript
domains.

.. versionadded:: 5.2.3
The directive option ``:nocontentsentry:`` in the Python, C, C++, Javascript,
and reStructuredText domains.

An example using a Python domain directive::

.. py:function:: spam(eggs)
Expand Down Expand Up @@ -523,7 +531,7 @@ For functions with optional parameters that don't have default values
argument support), you can use brackets to specify the optional parts:

.. py:function:: compile(source[, filename[, symbol]])
:noindex:
:nocontentsentry:

It is customary to put the opening bracket before the comma.

Expand Down Expand Up @@ -580,7 +588,7 @@ explained by an example::
This will render like this:

.. py:function:: send_message(sender, recipient, message_body, [priority=1])
:noindex:
:nocontentsentry:

Send a message to a recipient

Expand Down Expand Up @@ -1166,23 +1174,23 @@ visibility statement (``public``, ``private`` or ``protected``).
The example are rendered as follows.
.. cpp:type:: std::vector<int> MyList
:noindex:
:nocontentsentry:
A typedef-like declaration of a type.
.. cpp:type:: MyContainer::const_iterator
:noindex:
:nocontentsentry:
Declaration of a type alias with unspecified type.
.. cpp:type:: MyType = std::unordered_map<int, std::string>
:noindex:
:nocontentsentry:
Declaration of a type alias.
.. cpp:type:: template<typename T> \
MyContainer = std::vector<T>
:noindex:
:nocontentsentry:
.. rst:directive:: .. cpp:enum:: unscoped enum declaration
.. cpp:enum-struct:: scoped enum declaration
Expand Down Expand Up @@ -1277,7 +1285,7 @@ Options
Some directives support options:
- ``:noindexentry:``, see :ref:`basic-domain-markup`.
- ``:noindexentry:`` and ``:nocontentsentry:``, see :ref:`basic-domain-markup`.
- ``:tparam-line-spec:``, for templated declarations.
If specified, each template parameter will be rendered on a separate line.
Expand Down Expand Up @@ -1878,7 +1886,7 @@ The JavaScript domain (name **js**) provides the following directives:
This is rendered as:

.. js:function:: $.getJSON(href, callback[, errback])
:noindex:
:nocontentsentry:

:param string href: An URI to the location of the resource.
:param callback: Gets called with the object.
Expand Down Expand Up @@ -1908,7 +1916,7 @@ The JavaScript domain (name **js**) provides the following directives:
This is rendered as:

.. js:class:: MyAnimal(name[, age])
:noindex:
:nocontentsentry:

:param string name: The name of the animal
:param number age: an optional age for the animal
Expand Down Expand Up @@ -1955,12 +1963,12 @@ The reStructuredText domain (name **rst**) provides the following directives:
will be rendered as:

.. rst:directive:: foo
:noindex:
:nocontentsentry:

Foo description.

.. rst:directive:: .. bar:: baz
:noindex:
:nocontentsentry:

Bar description.

Expand All @@ -1979,13 +1987,13 @@ The reStructuredText domain (name **rst**) provides the following directives:
will be rendered as:

.. rst:directive:: toctree
:noindex:
:nocontentsentry:

.. rst:directive:option:: caption: caption of ToC
:noindex:
:nocontentsentry:
.. rst:directive:option:: glob
:noindex:
:nocontentsentry:
.. rubric:: options

Expand Down Expand Up @@ -2014,7 +2022,7 @@ The reStructuredText domain (name **rst**) provides the following directives:
will be rendered as:

.. rst:role:: foo
:noindex:
:nocontentsentry:

Foo description.

Expand Down
3 changes: 3 additions & 0 deletions sphinx/directives/__init__.py
Expand Up @@ -51,6 +51,8 @@ class ObjectDescription(SphinxDirective, Generic[T]):
final_argument_whitespace = True
option_spec: OptionSpec = {
'noindex': directives.flag,
'noindexentry': directives.flag,
'nocontentsentry': directives.flag,
}

# types of doc fields that this directive handles, see sphinx.util.docfields
Expand Down Expand Up @@ -211,6 +213,7 @@ def run(self) -> List[Node]:
node['objtype'] = node['desctype'] = self.objtype
node['noindex'] = noindex = ('noindex' in self.options)
node['noindexentry'] = ('noindexentry' in self.options)
node['nocontentsentry'] = ('nocontentsentry' in self.options)
if self.domain:
node['classes'].append(self.domain)
node['classes'].append(node['objtype'])
Expand Down
2 changes: 1 addition & 1 deletion sphinx/domains/c.py
Expand Up @@ -3142,8 +3142,8 @@ class CObject(ObjectDescription[ASTDeclaration]):
"""

option_spec: OptionSpec = {
'noindex': directives.flag,
'noindexentry': directives.flag,
'nocontentsentry': directives.flag,
}

def _add_enumerator_to_parent(self, ast: ASTDeclaration) -> None:
Expand Down
2 changes: 1 addition & 1 deletion sphinx/domains/cpp.py
Expand Up @@ -7186,8 +7186,8 @@ class CPPObject(ObjectDescription[ASTDeclaration]):
]

option_spec: OptionSpec = {
'noindex': directives.flag,
'noindexentry': directives.flag,
'nocontentsentry': directives.flag,
'tparam-line-spec': directives.flag,
}

Expand Down
4 changes: 3 additions & 1 deletion sphinx/domains/javascript.py
Expand Up @@ -40,6 +40,7 @@ class JSObject(ObjectDescription[Tuple[str, str]]):
option_spec: OptionSpec = {
'noindex': directives.flag,
'noindexentry': directives.flag,
'nocontentsentry': directives.flag,
}

def get_display_prefix(self) -> List[Node]:
Expand Down Expand Up @@ -284,7 +285,8 @@ class JSModule(SphinxDirective):
optional_arguments = 0
final_argument_whitespace = False
option_spec: OptionSpec = {
'noindex': directives.flag
'noindex': directives.flag,
'nocontentsentry': directives.flag,
}

def run(self) -> List[Node]:
Expand Down
2 changes: 2 additions & 0 deletions sphinx/domains/python.py
Expand Up @@ -427,6 +427,7 @@ class PyObject(ObjectDescription[Tuple[str, str]]):
option_spec: OptionSpec = {
'noindex': directives.flag,
'noindexentry': directives.flag,
'nocontentsentry': directives.flag,
'module': directives.unchanged,
'canonical': directives.unchanged,
'annotation': directives.unchanged,
Expand Down Expand Up @@ -1008,6 +1009,7 @@ class PyModule(SphinxDirective):
'platform': lambda x: x,
'synopsis': lambda x: x,
'noindex': directives.flag,
'nocontentsentry': directives.flag,
'deprecated': directives.flag,
}

Expand Down
2 changes: 1 addition & 1 deletion sphinx/domains/rst.py
Expand Up @@ -29,8 +29,8 @@ class ReSTMarkup(ObjectDescription[str]):
Description of generic reST markup.
"""
option_spec: OptionSpec = {
'noindex': directives.flag,
'noindexentry': directives.flag,
'nocontentsentry': directives.flag,
}

def add_target_and_index(self, name: str, sig: str, signode: desc_signature) -> None:
Expand Down
5 changes: 4 additions & 1 deletion sphinx/environment/collectors/toctree.py
Expand Up @@ -112,9 +112,12 @@ def build_toc(
# Skip if no name set
if not sig_node.get('_toc_name', ''):
continue
# Skip if explicitly disabled
if sig_node.parent.get('nocontentsentry'):
continue
# Skip entries with no ID (e.g. with :noindex: set)
ids = sig_node['ids']
if not ids or sig_node.parent.get('noindexentry'):
if not ids:
continue

anchorname = _make_anchor_name(ids, numentries)
Expand Down

0 comments on commit 3fbe4ac

Please sign in to comment.