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')
def block_table_repl(self, iter_content, stack, table): stack.clear() element = moin_page.table(attrib={moin_page('class'): '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)
def build_dom_calendar_table(rows, head=None, caption=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 caption is not None: table_caption = moin_page.caption() table_caption.append(caption) table.append(table_caption) if head is not None: table_head = moin_page.table_header() table_row = moin_page.table_row() for _idx, cell_tuple in enumerate(head): (cell, cell_class) = cell_tuple table_cell = moin_page.table_cell(children=[cell]) table_cell.attrib[moin_page('class')] = cell_class 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_tuple in row: # - cell content # - href for <a> tag # - CSS class for <td> tag (cell, cell_addr, cell_class) = cell_tuple # empty cell if not cell_addr: table_cell = moin_page.table_cell(children=[cell]) table_cell.attrib[moin_page('class')] = cell_class # cell with link to calendar else: table_a = moin_page.a(attrib={xlink.href: Iri(cell_addr)}, children=[cell]) table_cell = moin_page.table_cell(children=[table_a]) table_cell.attrib[moin_page('class')] = cell_class table_row.append(table_cell) table_body.append(table_row) table.append(table_body) return table
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], str) 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
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()
def visit_tbody(self, node): self.open_moin_page_node(moin_page.table_body())
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())
def visit_docinfo(self, node): self.open_moin_page_node(moin_page.table()) self.open_moin_page_node(moin_page.table_body())