@@ -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 ) {
0 commit comments