def apply_markup(self, rmap, page, parent=None): table = TABLE('\n\t\t') if self.bidi: table.set('dir', 'rtl') self.table_style.page = page style_map = {} if parent is None: try: first_para = rmap[next(iter(self))] except StopIteration: return parent = first_para.getparent() idx = parent.index(first_para) parent.insert(idx, table) else: parent.append(table) for row in self.namespace.XPath('./w:tr')(self.tbl): tr = TR('\n\t\t\t') style_map[tr] = self.style_map[row] tr.tail = '\n\t\t' table.append(tr) for tc in self.namespace.XPath('./w:tc')(row): td = TD() style_map[td] = s = self.style_map[tc] if s.col_span is not inherit: td.set('colspan', type('')(s.col_span)) if s.row_span is not inherit: td.set('rowspan', type('')(s.row_span)) td.tail = '\n\t\t\t' tr.append(td) for x in self.namespace.XPath('./w:p|./w:tbl')(tc): if x.tag.endswith('}p'): td.append(rmap[x]) else: self.sub_tables[x].apply_markup(rmap, page, parent=td) if len(tr): tr[-1].tail = '\n\t\t' if len(table): table[-1].tail = '\n\t' table_style = self.table_style.css if table_style: table.set('class', self.styles.register(table_style, 'table')) for elem, style in iteritems(style_map): css = style.css if css: elem.set('class', self.styles.register(css, elem.tag))
def apply_markup(self, rmap, page, parent=None): table = TABLE('\n\t\t') if self.bidi: table.set('dir', 'rtl') self.table_style.page = page style_map = {} if parent is None: try: first_para = rmap[next(iter(self))] except StopIteration: return parent = first_para.getparent() idx = parent.index(first_para) parent.insert(idx, table) else: parent.append(table) for row in self.namespace.XPath('./w:tr')(self.tbl): tr = TR('\n\t\t\t') style_map[tr] = self.style_map[row] tr.tail = '\n\t\t' table.append(tr) for tc in self.namespace.XPath('./w:tc')(row): td = TD() style_map[td] = s = self.style_map[tc] if s.col_span is not inherit: td.set('colspan', type('')(s.col_span)) if s.row_span is not inherit: td.set('rowspan', type('')(s.row_span)) td.tail = '\n\t\t\t' tr.append(td) for x in self.namespace.XPath('./w:p|./w:tbl')(tc): if x.tag.endswith('}p'): td.append(rmap[x]) else: self.sub_tables[x].apply_markup(rmap, page, parent=td) if len(tr): tr[-1].tail = '\n\t\t' if len(table): table[-1].tail = '\n\t' table_style = self.table_style.css if table_style: table.set('class', self.styles.register(table_style, 'table')) for elem, style in style_map.iteritems(): css = style.css if css: elem.set('class', self.styles.register(css, elem.tag))
def apply_markup(self, rmap, page, parent=None): table = TABLE("\n\t\t") self.table_style.page = page style_map = {} if parent is None: try: first_para = rmap[next(iter(self))] except StopIteration: return parent = first_para.getparent() idx = parent.index(first_para) parent.insert(idx, table) else: parent.append(table) for row in self.namespace.XPath("./w:tr")(self.tbl): tr = TR("\n\t\t\t") style_map[tr] = self.style_map[row] tr.tail = "\n\t\t" table.append(tr) for tc in self.namespace.XPath("./w:tc")(row): td = TD() style_map[td] = s = self.style_map[tc] if s.col_span is not inherit: td.set("colspan", type("")(s.col_span)) if s.row_span is not inherit: td.set("rowspan", type("")(s.row_span)) td.tail = "\n\t\t\t" tr.append(td) for x in self.namespace.XPath("./w:p|./w:tbl")(tc): if x.tag.endswith("}p"): td.append(rmap[x]) else: self.sub_tables[x].apply_markup(rmap, page, parent=td) if len(tr): tr[-1].tail = "\n\t\t" if len(table): table[-1].tail = "\n\t" table_style = self.table_style.css if table_style: table.set("class", self.styles.register(table_style, "table")) for elem, style in style_map.iteritems(): css = style.css if css: elem.set("class", self.styles.register(css, elem.tag))