Skip to content

Commit 4767812

Browse files
committed
[singlehtml]: append docname to section id
1 parent 1d6379e commit 4767812

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Contributors
7272
* Joel Wurtz -- cellspanning support in LaTeX
7373
* John Waltman -- Texinfo builder
7474
* Jon Dufresne -- modernisation
75+
* Jorge Marques -- singlehtml unique section ids
7576
* Josip Dzolonga -- coverage builder
7677
* Juan Luis Cano Rodríguez -- new tutorial (2021)
7778
* Julien Palard -- Colspan and rowspan in text builder

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ Bugs fixed
118118
for objects documented as ``:py:data:`` to be hyperlinked in function signatures.
119119
* #13858: doctest: doctest blocks are now correctly added to a group defined by the
120120
configuration variable ``doctest_test_doctest_blocks``.
121-
121+
* #13739: singlehtml builder: make section ids unique by appending the docname,
122+
matching ``sphinx/environment/adapters/toctree.py``'s ``_resolve_toctree()``
123+
format. E.g., ``id3`` becomes ``document-path/to/doc#id3``.
122124

123125
Testing
124126
-------

sphinx/writers/html5.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from sphinx.util.images import get_image_size
1818

1919
if TYPE_CHECKING:
20-
from docutils.nodes import Element, Node, Text
20+
from docutils.nodes import Element, Node, Text, section
2121

2222
from sphinx.builders import Builder
2323
from sphinx.builders.html import StandaloneHTMLBuilder
@@ -497,6 +497,15 @@ def depart_term(self, node: Element) -> None:
497497

498498
self.body.append('</dt>')
499499

500+
def visit_section(self, node: section) -> None:
501+
if self.builder.name == 'singlehtml' and node['ids']:
502+
docname = self.docnames[-1]
503+
node['ids'][0] = 'document-' + docname + '#' + node['ids'][0]
504+
super().visit_section(node)
505+
506+
def depart_section(self, node: section) -> None:
507+
super().depart_section(node)
508+
500509
# overwritten
501510
def visit_title(self, node: nodes.title) -> None:
502511
if (

0 commit comments

Comments
 (0)