phml.utils.misc.heading
Utility functions that do something with heading tags.
1"""Utility functions that do something with heading tags.""" 2from re import match 3 4from phml.nodes import Element 5 6__all__ = ["heading_rank"] 7 8 9def heading_rank(node: Element) -> int: 10 """Get the rank of the heading element. 11 12 Example: 13 `h2` yields `2` 14 """ 15 from phml.utils import is_heading # pylint: disable=import-outside-toplevel 16 17 if is_heading(node): 18 rank = match(r"h([1-6])", node.tag).group(1) 19 return int(rank) 20 21 raise TypeError(f"Node must be a heading. Was a {node.type}.{node.tag}")
def
heading_rank(node: phml.nodes.element.Element) -> int:
10def heading_rank(node: Element) -> int: 11 """Get the rank of the heading element. 12 13 Example: 14 `h2` yields `2` 15 """ 16 from phml.utils import is_heading # pylint: disable=import-outside-toplevel 17 18 if is_heading(node): 19 rank = match(r"h([1-6])", node.tag).group(1) 20 return int(rank) 21 22 raise TypeError(f"Node must be a heading. Was a {node.type}.{node.tag}")
Get the rank of the heading element.
Example
h2
yields2