Split lines into alternating non-table and table blocks. Returns list of ('text'|'table', [lines]) tuples.
(lines: list[str])
| 31 | |
| 32 | |
| 33 | def split_into_table_blocks(lines: list[str]) -> list[tuple[str, list[str]]]: |
| 34 | """ |
| 35 | Split lines into alternating non-table and table blocks. |
| 36 | Returns list of ('text'|'table', [lines]) tuples. |
| 37 | """ |
| 38 | blocks = [] |
| 39 | current_type = None |
| 40 | current = [] |
| 41 | |
| 42 | for line in lines: |
| 43 | in_table = line.startswith('|') |
| 44 | block_type = 'table' if in_table else 'text' |
| 45 | if block_type != current_type: |
| 46 | if current: |
| 47 | blocks.append((current_type, current)) |
| 48 | current_type = block_type |
| 49 | current = [line] |
| 50 | else: |
| 51 | current.append(line) |
| 52 | |
| 53 | if current: |
| 54 | blocks.append((current_type, current)) |
| 55 | return blocks |
| 56 | |
| 57 | |
| 58 | def is_toc_table(table_lines: list[str]) -> bool: |
no outgoing calls
no test coverage detected