11// import { Client } from 'notion-to-utils';
22import React , { useEffect , useState , useMemo , useCallback } from 'react' ;
33import styled , { ThemeProvider , createGlobalStyle } from 'styled-components' ;
4- import Prism from 'prismjs' ;
4+ import Prism , { Grammar } from 'prismjs' ;
55import 'prismjs/themes/prism.css' ;
66import 'prismjs/components/prism-typescript' ;
77import 'prismjs/components/prism-javascript' ;
@@ -42,16 +42,16 @@ const notion = {
4242 } ,
4343} ;
4444
45- const GlobalStyle = createGlobalStyle < { theme : Theme } > `
46- body {
47- background-color: ${ ( { theme } ) => theme . colors . background } ;
48- color: ${ ( { theme } ) => theme . colors . text } ;
49- font-family: ${ ( { theme } ) => theme . typography . fontFamily . base } ;
50- line-height: ${ ( { theme } ) => theme . typography . lineHeight . base } ;
51- margin: 0;
52- padding: 0;
53- }
54- ` ;
45+ // const GlobalStyle = createGlobalStyle<{ theme: Theme }>`
46+ // body {
47+ // background-color: ${({ theme }) => theme.colors.background};
48+ // color: ${({ theme }) => theme.colors.text };
49+ // font-family: ${({ theme }) => theme.typography.fontFamily.base};
50+ // line-height: ${({ theme }) => theme.typography.lineHeight.base};
51+ // margin: 0;
52+ // padding: 0;
53+ // }
54+ // `;
5555
5656const Container = styled . div `
5757 max-width: 900px;
@@ -148,7 +148,7 @@ const CodeBlock: React.FC<{
148148 const highlightedCode = useMemo ( ( ) => {
149149 const prismLanguage =
150150 Prism . languages [ language ] || Prism . languages . plaintext ;
151- return Prism . highlight ( code , prismLanguage , language ) ;
151+ return Prism . highlight ( code , prismLanguage as Grammar , language ) ;
152152 } , [ code , language ] ) ;
153153
154154 return (
@@ -173,7 +173,9 @@ const ListBlocksRenderer: React.FC<{
173173} > = ( { blocks, startIndex, type } ) => {
174174 let consecutiveItems = 0 ;
175175 for ( let i = startIndex ; i < blocks . length ; i ++ ) {
176- if ( blocks [ i ] . type === `${ type } _list_item` ) {
176+ const block = blocks [ i ] ;
177+ if ( ! block ) break ;
178+ if ( block . type === `${ type } _list_item` ) {
177179 consecutiveItems ++ ;
178180 } else {
179181 break ;
@@ -182,9 +184,15 @@ const ListBlocksRenderer: React.FC<{
182184
183185 return (
184186 < List as = { type === 'numbered' ? 'ol' : 'ul' } type = { type } >
185- { blocks . slice ( startIndex , startIndex + consecutiveItems ) . map ( ( block ) => (
186- < BlockRenderer key = { block . id } block = { block } />
187- ) ) }
187+ { blocks
188+ . slice ( startIndex , startIndex + consecutiveItems )
189+ . map ( ( block , index ) => (
190+ < BlockRenderer
191+ key = { block . id }
192+ block = { block }
193+ index = { startIndex + index }
194+ />
195+ ) ) }
188196 </ List >
189197 ) ;
190198} ;
@@ -237,15 +245,15 @@ const BlockRenderer: React.FC<{
237245 ) ;
238246 case 'bulleted_list_item' :
239247 return (
240- < ListItem ref = { ref } tabIndex = { 0 } role = "listitem" >
248+ < ListItem ref = { ref as any } tabIndex = { 0 } role = "listitem" >
241249 { block . bulleted_list_item ?. rich_text && (
242250 < MemoizedRichText richText = { block . bulleted_list_item . rich_text } />
243251 ) }
244252 </ ListItem >
245253 ) ;
246254 case 'numbered_list_item' :
247255 return (
248- < ListItem ref = { ref } tabIndex = { 0 } role = "listitem" >
256+ < ListItem ref = { ref as any } tabIndex = { 0 } role = "listitem" >
249257 { block . numbered_list_item ?. rich_text && (
250258 < MemoizedRichText richText = { block . numbered_list_item . rich_text } />
251259 ) }
@@ -347,10 +355,11 @@ export const Renderer: React.FC<{
347355
348356 for ( let i = 0 ; i < blocks . length ; i ++ ) {
349357 const block = blocks [ i ] ;
358+ if ( ! block ) break ;
350359
351360 if (
352361 block . type === 'bulleted_list_item' &&
353- ( i === 0 || blocks [ i - 1 ] . type !== 'bulleted_list_item' )
362+ ( i === 0 || blocks [ i - 1 ] ? .type !== 'bulleted_list_item' )
354363 ) {
355364 result . push (
356365 < List
@@ -369,18 +378,19 @@ export const Renderer: React.FC<{
369378 ) ;
370379 while (
371380 i + 1 < blocks . length &&
372- blocks [ i + 1 ] . type === 'bulleted_list_item'
381+ blocks [ i + 1 ] &&
382+ blocks [ i + 1 ] ?. type === 'bulleted_list_item'
373383 ) {
374384 i ++ ;
375385 }
376386 } else if (
377387 block . type === 'numbered_list_item' &&
378- ( i === 0 || blocks [ i - 1 ] . type !== 'numbered_list_item' )
388+ ( i === 0 || blocks [ i - 1 ] ? .type !== 'numbered_list_item' )
379389 ) {
380390 result . push (
381391 < List
382392 as = "ol"
383- type = "numbered "
393+ type = "1 "
384394 role = "list"
385395 aria-label = "Numbered list"
386396 key = { block . id }
@@ -394,7 +404,8 @@ export const Renderer: React.FC<{
394404 ) ;
395405 while (
396406 i + 1 < blocks . length &&
397- blocks [ i + 1 ] . type === 'numbered_list_item'
407+ blocks [ i + 1 ] &&
408+ blocks [ i + 1 ] ?. type === 'numbered_list_item'
398409 ) {
399410 i ++ ;
400411 }
@@ -418,7 +429,7 @@ export const Renderer: React.FC<{
418429
419430 return (
420431 < ThemeProvider theme = { theme } >
421- < GlobalStyle />
432+ { /* <GlobalStyle /> */ }
422433 < Container role = "main" aria-label = "Notion page content" >
423434 { renderedBlocks }
424435 </ Container >
0 commit comments