Given a row of text, build table cells.
(self, row: str, parent: etree.Element, align: Sequence[str | None])
| 124 | count -= 1 |
| 125 | |
| 126 | def _build_row(self, row: str, parent: etree.Element, align: Sequence[str | None]) -> None: |
| 127 | """ Given a row of text, build table cells. """ |
| 128 | tr = etree.SubElement(parent, 'tr') |
| 129 | tag = 'td' |
| 130 | if parent.tag == 'thead': |
| 131 | tag = 'th' |
| 132 | cells = self._split_row(row) |
| 133 | # We use align here rather than cells to ensure every row |
| 134 | # contains the same number of columns. |
| 135 | for i, a in enumerate(align): |
| 136 | c = etree.SubElement(tr, tag) |
| 137 | try: |
| 138 | c.text = cells[i].strip(' ') |
| 139 | except IndexError: # pragma: no cover |
| 140 | c.text = "" |
| 141 | if a: |
| 142 | if self.config['use_align_attribute']: |
| 143 | c.set('align', a) |
| 144 | else: |
| 145 | c.set('style', f'text-align: {a};') |
| 146 | |
| 147 | def _split_row(self, row: str) -> list[str]: |
| 148 | """ split a row of text into list of cells. """ |
no test coverage detected