from typing import Union
import re


def _header_line(line: str) -> Union[None, tuple]:
    """
    If it is detected as header line, returns its header level and caption.
    Otherwise returns `None`.
    """
    m = re.match(r"^(#+)(.+)", line)
    if m:
        level = len(m.group(1))
        caption = m.group(2)
        return level, caption

    return None