Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

singlehtml: Use same-document hyperlinks for internal project references #12551

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
920eed2
[singlehtml] Use same-document hyperlinks in nested/fixed reference U…
jayaddison Jul 12, 2024
56ccf3c
[singlehtml] Add test coverage to check for same-document hyperlinks.
jayaddison Jul 17, 2024
d5dc1db
Revert "[singlehtml] Use same-document hyperlinks in nested/fixed ref…
jayaddison Jul 17, 2024
5367be0
[singlehtml] Fixup: add missing return-type signature.
jayaddison Jul 17, 2024
3bff8c4
Reapply "[singlehtml] Use same-document hyperlinks in nested/fixed re…
jayaddison Jul 17, 2024
6a07e49
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
jayaddison Jul 17, 2024
fb7d4a6
Add CHANGES.rst entry.
jayaddison Jul 17, 2024
3d8a98b
[singlehtml] Tests: rename check function to `_intradocument_check`.
jayaddison Jul 18, 2024
ac94dc8
[singlehtml] Tests: add explanatory assertion failure messages.
jayaddison Jul 18, 2024
933903d
[singlehtml] Tests: add nodes-list non-emptiness check.
jayaddison Jul 18, 2024
943f436
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
jayaddison Jul 18, 2024
74ad42c
[singlehtml] Tests: adjust test coverage strategy; ensure that all `t…
jayaddison Jul 18, 2024
a69d1bf
[singlehtml] Tests: adjust test coverage strategy; ensure that all hy…
jayaddison Jul 18, 2024
d76bed6
[singlehtml] Tests: rectify/clarify name of `_intradocument_check` to…
jayaddison Jul 18, 2024
af5da5d
[singlehtml] Tests: fixup: remove f-string modifier from non-dynamic …
jayaddison Jul 18, 2024
0aab9fe
[singlehtml] Refactor: fixup: relocate `test_toctree` to `test_builde…
jayaddison Jul 18, 2024
8b83df0
[singlehtml] Tests: expand coverage: ensure that external hyperlinks …
jayaddison Jul 18, 2024
ef9e712
[singlehtml] Tests: skip same-doc hyperlink check for a few Sphinx in…
jayaddison Jul 18, 2024
f42cf83
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
jayaddison Jul 30, 2024
c514c4f
Tests: fixup: resolve `FutureWarning` by prepending context-node (dot).
jayaddison Jul 30, 2024
2ffcc4c
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
jayaddison Aug 2, 2024
91734a1
Tests: utils: add assertion-fail message to `_intradocument_hyperlink…
jayaddison Aug 4, 2024
77ae624
Tests: utils: add `_intradocument_hyperlink_check` docstring.
jayaddison Aug 4, 2024
7cb860b
Tests: refactor/rectification: relocate `_introdocument_hyperlink_che…
jayaddison Aug 4, 2024
0328640
Tests: fixup: resolve additional `FutureWarning` by prepending contex…
jayaddison Aug 4, 2024
cf93b47
Tests: refactor: relocate `_introdocument_hyperlink_check` to new `xp…
jayaddison Aug 4, 2024
c209061
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
jayaddison Aug 8, 2024
026648c
Edit CHANGES.rst credit
jayaddison Aug 10, 2024
da1b53d
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
jayaddison Aug 10, 2024
bbeb1e4
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
jayaddison Aug 11, 2024
d8e7f33
Lint fixups: adjust to within `ruff` guidelines
jayaddison Aug 11, 2024
edcafcd
Merge branch 'master' into pr-11970-followup/singlehtml-toctree-refur…
AA-Turner Aug 11, 2024
b1d741a
Fix CHANGES placement
AA-Turner Aug 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Release 7.4.6 (in development)
Bugs fixed
----------

* #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``. (note: continuation of a partial fix added in v7.3.0)
Patch by Eric Norige, James Addison.
jayaddison marked this conversation as resolved.
Show resolved Hide resolved

Release 7.4.5 (released Jul 16, 2024)
=====================================
Expand Down
4 changes: 2 additions & 2 deletions sphinx/builders/singlehtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def get_relative_uri(self, from_: str, to: str, typ: str | None = None) -> str:

def fix_refuris(self, tree: Node) -> None:
# fix refuris with double anchor
fname = self.config.root_doc + self.out_suffix
for refnode in tree.findall(nodes.reference):
if 'refuri' not in refnode:
continue
Expand All @@ -62,7 +61,8 @@ def fix_refuris(self, tree: Node) -> None:
continue
hashindex = refuri.find('#', hashindex + 1)
if hashindex >= 0:
refnode['refuri'] = fname + refuri[hashindex:]
# all references are on the same page...
picnixz marked this conversation as resolved.
Show resolved Hide resolved
refnode['refuri'] = refuri[hashindex:]

def _get_local_toctree(self, docname: str, collapse: bool = True, **kwargs: Any) -> str:
if isinstance(includehidden := kwargs.get('includehidden'), str):
Expand Down
12 changes: 10 additions & 2 deletions tests/test_builders/test_build_html_tocdepth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Test the HTML builder and check output against XPath."""
from collections.abc import Sequence
from xml.etree.ElementTree import Element

import pytest

Expand Down Expand Up @@ -52,9 +54,15 @@ def test_tocdepth(app, cached_etree_parse, fname, path, check, be_found):
check_xpath(cached_etree_parse(app.outdir / fname), fname, path, check, be_found)


def _intradocument(nodes: Sequence[Element]) -> None:
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
for node in nodes:
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
assert 'href' in node.attrib
assert node.attrib['href'].startswith('#')


@pytest.mark.parametrize("expect", [
(".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
(".//li[@class='toctree-l3']/a", '1.2.1. Foo B1', True),
(".//li[@class='toctree-l3']/a[.='1.1.1. Foo A1']", _intradocument),
(".//li[@class='toctree-l3']/a[.='1.2.1. Foo B1']", _intradocument),
(".//li[@class='toctree-l3']/a", '2.1.1. Bar A1', False),
(".//li[@class='toctree-l3']/a", '2.2.1. Bar B1', False),

Expand Down