Coverage for phml\utils\misc\heading.py: 100%
9 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 11:07 -0600
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 11:07 -0600
1"""Utility functions that do something with heading tags."""
2from re import match
4from phml.nodes import Element
6__all__ = ["heading_rank"]
9def heading_rank(node: Element) -> int:
10 """Get the rank of the heading element.
12 Example:
13 `h2` yields `2`
14 """
15 from phml.utils import is_heading # pylint: disable=import-outside-toplevel
17 if is_heading(node):
18 rank = match(r"h([1-6])", node.tag).group(1)
19 return int(rank)
21 raise TypeError(f"Node must be a heading. Was a {node.type}.{node.tag}")