

def build_list(li_nodes, meta_data):
    '\n    Build the list structure and return the root list\n    '
    ol_dict = {
        
    }
    current_ilvl = (- 1)
    current_numId = (- 1)
    current_ol = None
    root_ol = None
    visited_nodes = []
    list_contents = []

    def _build_li(list_contents):
        data = '<br />'.join((t for t in list_contents if (t is not None)))
        return etree.XML(('<li>%s</li>' % data))

    def _build_non_li_content(el, meta_data):
        w_namespace = get_namespace(el, 'w')
        if (el.tag == ('%stbl' % w_namespace)):
            (new_el, visited_nodes) = build_table(el, meta_data)
            return (etree.tostring(new_el), visited_nodes)
        elif (el.tag == ('%sp' % w_namespace)):
            return (get_element_content(el, meta_data), [el])
        if has_text(el):
            raise UnintendedTag(('Did not expect %s' % el.tag))

    def _merge_lists(ilvl, current_ilvl, ol_dict, current_ol):
        for i in reversed(range(ilvl, current_ilvl)):
            if (i not in ol_dict):
                continue
            if (ol_dict[i] is not current_ol):
                if (ol_dict[i] is current_ol):
                    continue
                ol_dict[i][(- 1)].append(current_ol)
                current_ol = ol_dict[i]
        for key in list(ol_dict):
            if (key > ilvl):
                del ol_dict[key]
        return current_ol
    for li_node in li_nodes:
        w_namespace = get_namespace(li_node, 'w')
        if (not is_li(li_node, meta_data)):
            (new_el, el_visited_nodes) = _build_non_li_content(li_node, meta_data)
            list_contents.append(new_el)
            visited_nodes.extend(el_visited_nodes)
            continue
        if list_contents:
            li_el = _build_li(list_contents)
            list_contents = []
            current_ol.append(li_el)
        list_contents.append(get_element_content(li_node, meta_data))
        ilvl = get_ilvl(li_node, w_namespace)
        numId = get_numId(li_node, w_namespace)
        list_type = get_ordered_list_type(meta_data, numId, ilvl)
        if ((ilvl > current_ilvl) or (numId != current_numId)):
            ol_dict[ilvl] = create_list(list_type)
            current_ol = ol_dict[ilvl]
            current_ilvl = ilvl
            current_numId = numId
        else:
            current_ol = _merge_lists(ilvl=ilvl, current_ilvl=current_ilvl, ol_dict=ol_dict, current_ol=current_ol)
        if (root_ol is None):
            root_ol = current_ol
        if (ilvl in ol_dict):
            current_ol = ol_dict[ilvl]
        elif (current_ol is not root_ol):
            root_ol[(- 1)].append(current_ol)
            current_ol = create_list(list_type)
        visited_nodes.extend(list(li_node.iter()))
    if list_contents:
        li_el = _build_li(list_contents)
        list_contents = []
        current_ol.append(li_el)
    current_ol = _merge_lists(ilvl=0, current_ilvl=current_ilvl, ol_dict=ol_dict, current_ol=current_ol)
    return (root_ol, visited_nodes)

dataset/ETHPy150Open PolicyStat/docx2html/docx2html/core.py build_list/original