def process_into(self, node, obj): """ Process a BeautifulSoup node and fill its elements into a pyth base object. """ if isinstance(node, BeautifulSoup.NavigableString): text = self.process_text(node) if text: obj.append(text) return if node.name == 'p': # add a new paragraph into the pyth object new_obj = document.Paragraph() obj.append(new_obj) obj = new_obj elif node.name == 'ul': # add a new list new_obj = document.List() obj.append(new_obj) obj = new_obj elif node.name == 'li': # add a new list entry new_obj = document.ListEntry() obj.append(new_obj) obj = new_obj for child in node: self.process_into(child, obj)
def handle_Para(self, para): self.flushParagraph() prevListLevel = self.listLevel self.listLevel = para.listLevel if self.listLevel > prevListLevel: l = document.List() self.listStack.append(l) elif self.listLevel < prevListLevel: l = self.listStack.pop() self.listStack[-1].append(l) self.block = None