diff --git a/packages/react-notion-x/src/block.tsx b/packages/react-notion-x/src/block.tsx
index 73259aae..5682181d 100644
--- a/packages/react-notion-x/src/block.tsx
+++ b/packages/react-notion-x/src/block.tsx
@@ -23,7 +23,13 @@ import { SyncPointerBlock } from './components/sync-pointer-block'
import { Text } from './components/text'
import { useNotionContext } from './context'
import { LinkIcon } from './icons/link-icon'
-import { cs, getListNumber, isUrl } from './utils'
+import {
+ cs,
+ getListNestingLevel,
+ getListNumber,
+ getListStyle,
+ isUrl
+} from './utils'
interface BlockProps {
block: types.Block
@@ -433,24 +439,57 @@ export function Block(props: BlockProps) {
{content}
)
let output: React.ReactNode | null = null
+ const isTopLevel =
+ block.type !== recordMap.block[block.parent_id]?.value?.type
+ const start = getListNumber(block.id, recordMap.block)
if (block.content) {
- output = (
- <>
- {block.properties && (
-
-
-
- )}
- {wrapList(children)}
- >
- )
+ const listItem = block.properties ? (
+
+
+
+ ) : null
+
+ if (block.type === 'bulleted_list') {
+ output = (
+ <>
+ {listItem}
+
+ >
+ )
+ } else {
+ const nestingLevel = getListNestingLevel(block.id, recordMap.block)
+ output = (
+ <>
+ {listItem}
+
+ {children}
+
+ >
+ )
+ }
} else {
output = block.properties ? (
@@ -459,10 +498,6 @@ export function Block(props: BlockProps) {
) : null
}
- const isTopLevel =
- block.type !== recordMap.block[block.parent_id]?.value?.type
- const start = getListNumber(block.id, recordMap.block)
-
return isTopLevel ? wrapList(output, start) : output
}
diff --git a/packages/react-notion-x/src/utils.ts b/packages/react-notion-x/src/utils.ts
index c7a178ce..2248da15 100644
--- a/packages/react-notion-x/src/utils.ts
+++ b/packages/react-notion-x/src/utils.ts
@@ -48,6 +48,38 @@ export const getListNumber = (blockId: string, blockMap: BlockMap) => {
return group.indexOf(blockId) + 1
}
+export const getListNestingLevel = (
+ blockId: string,
+ blockMap: BlockMap
+): number => {
+ let level = 0
+ let currentBlockId = blockId
+
+ while (true) {
+ const parentId = blockMap[currentBlockId]?.value?.parent_id
+
+ if (!parentId) break
+
+ const parentBlock = blockMap[parentId]?.value
+ if (!parentBlock) break
+
+ if (parentBlock.type === 'numbered_list') {
+ level++
+ currentBlockId = parentId
+ } else {
+ break
+ }
+ }
+
+ return level
+}
+
+export const getListStyle = (level: number): string => {
+ const styles: string[] = ['decimal', 'lower-alpha', 'lower-roman']
+ const index = ((level % styles.length) + styles.length) % styles.length
+ return styles[index] as string
+}
+
export const getHashFragmentValue = (url: string) => {
return url.includes('#') ? url.replace(/^.+(#.+)$/, '$1') : ''
}