def _tag_encloses_foreign_namespace(tag: str) -> bool:
    """
    Checks whether the tag encloses a foreign namespace (MathML or SVG).

    https://html.spec.whatwg.org/multipage/syntax.html#foreign-elements
    """
    return tag.lower() in ("math", "svg")