Skip to content

Commit c444bfc

Browse files
committed
fix: blocks command now renders table contents
1 parent 7f48174 commit c444bfc

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

commands/blocks.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,50 @@ module.exports = {
5656
continue;
5757
}
5858

59+
// Handle table blocks - fetch and render children
60+
if (type === 'table') {
61+
const idTag = opts.ids ? `[${block.id.slice(0, 8)}] ` : '';
62+
try {
63+
const { results: tableRows } = await paginate(
64+
({ start_cursor, page_size }) => notion.blocks.children.list({
65+
block_id: block.id,
66+
start_cursor,
67+
page_size,
68+
}),
69+
{ pageSizeLimit: 100 },
70+
);
71+
72+
const rows = tableRows.map(row => {
73+
if (row.type !== 'table_row') return null;
74+
return row.table_row.cells.map(cell =>
75+
cell.map(rt => rt.plain_text || '').join('')
76+
);
77+
}).filter(Boolean);
78+
79+
if (rows.length > 0) {
80+
// Calculate column widths
81+
const colWidths = rows[0].map((_, i) =>
82+
Math.max(...rows.map(r => (r[i] || '').length), 3)
83+
);
84+
85+
// Render table
86+
rows.forEach((row, ri) => {
87+
const line = row.map((cell, i) => cell.padEnd(colWidths[i])).join(' │ ');
88+
console.log(`${idTag}${line}`);
89+
if (ri === 0 && content?.has_column_header) {
90+
console.log(`${opts.ids ? ' '.repeat(10) : ''}${colWidths.map(w => '─'.repeat(w)).join('─┼─')}`);
91+
}
92+
});
93+
console.log(''); // blank line after table
94+
} else {
95+
console.log(`${idTag}(empty table)`);
96+
}
97+
} catch (e) {
98+
console.log(`${idTag}📊 (table - use table-read ${block.id} for contents)`);
99+
}
100+
continue;
101+
}
102+
59103
if (content?.rich_text) {
60104
text = richTextToPlain(content.rich_text);
61105
} else if (content?.text) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jordancoin/notioncli",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "A powerful CLI for the Notion API — query databases, manage pages, and automate your workspace from the terminal.",
55
"main": "bin/notion.js",
66
"bin": {

0 commit comments

Comments
 (0)