This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tableToList(md: string): string { | |
return md.replace(/\|.+\n(\|[-:]+.*\n)(\|.+\n)+/g, block => { | |
const lines = block.trim().split('\n').filter(l => l.startsWith('|')); | |
const headers = split(lines[0]); | |
const rows = lines.slice(2).map(split); | |
return rows | |
.map(r => headers.map((h, i) => `- **${h}**: ${r[i] ?? ''}`).join('\n')) | |
.join('\n\n'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseMarkdownTable(md: string) { | |
const lines = md.trim().split('\n').filter(l => l.startsWith('|')); | |
if (lines.length < 2) return []; | |
const headers = splitRow(lines[0]); | |
return lines.slice(2).map(line => { | |
const cells = splitRow(line); | |
return Object.fromEntries(headers.map((h, i) => [h, cells[i] ?? ''])); | |
}); |