Split "| a | b | | c | d | | e | f |" into separate rows
(line: string)
| 127 | |
| 128 | /** Split "| a | b | | c | d | | e | f |" into separate rows */ |
| 129 | function splitCrammedRows(line: string): string[] { |
| 130 | // Strategy: split by "| |" which is the boundary between rows |
| 131 | const parts = line.split(/\|\s*\|/); |
| 132 | if (parts.length <= 2) return [line]; // normal single row has 2 empty parts at edges |
| 133 | |
| 134 | const rows: string[] = []; |
| 135 | let current = ''; |
| 136 | for (let i = 0; i < parts.length; i++) { |
| 137 | const part = parts[i].trim(); |
| 138 | if (part === '' && current) { |
| 139 | // End of a row |
| 140 | rows.push('| ' + current + ' |'); |
| 141 | current = ''; |
| 142 | } else if (part) { |
| 143 | current = current ? current + ' | ' + part : part; |
| 144 | } |
| 145 | } |
| 146 | if (current) rows.push('| ' + current + ' |'); |
| 147 | |
| 148 | return rows.length > 1 ? rows : [line]; |
| 149 | } |
| 150 | |
| 151 | function isTableRow(line: string): boolean { |
| 152 | if (!line) return false; |