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

Method run

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

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