Skip to content

Commit 705703d

Browse files
committed
docs: render markdown headings relative to their section
sphinx-markdown-builder pins rubric and option/signature headings to level 3 while section titles use their absolute nesting depth. Nested sphinx-click and sphinxcontrib-autoprogram sections therefore jump from level 3 to 5 in the generated markdown, which the aggregated docs reject (gldq HEAD-SKIP). Override the markdown translator so those headings are rendered one level below the enclosing section, keeping the API class/method layout unchanged. Signed-off-by: Eike Waldt <waldt@b1-systems.de> On-behalf-of: SAP <eike.waldt@sap.com> Assisted-by: Kilo:claude-sonnet-4-6
1 parent e7e6d8a commit 705703d

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎docs/conf.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1+
from typing import Any
2+
13
from sphinx.application import Sphinx
24

5+
6+
def _register_relative_headings(app: Sphinx) -> None:
7+
try:
8+
from sphinx_markdown_builder.contexts import TitleContext
9+
from sphinx_markdown_builder.translator import (
10+
MarkdownTranslator,
11+
pushing_context,
12+
)
13+
except ImportError:
14+
return
15+
16+
class SectionRelativeMarkdownTranslator(MarkdownTranslator): # type: ignore[misc]
17+
"""Render rubric and signature headings relative to their section.
18+
19+
sphinx-markdown-builder pins these headings to level 3 while section
20+
titles use their absolute nesting depth. Nested sphinx-click and
21+
sphinxcontrib-autoprogram sections then jump from level 3 to 5, which
22+
breaks the aggregated documentation (gldq HEAD-SKIP).
23+
"""
24+
25+
@pushing_context
26+
def visit_rubric(self, _node: Any) -> None:
27+
self._push_context(TitleContext(self.status.section_level + 1))
28+
29+
@pushing_context
30+
def visit_desc_signature(self, node: Any) -> None:
31+
if self.config.markdown_anchor_signatures:
32+
for anchor in node.get("ids", []):
33+
self._add_anchor(anchor)
34+
level = self.status.section_level + 1
35+
if node.get("class"):
36+
level += 1
37+
self._push_context(TitleContext(level))
38+
39+
app.set_translator("markdown", SectionRelativeMarkdownTranslator, override=True)
40+
41+
342
# Configuration file for the Sphinx documentation builder.
443
#
544
# For the full list of built-in configuration values, see the documentation:
@@ -61,3 +100,4 @@
61100
# Add custom CSS
62101
def setup(app: Sphinx) -> None:
63102
app.add_css_file("custom.css")
103+
_register_relative_headings(app)

0 commit comments

Comments
 (0)