def to_anchor_id(text: str) -> str:
    """
    Converts `text` to an anchor ID.

    This method is intended to be compatible with GitHub's method of converting heading
    text to anchors for tables of content.
    """

    a = ""
    for c in text:
        if c in [" ", "-"]:
            a += "-"
        elif str.isalnum(c):
            a += c.lower()
    return a