MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / splitRow

Function splitRow

packages/app-core/src/lib/markdown-table.ts:73–99  ·  view source on GitHub ↗

Split one `| a | b |` row into trimmed, unescaped cell strings. Honors * `\|` (escaped pipe) and `\\` so cells can contain literal pipes.

(line: string)

Source from the content-addressed store, hash-verified

71/** Split one `| a | b |` row into trimmed, unescaped cell strings. Honors
72 * `\|` (escaped pipe) and `\\` so cells can contain literal pipes. */
73function splitRow(line: string): string[] {
74 let trimmed = line.trim()
75 // Drop a single leading / trailing unescaped pipe (the common form).
76 if (trimmed.startsWith('|')) trimmed = trimmed.slice(1)
77 if (endsWithUnescapedPipe(trimmed)) trimmed = trimmed.slice(0, -1)
78
79 const cells: string[] = []
80 let current = ''
81 for (let i = 0; i < trimmed.length; i++) {
82 const ch = trimmed[i]
83 if (ch === '\\' && i + 1 < trimmed.length) {
84 // Preserve the escape sequence verbatim for an exact round-trip;
85 // unescaping happens in `unescapeCell` for display.
86 current += ch + trimmed[i + 1]
87 i++
88 continue
89 }
90 if (ch === '|') {
91 cells.push(current)
92 current = ''
93 continue
94 }
95 current += ch
96 }
97 cells.push(current)
98 return cells.map((c) => unescapeCell(c.trim()))
99}
100
101function endsWithUnescapedPipe(text: string): boolean {
102 if (!text.endsWith('|')) return false

Callers 2

isDelimiterRowFunction · 0.85
parseTableFunction · 0.85

Calls 2

endsWithUnescapedPipeFunction · 0.85
unescapeCellFunction · 0.85

Tested by

no test coverage detected