Skip to content

Commit 67355b2

Browse files
committed
Toggleable ToC
1 parent 92f3dc5 commit 67355b2

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

pep_sphinx_extensions/pep_processor/html/pep_html_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def get_doc_context(self, docname: str, body: str, _metatags: str) -> dict:
3838
toc_tree = self.env.tocs[docname].deepcopy()
3939
if len(toc_tree[0]) > 1:
4040
toc_tree = toc_tree[0][1] # don't include document title
41+
del toc_tree[0] # remove contents node
4142
for node in toc_tree.findall(nodes.reference):
4243
node["refuri"] = node["anchorname"] or '#' # fix targets
4344
toc = self.render_partial(toc_tree)["fragment"]

pep_sphinx_extensions/pep_processor/html/pep_html_translator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ def depart_label(self, node) -> None:
8989
# Close the def tags
9090
self.body.append("</dt>\n<dd>")
9191

92+
def visit_bullet_list(self, node):
93+
if isinstance(node.parent, nodes.section) and "contents" in node.parent["names"]:
94+
self.body.append("<details><summary>Contents</summary>")
95+
self.context.append("</details>")
96+
super().visit_bullet_list(node)
97+
98+
def depart_bullet_list(self, node):
99+
super().depart_bullet_list(node)
100+
if isinstance(node.parent, nodes.section) and "contents" in node.parent["names"]:
101+
self.body.append(self.context.pop())
102+
92103
def unknown_visit(self, node: nodes.Node) -> None:
93104
"""No processing for unknown node types."""
94105
pass

pep_sphinx_extensions/pep_processor/transforms/pep_contents.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def apply(self) -> None:
1717
if not Path(self.document["source"]).match("pep-*"):
1818
return # not a PEP file, exit early
1919
# Create the contents placeholder section
20-
title = nodes.title("", "", nodes.Text("Contents"))
21-
contents_section = nodes.section("", title)
20+
contents_section = nodes.section("")
2221
if not self.document.has_name("contents"):
2322
contents_section["names"].append("contents")
2423
self.document.note_implicit_target(contents_section)

pep_sphinx_extensions/pep_theme/static/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ pre {
118118
padding: .5rem .75rem;
119119
}
120120

121+
/* Contents rules */
122+
details > summary > h2 {
123+
font-weight: bold;
124+
}
125+
121126
/* Definition list rules */
122127
dl dt {
123128
font-weight: bold;

0 commit comments

Comments
 (0)