Beispiel #1
0
 def build_dom_table(self, rows, head=None, cls=None):
     """
     Build a DOM table with data from <rows>.
     """
     table = moin_page.table()
     if cls is not None:
         table.attrib[moin_page('class')] = cls
     if head is not None:
         table_head = moin_page.table_header()
         table_row = moin_page.table_row()
         for idx, cell in enumerate(head):
             table_cell = moin_page.table_cell(children=[cell, ],)
             if rows and len(rows[0]) == len(head):
                 # add "align: right" to heading cell if cell in first data row is numeric
                 self.add_numeric_class(rows[0][idx], table_cell)
             table_row.append(table_cell)
         table_head.append(table_row)
         table.append(table_head)
     table_body = moin_page.table_body()
     for row in rows:
         table_row = moin_page.table_row()
         for cell in row:
             if isinstance(cell, ET.Node) and len(cell) and isinstance(cell[0], unicode) and \
                 len(cell[0].split()) == 1 and len(cell[0]) > WORDBREAK_LEN:
                 # avoid destroying table layout by applying special styling to cells with long file name hyperlinks
                 table_cell = moin_page.table_cell(children=[cell, ], attrib={moin_page.class_: 'moin-wordbreak'})
             elif isinstance(cell, ET.Node):
                 table_cell = moin_page.table_cell(children=[cell, ])
             else:
                 table_cell = moin_page.table_cell(children=[cell, ],)
                 self.add_numeric_class(cell, table_cell)
             table_row.append(table_cell)
         table_body.append(table_row)
     table.append(table_body)
     return table
Beispiel #2
0
    def block_table_repl(self, iter_content, stack, table, table_args=''):
        stack.clear()
        # TODO: table attributes
        elem = moin_page.table()
        stack.push(elem)
        if table_args:
            table_args = _TableArguments()(table_args)
            for key, value in table_args.keyword.iteritems():
                attrib = elem.attrib
                if key in ('class', 'style', 'number-columns-spanned',
                           'number-rows-spanned'):
                    attrib[moin_page(key)] = value

        element = moin_page.table_body()
        stack.push(element)
        lines = _Iter(self.block_table_lines(iter_content),
                      startno=iter_content.lineno)
        element = moin_page.table_row()
        stack.push(element)
        preprocessor_status = []
        for line in lines:
            m = self.tablerow_re.match(line)
            if not m:
                return
            if m.group('newrow'):
                stack.pop_name('table-row')
                element = moin_page.table_row()
                stack.push(element)
            cells = m.group('cells')
            if cells:
                cells = cells.split('||')
                for cell in cells:
                    if stack.top_check('table-cell'):
                        stack.pop()

                    cell = re.split(r'\s*\|\s*', cell)
                    element = moin_page.table_cell()
                    if len(cell) > 1:
                        cell_args = _TableArguments()(cell[0])
                        for key, value in cell_args.keyword.iteritems():
                            attrib = element.attrib
                            if key in ('class', 'style',
                                       'number-columns-spanned',
                                       'number-rows-spanned'):
                                attrib[moin_page(key)] = value
                        cell = cell[1]
                    else:
                        cell = cell[0]
                    stack.push(element)
                    self.preprocessor.push()
                    self.parse_inline(cell, stack, self.inline_re)
                    preprocessor_status = self.preprocessor.pop()
            elif m.group('text'):
                self.preprocessor.push(preprocessor_status)
                self.parse_inline('\n{0}'.format(m.group('text')), stack,
                                  self.inline_re)
                preprocessor_status = self.preprocessor.pop()
        stack.pop_name('table')
Beispiel #3
0
    def block_table_repl(self, iter_content, stack, table):
        stack.clear()

        element = moin_page.table()
        stack.push(element)
        element = moin_page.table_body()
        stack.push(element)

        self.block_table_row(table, stack)

        for line in iter_content:
            match = self.table_re.match(line)
            if not match:
                # Allow the mainloop to take care of the line after a list.
                iter_content.push(line)
                break

            self.block_table_row(match.group('table'), stack)

        stack.clear()
Beispiel #4
0
    def block_table_repl(self, iter_content, stack, table):
        stack.clear()

        element = moin_page.table(attrib={moin_page('class'): u'moin-wiki-table'})
        stack.push(element)
        stack.push(moin_page.table_body())

        self.block_table_row(table, stack, element)

        for line in iter_content:
            match = self.table_re.match(line)
            if not match:
                match = self.header_footer_re.match(line)
                if match:
                    # this is a header/body/footer separator: create multiple table_body's, html_out will convert to thead, tbody or tfoot
                    stack.pop()
                    stack.push(moin_page.table_body())
                    continue
                else:
                    # Allow the mainloop to take care of the line after table end.
                    iter_content.push(line)
                    break
            self.block_table_row(match.group('table'), stack, element)
Beispiel #5
0
 def visit_table(self, node):
     self.open_moin_page_node(moin_page.table())
Beispiel #6
0
 def visit_option_list(self, node):
     attrib = {html.class_: 'moin-rst-optionlist'}
     self.open_moin_page_node(moin_page.table(attrib=attrib))
     self.open_moin_page_node(moin_page.table_body())
Beispiel #7
0
 def visit_docinfo(self, node):
     self.open_moin_page_node(moin_page.table())
     self.open_moin_page_node(moin_page.table_body())