import re


def get_supported_types(soup):
    """
    Extract supported types

    There is a table that stores the supported filetypes. It contains links of
    the form <a href="#filetype">, so we search for the BAM one, the find the
    parent (a <li>) and then it's parent (the <ul>). That will be our list of
    supported filetypes::

        <ol>
            <ul>
                <li><a href="#bam"> <---- (FIND THIS)
                <li><a href="#bigBed">
                ...
            </ul>
            <li>
            <ul>
                <li><a href="#superTrack">...
            </ul>
            <li> (don't care about this one since not in a ul)
    """
    abam = soup.find('a', href=re.compile('#bam'))
    ol = abam.parent.parent.parent.parent
    supported_types = []
    for ul in ol.find_all('ul'):
        for a in ul.find_all('a'):
            ref = a['href'].replace('#', '')

            # some have text like "#bigMaf_-_Multiple_Alignments", so split on
            # the '_'
            ref = ref.split('_')[0]
            supported_types.append(ref)

    # multiWig is not included in this table, but it's considered a type in the
    # divs.
    supported_types.append('multiWig')

    # If a setting pertains to all types, they are not all listed, rather, the
    # "all" type is specified.
    supported_types.append('all')

    return supported_types