MCPcopy Create free account
hub / github.com/enowdev/enowX-Coder / splitCrammedRows

Function splitCrammedRows

src/lib/utils.ts:129–149  ·  view source on GitHub ↗

Split "| a | b | | c | d | | e | f |" into separate rows

(line: string)

Source from the content-addressed store, hash-verified

127
128/** Split "| a | b | | c | d | | e | f |" into separate rows */
129function 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
151function isTableRow(line: string): boolean {
152 if (!line) return false;

Callers 1

fixMarkdownTablesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected