[docs/7.10.0] selector.py: Make ids even more unique for selected content (#5765)

This commit is contained in:
peterjunpark
2025-12-11 17:47:58 -05:00
committed by GitHub
parent 5f6018027b
commit e88e961519
2 changed files with 22 additions and 7 deletions

View File

@@ -256,8 +256,9 @@ class SelectedContent(nodes.General, nodes.Element):
id_attr = ""
heading_elem = ""
combined_show_when = node.get("combined-show-when", show_when)
if heading:
id_attr = nodes.make_id(f"{heading}-{show_when}")
id_attr = nodes.make_id(f"{heading}-{combined_show_when}")
heading_elem = (
f'<h{heading_level} class="rocm-docs-custom-heading">'
@@ -302,9 +303,20 @@ class SelectedContentDirective(SphinxDirective):
node["show-when"] = self.arguments[0]
node["id"] = self.options.get("id", "")
node["class"] = self.options.get("class", "")
node["heading"] = self.options.get("heading", "") # empty string if none
node["heading"] = self.options.get("heading", "")
node["heading-level"] = self.options.get("heading-level", None)
# Collect parent show-whens (if nested)
# to create a completely unique id
parent_show_whens = []
for ancestor in self.state.parent.traverse(include_self=True):
if isinstance(ancestor, SelectedContent) and "show-when" in ancestor:
parent_show_whens.append(ancestor["show-when"])
# Compose combined show-when chain
combined_show_when = "+".join(parent_show_whens + [node["show-when"]])
node["combined-show-when"] = combined_show_when
# Parse nested content
self.state.nested_parse(self.content, self.content_offset, node)
return [node]