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

Method run

markdown/extensions/tables.py:90–119  ·  view source on GitHub ↗

Parse a table block and build table.

(self, parent: etree.Element, blocks: list[str])

Source from the content-addressed store, hash-verified

88 return is_table
89
90 def run(self, parent: etree.Element, blocks: list[str]) -> None:
91 """ Parse a table block and build table. """
92 block = blocks.pop(0).split('\n')
93 header = block[0].strip(' ')
94 rows = [] if len(block) < 3 else block[2:]
95
96 # Get alignment of columns
97 align: list[str | None] = []
98 for c in self.separator:
99 c = c.strip(' ')
100 if c.startswith(':') and c.endswith(':'):
101 align.append('center')
102 elif c.startswith(':'):
103 align.append('left')
104 elif c.endswith(':'):
105 align.append('right')
106 else:
107 align.append(None)
108
109 # Build table
110 table = etree.SubElement(parent, 'table')
111 thead = etree.SubElement(table, 'thead')
112 self._build_row(header, thead, align)
113 tbody = etree.SubElement(table, 'tbody')
114 if len(rows) == 0:
115 # Handle empty table
116 self._build_empty_row(tbody, align)
117 else:
118 for row in rows:
119 self._build_row(row.strip(' '), tbody, align)
120
121 def _build_empty_row(self, parent: etree.Element, align: Sequence[str | None]) -> None:
122 """Build an empty row."""

Callers

nothing calls this directly

Calls 2

_build_rowMethod · 0.95
_build_empty_rowMethod · 0.95

Tested by

no test coverage detected