Exemplo n.º 1
0
 def apply_markup(self, rmap, parent=None):
     table = TABLE('\n\t\t')
     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 XPath('./w:tr')(self.tbl):
         tr = TR('\n\t\t\t')
         tr.tail = '\n\t\t'
         table.append(tr)
         for tc in XPath('./w:tc')(row):
             td = TD()
             td.tail = '\n\t\t\t'
             tr.append(td)
             for x in XPath('./w:p|./w:tbl')(tc):
                 if x.tag.endswith('}p'):
                     td.append(rmap[x])
                 else:
                     self.sub_tables[x].apply_markup(rmap, parent=td)
         if len(tr):
             tr[-1].tail = '\n\t\t'
     if len(table):
         table[-1].tail = '\n\t'
Exemplo n.º 2
0
 def apply_markup(self, rmap, parent=None):
     table = TABLE('\n\t\t')
     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 XPath('./w:tr')(self.tbl):
         tr = TR('\n\t\t\t')
         tr.tail = '\n\t\t'
         table.append(tr)
         for tc in XPath('./w:tc')(row):
             td = TD()
             td.tail = '\n\t\t\t'
             tr.append(td)
             for x in XPath('./w:p|./w:tbl')(tc):
                 if x.tag.endswith('}p'):
                     td.append(rmap[x])
                 else:
                     self.sub_tables[x].apply_markup(rmap, parent=td)
         if len(tr):
             tr[-1].tail = '\n\t\t'
     if len(table):
         table[-1].tail = '\n\t'
Exemplo n.º 3
0
    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))
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
 def apply_markup(self, object_map):
     rmap = {v:k for k, v in object_map.iteritems()}
     for tbl, blocks in self.tables.iteritems():
         if not blocks:
             continue
         parent = rmap[blocks[0]].getparent()
         table = TABLE('\n\t\t')
         idx = parent.index(rmap[blocks[0]])
         parent.insert(idx, table)
         for row in XPath('./w:tr')(tbl):
             tr = TR('\n\t\t\t')
             tr.tail = '\n\t\t'
             table.append(tr)
             for tc in XPath('./w:tc')(row):
                 td = TD()
                 td.tail = '\n\t\t\t'
                 tr.append(td)
                 for p in XPath('./w:p')(tc):
                     block = rmap[p]
                     td.append(block)
             if len(tr):
                 tr[-1].tail = '\n\t\t'
         if len(table):
             table[-1].tail = '\n\t'