MIC-04-2 some progress

My first pass -- taking a recursive approach:

def panflute_to_bike_etree(pfe) -> ET.Element:
    """
    pfe: panflute element    
    base_header_level: the base header level to use for the document
    TO DO: handle different header levels -- might need to abandon this approach in favor of non-recursive approach with a manual stack
    """

    if is_inline_or_contentless(pfe):
        p_elem = ET.Element("p")
        p_elem.text = pf.stringify(pfe).strip()
        return p_elem
    else:
        if pfe.tag == "Doc":
            etree = empty_bike_etree()
            ul_elem = etree.xpath("//ul")[0]
        else:
            ul_elem = ET.Element("ul")

        try:
            for c in pfe.content:
                e = panflute_to_bike_etree(c)
                li_elem = ET.SubElement(ul_elem, "li")
                li_elem.append(e)
        except AttributeError:
            pass
        else:
            if pfe.tag == "Doc":
                etree = add_ids_to_bike_etree(etree)
                return etree
            else:
                return ul_elem

Leave a Reply

Only people in my network can comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.