Coverage for phml\utils\misc\heading.py: 33%
9 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-30 09:38 -0600
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-30 09:38 -0600
1from re import match
3from phml.nodes import Element
5__all__ = ["heading_rank"]
8def heading_rank(node: Element) -> int:
9 """Get the rank of the heading element.
11 Example:
12 `h2` yields `2`
13 """
14 from phml.utils import is_heading
16 if is_heading(node):
17 rank = match(r"h([1-6])", node.tag).group(1)
18 return int(rank)
19 else:
20 raise TypeError(f"Node must be a heading. Was a {node.type}.{node.tag}")