Skip to content

Commit 9a3bb92

Browse files
committed
docs: fix sidebar scaffold on section-less pages
Body-class regex required class right after <body>, but pages with a title anchor emit <body id=... class=...>, so toc2 toc-left was never added. Section-less pages (pci-parallel-port, mpg) lost the left margin and TOC arrows. Match attrs before class.
1 parent 77e9f58 commit 9a3bb92

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

docs/src/lang_switcher_postprocess.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,11 @@ def _scaffold_sidebar(content, nav):
397397
"""Section-less pages have no toc2 container; add the body classes and
398398
insert the sidebar div after the page <h1>."""
399399
def body_cls(m):
400-
cls = m.group(1)
401-
return m.group(0) if 'toc2' in cls else f'<body class="{cls} toc2 toc-left"'
402-
content = re.sub(r'<body class="([^"]*)"', body_cls, content, count=1)
400+
attrs, cls = m.group(1), m.group(2)
401+
if 'toc2' in cls:
402+
return m.group(0)
403+
return f'<body{attrs} class="{cls} toc2 toc-left"'
404+
content = re.sub(r'<body\b([^>]*?) class="([^"]*)"', body_cls, content, count=1)
403405
div = f'<div id="toc" class="toc2">{nav}</div>\n'
404406
return re.sub(r'(<div id="header">.*?</h1>\s*)',
405407
lambda m: m.group(1) + div, content, count=1, flags=re.DOTALL)

0 commit comments

Comments
 (0)