MCPcopy Index your code
hub / github.com/OWASP/APTS / parse_table_row

Function parse_table_row

scripts/validate_markdown_tables.py:17–74  ·  view source on GitHub ↗
(row: str)

Source from the content-addressed store, hash-verified

15
16
17def parse_table_row(row: str) -> ParsedRow:
18 text = row.strip()
19
20 if text.startswith("|"):
21 text = text[1:]
22
23 if text.endswith("|"):
24 text = text[:-1]
25
26 cells: list[str] = []
27 current: list[str] = []
28 separator_count = 0
29 code_delimiter_length = 0
30 backslash_run = 0
31 index = 0
32
33 while index < len(text):
34 character = text[index]
35
36 if character == "`":
37 run_end = index
38 while run_end < len(text) and text[run_end] == "`":
39 run_end += 1
40
41 run_length = run_end - index
42 if code_delimiter_length == 0:
43 code_delimiter_length = run_length
44 elif run_length == code_delimiter_length:
45 code_delimiter_length = 0
46
47 current.append(text[index:run_end])
48 backslash_run = 0
49 index = run_end
50 continue
51
52 if code_delimiter_length == 0 and character == "|":
53 if backslash_run % 2 == 1:
54 current.append(character)
55 else:
56 cells.append("".join(current).strip())
57 current = []
58 separator_count += 1
59
60 backslash_run = 0
61 index += 1
62 continue
63
64 current.append(character)
65
66 if code_delimiter_length == 0 and character == "\\":
67 backslash_run += 1
68 else:
69 backslash_run = 0
70
71 index += 1
72
73 cells.append("".join(current).strip())
74 return ParsedRow(cells=cells, separator_count=separator_count)

Callers 1

validate_markdown_tablesFunction · 0.85

Calls 1

ParsedRowClass · 0.85

Tested by

no test coverage detected