MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / run

Method run

markdown/extensions/tables.py:30–56  ·  view source on GitHub ↗

Parse a table block and build table.

(self, parent, blocks)

Source from the content-addressed store, hash-verified

28 rows[1][0] in ['|', ':', '-'])
29
30 def run(self, parent, blocks):
31 """ Parse a table block and build table. """
32 block = blocks.pop(0).split('\n')
33 header = block[:2]
34 rows = block[2:]
35 # Get format type (bordered by pipes or not)
36 border = False
37 if header[0].startswith('|'):
38 border = True
39 # Get alignment of columns
40 align = []
41 for c in self._split_row(header[1], border):
42 if c.startswith(':') and c.endswith(':'):
43 align.append('center')
44 elif c.startswith(':'):
45 align.append('left')
46 elif c.endswith(':'):
47 align.append('right')
48 else:
49 align.append(None)
50 # Build table
51 table = etree.SubElement(parent, 'table')
52 thead = etree.SubElement(table, 'thead')
53 self._build_row(header[0], thead, align, border)
54 tbody = etree.SubElement(table, 'tbody')
55 for row in rows:
56 self._build_row(row, tbody, align, border)
57
58 def _build_row(self, row, parent, align, border):
59 """ Given a row of text, build table cells. """

Callers

nothing calls this directly

Calls 5

_split_rowMethod · 0.95
_build_rowMethod · 0.95
splitMethod · 0.45
popMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected