def METHOD_NAME(infile, debug):
    topics_data = []
    commands_data = []
    f = open(infile)
    for line in f:
        if line.startswith('[['):
            line = line[2:-3]  # strip [[ and ]]\n
            info, short_help = line.split(',', 1)
            short_help = short_help.strip()
            info_split = info.split('_')
            if info_split[0] == 'topics':
                if len(info_split) == 2:
                    topics_data.append((1, short_help, info))
                elif len(info_split) >= 3:
                    topics_data.append((2, short_help, info))
            elif info_split[0] == 'cmdhelp':
                if len(info_split) == 2:
                    commands_data.append((2, info_split[1], info))
                elif len(info_split) >= 3:
                    commands_data.append((3, '_'.join(info_split[2:]), info))
    toc = ''
    if len(topics_data) > 0 or len(commands_data) > 0:
        toc = '<div id="toc">\n'
        for depth, text, link in topics_data:
            toc += '<div class="toclevel%s"><a href="#%s">%s</a></div>\n' % (
                depth, link, text)
        for depth, text, link in commands_data:
            toc += '<div class="toclevel%s"><a href="#%s">%s</a></div>\n' % (
                depth, link, text)
        toc += '</div>\n'
    return toc