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

Method _build_row

markdown/extensions/tables.py:126–145  ·  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

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. """

Callers 1

runMethod · 0.95

Calls 2

_split_rowMethod · 0.95
setMethod · 0.80

Tested by

no test coverage detected