sphinx/tests/test_builders/xpath_html_util.py
James Addison 0bfaadf6c9
singlehtml: Use same-document hyperlinks for internal project references (#12551)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-08-11 22:43:48 +01:00

20 lines
809 B
Python

from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Sequence
from xml.etree.ElementTree import Element
def _intradocument_hyperlink_check(nodes: Sequence[Element]) -> None:
"""Confirm that a series of nodes are all HTML hyperlinks to the current page"""
assert nodes, 'Expected at least one node to check'
for node in nodes:
assert node.tag == 'a', 'Attempted to check hyperlink on a non-anchor element'
href = node.attrib.get('href')
# Allow Sphinx index and table hyperlinks to be non-same-document, as exceptions.
if href in {'genindex.html', 'py-modindex.html', 'search.html'}:
continue
assert not href or href.startswith('#'), 'Hyperlink failed same-document check'