diff --git a/sphinx/ext/autosectionlabel.py b/sphinx/ext/autosectionlabel.py index 02e2e401460..c5f9ca376be 100644 --- a/sphinx/ext/autosectionlabel.py +++ b/sphinx/ext/autosectionlabel.py @@ -28,6 +28,7 @@ def get_node_depth(node: Node) -> int: i += 1 return i + def get_node_parents(node: Node) -> list[str]: parents = [] cur_node = node @@ -38,6 +39,7 @@ def get_node_parents(node: Node) -> list[str]: parents.append(ref_name) return parents + def register_sections_as_label(app: Sphinx, document: Node) -> None: domain = app.env.domains.standard_domain for node in document.findall(nodes.section): @@ -55,7 +57,7 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None: id_array.reverse() id_array.append(ref_name) name = nodes.fully_normalize_name(':'.join(id_array)) - labelid = make_id(app.env, document, '', '.'.join(id_array)) + labelid = make_id(app.env, node.document, '', '.'.join(id_array)) else: name = nodes.fully_normalize_name(docname + ':' + ref_name) else: