MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / _build_row

Method _build_row

markdown/extensions/tables.py:129–148  ·  view source on GitHub ↗

Given a row of text, build table cells.

(self, row: str, parent: etree.Element, align: Sequence[str | None])

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.95

Calls 2

_split_rowMethod · 0.95
setMethod · 0.80

Tested by

no test coverage detected