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

Function parseTable

packages/app-core/src/lib/markdown-table.ts:138–158  ·  view source on GitHub ↗
(block: string)

Source from the content-addressed store, hash-verified

136 * well-formed table (header + delimiter + zero or more body rows).
137 */
138export function parseTable(block: string): MarkdownTable | null {
139 const lines = block.replace(/\n+$/, '').split('\n')
140 if (lines.length < 2) return null
141 if (!isDelimiterRow(lines[1])) return null
142
143 const headers = splitRow(lines[0])
144 const alignCells = splitRow(lines[1])
145 const colCount = headers.length
146 if (colCount === 0) return null
147
148 const aligns: ColumnAlign[] = []
149 for (let c = 0; c < colCount; c++) aligns.push(parseAlign(alignCells[c] ?? ''))
150
151 const rows: string[][] = []
152 for (let i = 2; i < lines.length; i++) {
153 if (lines[i].trim() === '') continue
154 rows.push(normalizeRow(splitRow(lines[i]), colCount))
155 }
156
157 return { headers, rows, aligns }
158}
159
160function normalizeRow(cells: string[], colCount: number): string[] {
161 const out = cells.slice(0, colCount)

Callers 3

parseFunction · 0.90
buildDecorationsFunction · 0.90

Calls 4

isDelimiterRowFunction · 0.85
splitRowFunction · 0.85
parseAlignFunction · 0.85
normalizeRowFunction · 0.85

Tested by 1

parseFunction · 0.72