

def run(self, parent, blocks):
    items = self.get_items(blocks.pop(0))
    sibling = self.lastChild(parent)
    if (sibling and (sibling.tag in ['ol', 'ul'])):
        lst = sibling
        if lst[(- 1)].text:
            p = util.etree.Element('p')
            p.text = lst[(- 1)].text
            lst[(- 1)].text = ''
            lst[(- 1)].insert(0, p)
        lch = self.lastChild(lst[(- 1)])
        if ((lch is not None) and lch.tail):
            p = util.etree.SubElement(lst[(- 1)], 'p')
            p.text = lch.tail.lstrip()
            lch.tail = ''
        li = util.etree.SubElement(lst, 'li')
        self.parser.state.set('looselist')
        firstitem = items.pop(0)
        self.parser.parseBlocks(li, [firstitem])
        self.parser.state.reset()
    elif (parent.tag in ['ol', 'ul']):
        lst = parent
    else:
        lst = util.etree.SubElement(parent, self.TAG)
        if ((not self.parser.markdown.lazy_ol) and (self.STARTSWITH != '1')):
            lst.attrib['start'] = self.STARTSWITH
    self.parser.state.set('list')
    for item in items:
        if item.startswith((' ' * self.tab_length)):
            self.parser.parseBlocks(lst[(- 1)], [item])
        else:
            li = util.etree.SubElement(lst, 'li')
            self.parser.parseBlocks(li, [item])
    self.parser.state.reset()

dataset/ETHPy150Open darcyliu/storyboard/markdown/blockprocessors.py OListProcessor.run/original