Skip to content

Use a different CSS class to mark TOC levels as visible #2163

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ nav.page-toc {
display: none;

// So we can manually specify a level as visible in the config
&.visible {
&.pst-show_toc_level {
display: block;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pydata_sphinx_theme/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def add_header_level_recursive(ul, level):
if ul is None:
return
if level <= (context["theme_show_toc_level"] + 1):
ul["class"] = [*ul.get("class", []), "visible"]
ul["class"] = [*ul.get("class", []), "pst-show_toc_level"]
for li in ul("li", recursive=False):
li["class"] = [*li.get("class", []), f"toc-h{level}"]
add_header_level_recursive(li.find("ul", recursive=False), level + 1)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def test_toc_visibility(sphinx_build_factory) -> None:
index_html = sphinx_build.html_tree("index.html")

# The 3rd level headers should be visible, but not the fourth-level
assert "visible" in index_html.select(".toc-h2 ul")[0].attrs["class"]
assert "visible" not in index_html.select(".toc-h3 ul")[0].attrs["class"]
assert "pst-show_toc_level" in index_html.select(".toc-h2 ul")[0].attrs["class"]
assert "pst-show_toc_level" not in index_html.select(".toc-h3 ul")[0].attrs["class"]


def test_icon_links(sphinx_build_factory, file_regression) -> None:
Expand Down
Loading