import requests


def _download_index(category, index_url):
    """
    Download the index.

    :param category: suffixed category, e.g. 'filters', 'templates'
    :param index_url: url to the index. Default: 'https://raw.githubusercontent.com/pandoc-extras/packages/master/<category>.yaml'
    :return: the content of the index, which is in YAML
    """
    if index_url is None:
        index_url = 'https://raw.githubusercontent.com/pandoc-extras/packages/master/{}.yaml'
    url = index_url.format(category)
    r = requests.get(url)
    if r.status_code != 200:
        raise IOError("Cannot download index, error {}".format(r.status_code))
    return r.text