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