Skip to content

Commit 413e740

Browse files
authored
🐛 Fix singlehtml target uris to be same-document references (#11970)
Before this change, target_uris would be generated as `index.html#foo`. This makes it difficult to rename the generated document and can require reloading the document when following a link. After this change, they are just `#foo`, which avoids the above problems.
1 parent c7c0200 commit 413e740

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ Bugs fixed
147147
* #12040: HTML Search: Ensure that document titles that are partially-matched by
148148
the user search query are included in search results.
149149
Patch by James Addison.
150+
* #11970: singlehtml builder: make target URIs to be same-document references in
151+
the sense of :rfc:`RFC 3986, §4.4 <3986#section-4.4>`, e.g., ``index.html#foo``
152+
becomes ``#foo``. Patch by eanorige.
150153

151154
Testing
152155
-------

sphinx/builders/singlehtml.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def get_outdated_docs(self) -> str | list[str]: # type: ignore[override]
4141
def get_target_uri(self, docname: str, typ: str | None = None) -> str:
4242
if docname in self.env.all_docs:
4343
# all references are on the same page...
44-
return self.config.root_doc + self.out_suffix + \
45-
'#document-' + docname
44+
return '#document-' + docname
4645
else:
4746
# chances are this is a html_additional_page
4847
return docname + self.out_suffix

0 commit comments

Comments
 (0)