File: xpath_html_util.py

package info (click to toggle)
sphinx 9.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 28,732 kB
  • sloc: python: 109,394; javascript: 37,318; perl: 449; makefile: 183; sh: 37; xml: 19; ansic: 2
file content (19 lines) | stat: -rw-r--r-- 809 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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'