🐛 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.
This commit is contained in:
Eric Norige 2024-04-07 15:08:30 -07:00 committed by GitHub
parent c7c02002e5
commit 413e740dca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

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

View File

@ -41,8 +41,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder):
def get_target_uri(self, docname: str, typ: str | None = None) -> str:
if docname in self.env.all_docs:
# all references are on the same page...
return self.config.root_doc + self.out_suffix + \
'#document-' + docname
return '#document-' + docname
else:
# chances are this is a html_additional_page
return docname + self.out_suffix