def filter_soup(soup, mode='html', **kwargs):
    """Turn a multicode block into the correct syntax for minitabs, but only
       in the HTML version."""
    if mode != 'html':
        return
    multicodes = soup.find_all(class_='multicode')
    index1 = 0
    for cb_area in multicodes:
        cb_area['id'] = 'code-%d' % index1
        codetabs_ul = soup.new_tag('ul')
        codetabs_ul['class'] = 'codetabs'
        cb_area.insert(0, codetabs_ul)
        pres = cb_area.find_all('pre')
        index2 = 0
        for pre in pres:
            linkid = 'code-%d-%d' % (index1, index2)
            code_sample_wrapper = soup.new_tag('div', id=linkid)
            code_sample_wrapper['class'] = 'code_sample'
            code_sample_wrapper['style'] = 'position: static;'
            pre.wrap(code_sample_wrapper)
            linkback = soup.new_tag('a', href='#%s' % linkid)
            linkback_li = soup.new_tag('li')
            linkback_li.append(linkback)
            codetabs_ul.append(linkback_li)
            prev_p = code_sample_wrapper.find_previous_sibling('p')
            try:
                label = ''.join(prev_p.em.strings)
            except AttributeError:
                label = 'Code Sample %d-%d' % (index1, index2)
            linkback.string = label
            prev_p.decompose()
            index2 += 1
        index1 += 1
