def test_table_cell_classes(): """Test the table cell classes.""" tree = parse('||<cellclass=foo>1||<bar>2||') assert tree == nodes.Document([ nodes.Table([ nodes.TableRow([ nodes.TableCell([nodes.Text('1')], class_='foo'), nodes.TableCell([nodes.Text('2')], class_='bar') ]) ]) ])
def test_table_row_classes(): """Test the table row class assignments.""" tree = parse('||<foo>1||2||3') assert tree == nodes.Document([ nodes.Table([ nodes.TableRow([ nodes.TableCell([nodes.Text('1')]), nodes.TableCell([nodes.Text('2')]), nodes.TableCell([nodes.Text('3')]) ], class_='foo') ]) ])
def test_span_table(): """Test tables with col/rowspans.""" tree = parse('||<-2>1||<|2>2||\n||3||4||') assert tree == nodes.Document([ nodes.Table([ nodes.TableRow([ nodes.TableCell([nodes.Text('1')], colspan=2), nodes.TableCell([nodes.Text('2')], rowspan=2) ]), nodes.TableRow([ nodes.TableCell([nodes.Text('3')]), nodes.TableCell([nodes.Text('4')]) ]) ]) ])
def test_table_alignment(): """Check if table alignment parameters work.""" tree = parse('||<:~>1||<(v>2||<)^>3||') assert tree == nodes.Document([ nodes.Table([ nodes.TableRow([ nodes.TableCell([nodes.Text('1')], align='center', valign='middle'), nodes.TableCell([nodes.Text('2')], align='left', valign='bottom'), nodes.TableCell([nodes.Text('3')], align='right', valign='top') ]) ]) ])
def test_simple_table(): """Test the simple table markup.""" tree = parse('||1||2||3||\n||4||5||6||') assert tree == nodes.Document([ nodes.Table([ nodes.TableRow([ nodes.TableCell([nodes.Text('1')]), nodes.TableCell([nodes.Text('2')]), nodes.TableCell([nodes.Text('3')]) ]), nodes.TableRow([ nodes.TableCell([nodes.Text('4')]), nodes.TableCell([nodes.Text('5')]), nodes.TableCell([nodes.Text('6')]) ]) ]) ])
def parse_table(self, stream): """ Parse a table. Contrary to moin we have extended support for attribute sections (``<foo, bar=baz>``) which means that table delimiters are supported inside that section. Also all attributes in such a section are German. Returns a `Table` node. """ def attach_defs(): if stream.current.type in 'table_def_begin': stream.next() args, kwargs = self.parse_arguments(stream, 'table_def_end') if stream.current.type == 'table_def_end': stream.next() attrs, args = _parse_align_args(args, kwargs) if cell_type == 'tablefirst': table.class_ = attrs.get('tableclass') or None table.style = filter_style(attrs.get('tablestyle')) or None if cell_type in ('tablefirst', 'rowfirst'): row.class_ = attrs.get('rowclass') or None if not row.class_: row.class_ = u' '.join(args) or None row.style = filter_style(attrs.get('rowstyle')) or None cell.class_ = attrs.get('cellclass') or None cell.style = filter_style(attrs.get('cellstyle')) or None cell.colspan = attrs.get('colspan', 0) cell.rowspan = attrs.get('rowspan', 0) cell.align = attrs.get('align') if cell.align not in ('left', 'right', 'center'): cell.align = None cell.valign = attrs.get('valign') if cell.valign not in ('top', 'middle', 'bottom'): cell.valign = None if cell_type == 'normal': if not cell.class_: cell.class_ = u' '.join(args) or None table = nodes.Table() cell = row = None cell_type = 'tablefirst' while not stream.eof: if stream.current.type == 'table_row_begin': stream.next() cell = nodes.TableCell() row = nodes.TableRow([cell]) table.children.append(row) attach_defs() elif stream.current.type == 'table_col_switch': stream.next() cell_type = 'normal' cell = nodes.TableCell() row.children.append(cell) attach_defs() elif stream.current.type == 'table_row_end': stream.next() cell_type = 'rowfirst' if stream.current.type != 'table_row_begin': break else: cell.children.append(self.parse_node(stream)) return table