Skip to content

Commit e2a8a2d

Browse files
authored
Unhide hidden tables of contents for readthedocs (#82)
The tables of contents added to the stdlib-reference repo for use on readthedocs were not hidden on GitHub pages. Wrapping them in HTML comments hides them, but they need to be unhidden in order for RTD to be able to use the TOCs, so this change adds a function to the RTD config file to filter out the wrapper from each doc as it gets processed.
1 parent c263456 commit e2a8a2d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/conf.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,27 @@
88
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
99
import os
1010
import sys
11+
import re
12+
1113
sys.path.insert(0, os.path.abspath('.')) # For finding _ext
1214
sys.path.insert(0, os.path.abspath('..'))
1315

16+
def source_read_handler(app, docname, source):
17+
content = source[0]
18+
# Regex to find the comment block and extract its content
19+
pattern = re.compile(r'<!-- RTD-TOC-START\s*(.*?)\s*RTD-TOC-END -->', re.DOTALL)
20+
21+
def uncomment_toc(match):
22+
return match.group(1) # Return only the content inside the comments
23+
24+
# Replace the comment block with its uncommented content
25+
new_content = pattern.sub(uncomment_toc, content)
26+
source[0] = new_content
27+
28+
def setup(app):
29+
# Connect the handler to the 'source-read' event
30+
app.connect('source-read', source_read_handler)
31+
1432
project = 'Slang Documentation'
1533
author = 'Chris Cummings, Benedikt Bitterli, Sai Bangaru, Yong Hei, Aidan Foster'
1634
release = '0.1.0'
@@ -76,4 +94,4 @@
7694
}
7795

7896
# Use default Furo sidebar configuration - remove custom sidebar
79-
# html_sidebars = {} # Let Furo use its defaults
97+
# html_sidebars = {} # Let Furo use its defaults

0 commit comments

Comments
 (0)