Parse a table block and build table.
(self, parent, blocks)
| 28 | rows[1][0] in ['|', ':', '-']) |
| 29 | |
| 30 | def run(self, parent, blocks): |
| 31 | """ Parse a table block and build table. """ |
| 32 | block = blocks.pop(0).split('\n') |
| 33 | header = block[:2] |
| 34 | rows = block[2:] |
| 35 | # Get format type (bordered by pipes or not) |
| 36 | border = False |
| 37 | if header[0].startswith('|'): |
| 38 | border = True |
| 39 | # Get alignment of columns |
| 40 | align = [] |
| 41 | for c in self._split_row(header[1], border): |
| 42 | if c.startswith(':') and c.endswith(':'): |
| 43 | align.append('center') |
| 44 | elif c.startswith(':'): |
| 45 | align.append('left') |
| 46 | elif c.endswith(':'): |
| 47 | align.append('right') |
| 48 | else: |
| 49 | align.append(None) |
| 50 | # Build table |
| 51 | table = etree.SubElement(parent, 'table') |
| 52 | thead = etree.SubElement(table, 'thead') |
| 53 | self._build_row(header[0], thead, align, border) |
| 54 | tbody = etree.SubElement(table, 'tbody') |
| 55 | for row in rows: |
| 56 | self._build_row(row, tbody, align, border) |
| 57 | |
| 58 | def _build_row(self, row, parent, align, border): |
| 59 | """ Given a row of text, build table cells. """ |
nothing calls this directly
no test coverage detected