Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class option to toctree directive #12524

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

timhoffm
Copy link
Contributor

@timhoffm timhoffm commented Jul 9, 2024

This is a common option for directives (https://docutils.sourceforge.io/docs/ref/rst/directives.html#common-options).

Implementation: The class is added to there toctree-wrapper element, so that

.. toctree::
   :class: some-class

is equivalent to

.. rst-class:: some-class
.. toctree::

This is a common option for directives (https://docutils.sourceforge.io/docs/ref/rst/directives.html#common-options).

Implementation detail: The class is added to there `toctree-wrapper`
element, so that
```
.. toctree::
   :class: some-class
```
is equivalent to
```
.. rst-class:: some-class
.. toctree::
```
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, my only reservation would be adding the class to toctree-wrapper instead of the actual node.

A

CHANGES.rst Outdated Show resolved Hide resolved
doc/conf.py Outdated Show resolved Hide resolved
doc/usage/restructuredtext/directives.rst Outdated Show resolved Hide resolved
sphinx/directives/other.py Outdated Show resolved Hide resolved
doc/usage/restructuredtext/basics.rst Outdated Show resolved Hide resolved
Comment on lines 141 to 144
text = (".. toctree::\n"
" :class: custom-toc\n"
"\n"
" foo\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
text = (".. toctree::\n"
" :class: custom-toc\n"
"\n"
" foo\n")
text = ('.. toctree::\n'
' :class: custom-toc\n'
'\n'
' foo\n')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. But note that all neighboring examples use double quotes.

@timhoffm
Copy link
Contributor Author

Looks reasonable, my only reservation would be adding the class to toctree-wrapper instead of the actual node.

My reasoning was

  • This is what an external .. rst-class:: directive would do to toctree
  • It's simpler to select children (.custom-toc [child-selector]) rather than parents ("a node which has a child with .custom-toc class" - I suppose that's possible through the relatively new has(), but would have to look it up)

But if you say the actual node should be used, I can change that. I don't have enough insight why the wrapper is there and whether it should be considered or skipped.

@AA-Turner
Copy link
Member

Seems that it was added in #129, see https://www.sphinx-doc.org/en/master/changes.html#id3196 (fifth bullet under "HTML output"). Regardless, I think your logic makes sense.

A

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
CHANGES.rst Outdated Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
@AA-Turner AA-Turner merged commit a95d716 into sphinx-doc:master Jul 10, 2024
23 checks passed
@AA-Turner
Copy link
Member

Thanks Tim!

A

@timhoffm timhoffm deleted the toctree-class branch July 10, 2024 10:15
@AA-Turner AA-Turner added this to the 7.4.0 milestone Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants