"""Small text helpers shared by the scanner and the Reddit reader."""
from __future__ import annotations

import re
from html import unescape


def html_to_text(html: str) -> str:
    """A web page as plain reading matter: tags gone, line breaks kept."""
    text = re.sub(r"<(br|/p|/div|/li|/tr)[^>]*>", "\n", html, flags=re.I)
    text = re.sub(r"<[^>]+>", "", text)
    return unescape(text)
