def process_text_block(self, tag): tb = self.parsed_objects[tag.get('objid')] for item in tag.contents: if hasattr(item, 'name'): if item.name == 'p': tb.append(self.process_paragraph(item)) elif item.name == 'cr': tb.append(CR()) elif item.name == 'charbutton': # BookDesigner does this p = Paragraph() tb.append(p) elem = self.text_tag_to_element(item) self.process_text_element(item, elem) p.append(elem)
def process_paragraph(self, tag): p = Paragraph() contents = [i for i in tag.contents] if contents: if isinstance(contents[0], NavigableString): contents[0] = contents[0].string.lstrip() for item in contents: if isinstance(item, basestring): p.append(item) elif isinstance(item, NavigableString): p.append(item.string) else: elem = self.text_tag_to_element(item) p.append(elem) self.process_text_element(item, elem) return p