def mimetype_to_fmt(mimetype: str) -> str:
    """Get a format string given a mimetype."""
    if mimetype.startswith("application/vnd.vegalite"):
        return "vega-lite"
    elif mimetype.startswith("application/vnd.vega"):
        return "vega"
    elif mimetype == "application/json":
        return "json"
    elif mimetype == "application/pdf":
        return "pdf"
    elif mimetype == "text/html":
        return "html"
    elif mimetype == "image/png":
        return "png"
    elif mimetype == "image/svg+xml":
        return "svg"
    else:
        raise ValueError(f"Unrecognized mimetype={mimetype!r}")