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

Method test

markdown/extensions/tables.py:51–85  ·  view source on GitHub ↗

Ensure first two rows (column header and separator row) are valid table rows. Keep border check and separator row do avoid repeating the work.

(self, parent: etree.Element, block: str)

Source from the content-addressed store, hash-verified

49 super().__init__(parser)
50
51 def test(self, parent: etree.Element, block: str) -> bool:
52 """
53 Ensure first two rows (column header and separator row) are valid table rows.
54
55 Keep border check and separator row do avoid repeating the work.
56 """
57 is_table = False
58 rows = [row.strip(' ') for row in block.split('\n')]
59 if len(rows) > 1:
60 header0 = rows[0]
61 self.border = PIPE_NONE
62 if header0.startswith('|'):
63 self.border |= PIPE_LEFT
64 if self.RE_END_BORDER.search(header0) is not None:
65 self.border |= PIPE_RIGHT
66 row = self._split_row(header0)
67 row0_len = len(row)
68 is_table = row0_len > 1
69
70 # Each row in a single column table needs at least one pipe.
71 if not is_table and row0_len == 1 and self.border:
72 for index in range(1, len(rows)):
73 is_table = rows[index].startswith('|')
74 if not is_table:
75 is_table = self.RE_END_BORDER.search(rows[index]) is not None
76 if not is_table:
77 break
78
79 if is_table:
80 row = self._split_row(rows[1])
81 is_table = (len(row) == row0_len) and set(''.join(row)) <= set('|:- ')
82 if is_table:
83 self.separator = row
84
85 return is_table
86
87 def run(self, parent: etree.Element, blocks: list[str]) -> None:
88 """ Parse a table block and build table. """

Callers

nothing calls this directly

Calls 1

_split_rowMethod · 0.95

Tested by

no test coverage detected