Skip to content
2 changes: 1 addition & 1 deletion Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
html_sidebars = {
# Defaults taken from https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars
# Removes the quick search block
'**': ['localtoc.html', 'relations.html', 'customsourcelink.html'],
'**': ['customlocaltoc.html', 'relations.html', 'customsourcelink.html'],
'index': ['indexsidebar.html'],
}

Expand Down
1 change: 1 addition & 0 deletions Doc/contents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

.. toctree::
:maxdepth: 2

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this is a separable change from the toc headers if that would be better to consider separately!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does this change?

For example, these both go down to 2.5.4.1, so I guess it's something else?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Just the depth of this page: https://cpython-previews--123453.org.readthedocs.build/en/123453/contents.html

We can remove this change or increase the number or whatever works, that page is just at the top of the hierarchy (and what you get bumped to whenever you click "up" in the ToC currently), and so if the hierarchy was easier to ascend and descend, then I thought it might be easier to have that page not list every child page, but a shorter view that can then be expanded.

But I don't want it to be a blocker for the main TOC header change, so if its controversial we can drop it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay, let's put this in another PR so we can consider it separately.


whatsnew/index.rst
tutorial/index.rst
Expand Down
29 changes: 29 additions & 0 deletions Doc/tools/templates/customlocaltoc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{#
Customization of Sphinx's basic/localtoc.html

- When present, display links to the parent pages within sections,
rather than link to the global contents
- When parents are absent, display a link to the document root using the docstitle

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
- When parents are absent, display a link to the document root using the docstitle
- When parents are absent, display a link to the homepage using the docstitle

#}
<div>
<div>
{%- if parents %}
{%- for parent in parents[-4:] %}
<h{{ loop.index0 + 3 }}>
Comment on lines +8 to +12

@hugovk hugovk May 12, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comparing Doc/venv/lib/python3.14/site-packages/sphinx/themes/basic/localtoc.html:

{# Sphinx sidebar template: local table of contents. #}
{%- if display_toc %}
  <div>
    <h3><a href="{{ pathto(root_doc)|e }}">{{ _('Table of Contents') }}</a></h3>
    {{ toc }}
  </div>
{%- endif %}

That's one <div> before the first h.

Here we have two <div> before the first h. Do we need both or can we drop one to keep it consistent?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No problem - I had added the second one to group all the header elements together with ToC as a sibling in case we wanted to style those as a group, but there currently aren't any CSS rules that target it, so can drop

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed the other problems, and the TOC for a triple-nested page looks like this:

Screenshot 2026-05-12 at 5 36 49 PM

which is fine, but it's a little awkward - it's not that obvious that the top three are parent headers and then the one below that is the page contents. It might be useful to add some additional spacing or a divider after the header block, reduce the top-margins on the headers, or add some hierarchy indicators (this looks pretty crappy, just a 5 minute manual in-page css edit for the sake of illustration)

Screenshot 2026-05-12 at 5 34 40 PM

I don't see any custom css in here except for the profiling visualization css, so it might not be worth it to introduce it just for this, but i could write it inline if that would be desired.

or, if it's fine, and we want to remove this extra div, just lmk, no problem with that.

@StanFromIreland StanFromIreland May 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Custom CSS goes in our Sphinx theme generally.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

got it, lmk if that would be a good addition!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's drop the extra <div>: if we don't need them now, it's probably better to keep it consistent with the basic theme.

We can always add back if/when we need to target this specifically.

Comment thread
sneakers-the-rat marked this conversation as resolved.
Resolved
<a href="{{ parent.link|e }}"
title="{{ parent.title|striptags }}">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sphinx's own templates escape, shall we also?

Suggested change
title="{{ parent.title|striptags }}">
title="{{ parent.title|striptags|e }}">

{{ parent.title }}
</a>
</h{{ loop.index0 + 3 }}>
{%- endfor %}
{%- else %}
<h3>
<a href="{{ pathto(root_doc)|e }}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

title="{{ docstitle|striptags }}">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
title="{{ docstitle|striptags }}">
title="{{ docstitle|striptags|e }}">

{{ docstitle|e }}
</a>
</h3>
{%- endif %}
</div>
{{ toc }}
</div>
Loading