File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed
packages/react-notion-x/src Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,13 @@ import { SyncPointerBlock } from './components/sync-pointer-block'
2323import { Text } from './components/text'
2424import { useNotionContext } from './context'
2525import { LinkIcon } from './icons/link-icon'
26- import { cs , getListNumber , isUrl } from './utils'
26+ import {
27+ cs ,
28+ getListNestingLevel ,
29+ getListNumber ,
30+ getListStyle ,
31+ isUrl
32+ } from './utils'
2733
2834interface BlockProps {
2935 block : types . Block
@@ -433,6 +439,15 @@ export function Block(props: BlockProps) {
433439 < ol
434440 start = { start }
435441 className = { cs ( 'notion-list' , 'notion-list-numbered' , blockId ) }
442+ style = {
443+ block . type === 'numbered_list'
444+ ? {
445+ listStyleType : getListStyle (
446+ getListNestingLevel ( block . id , recordMap . block )
447+ )
448+ }
449+ : undefined
450+ }
436451 >
437452 { content }
438453 </ ol >
Original file line number Diff line number Diff line change @@ -852,6 +852,18 @@ svg.notion-page-icon {
852852 margin-bottom : 0 ;
853853}
854854
855+ .notion-list-numbered ol {
856+ list-style-type : lower-alpha;
857+ }
858+
859+ .notion-list-numbered ol ol {
860+ list-style-type : lower-roman;
861+ }
862+
863+ .notion-list-numbered ol ol ol {
864+ list-style-type : decimal;
865+ }
866+
855867.notion-list-disc li {
856868 padding-left : 0.1em ;
857869}
Original file line number Diff line number Diff line change @@ -48,6 +48,38 @@ export const getListNumber = (blockId: string, blockMap: BlockMap) => {
4848 return group . indexOf ( blockId ) + 1
4949}
5050
51+ export const getListNestingLevel = (
52+ blockId : string ,
53+ blockMap : BlockMap
54+ ) : number => {
55+ let level = 0
56+ let currentBlockId = blockId
57+
58+ while ( true ) {
59+ const parentId = blockMap [ currentBlockId ] ?. value ?. parent_id
60+
61+ if ( ! parentId ) break
62+
63+ const parentBlock = blockMap [ parentId ] ?. value
64+ if ( ! parentBlock ) break
65+
66+ if ( parentBlock . type === 'numbered_list' ) {
67+ level ++
68+ currentBlockId = parentId
69+ } else {
70+ break
71+ }
72+ }
73+
74+ return level
75+ }
76+
77+ export const getListStyle = ( level : number ) : string => {
78+ const styles : string [ ] = [ 'decimal' , 'lower-alpha' , 'lower-roman' ]
79+ const index = ( ( level % styles . length ) + styles . length ) % styles . length
80+ return styles [ index ] as string
81+ }
82+
5183export const getHashFragmentValue = ( url : string ) => {
5284 return url . includes ( '#' ) ? url . replace ( / ^ .+ ( # .+ ) $ / , '$1' ) : ''
5385}
You can’t perform that action at this time.
0 commit comments