@@ -21,7 +21,6 @@ export function serializeInlineContentInternalHTML<
21
21
editor : BlockNoteEditor < any , I , S > ,
22
22
blockContent : PartialBlock < BSchema , I , S > [ "content" ] ,
23
23
serializer : DOMSerializer ,
24
- _toExternalHTML : boolean , // TODO, externalHTML for IC
25
24
options ?: { document ?: Document }
26
25
) {
27
26
let nodes : any ;
@@ -67,7 +66,7 @@ function serializeBlock<
67
66
editor : BlockNoteEditor < BSchema , I , S > ,
68
67
block : PartialBlock < BSchema , I , S > ,
69
68
serializer : DOMSerializer ,
70
- toExternalHTML : boolean ,
69
+ listIndex : number ,
71
70
options ?: { document ?: Document }
72
71
) {
73
72
const BC_NODE = editor . pmSchema . nodes [ "blockContainer" ] ;
@@ -94,16 +93,23 @@ function serializeBlock<
94
93
} ;
95
94
96
95
const impl = editor . blockImplementations [ block . type as any ] . implementation ;
97
- const ret = toExternalHTML
98
- ? impl . toExternalHTML ( { ...block , props } as any , editor as any )
99
- : impl . toInternalHTML ( { ...block , props } as any , editor as any ) ;
96
+ const ret = impl . toInternalHTML ( { ...block , props } as any , editor as any ) ;
97
+
98
+ if ( block . type === "numberedListItem" ) {
99
+ // This is a workaround to make sure there's a list index set.
100
+ // Normally, this is set on the internal prosemirror nodes by the NumberedListIndexingPlugin,
101
+ // but:
102
+ // - (a) this information is not available on the Blocks passed to the serializer. (we only have access to BlockNote Blocks)
103
+ // - (b) the NumberedListIndexingPlugin might not even have run, because we can manually call blocksToFullHTML
104
+ // with blocks that are not part of the active document
105
+ ret . dom . setAttribute ( "data-index" , listIndex . toString ( ) ) ;
106
+ }
100
107
101
108
if ( ret . contentDOM && block . content ) {
102
109
const ic = serializeInlineContentInternalHTML (
103
110
editor ,
104
111
block . content as any , // TODO
105
112
serializer ,
106
- toExternalHTML ,
107
113
options
108
114
) ;
109
115
ret . contentDOM . appendChild ( ic ) ;
@@ -113,13 +119,7 @@ function serializeBlock<
113
119
114
120
if ( block . children && block . children . length > 0 ) {
115
121
bc . contentDOM ?. appendChild (
116
- serializeBlocksInternalHTML (
117
- editor ,
118
- block . children ,
119
- serializer ,
120
- toExternalHTML ,
121
- options
122
- )
122
+ serializeBlocksInternalHTML ( editor , block . children , serializer , options )
123
123
) ;
124
124
}
125
125
return bc . dom ;
@@ -133,7 +133,6 @@ export const serializeBlocksInternalHTML = <
133
133
editor : BlockNoteEditor < BSchema , I , S > ,
134
134
blocks : PartialBlock < BSchema , I , S > [ ] ,
135
135
serializer : DOMSerializer ,
136
- toExternalHTML : boolean ,
137
136
options ?: { document ?: Document }
138
137
) => {
139
138
const BG_NODE = editor . pmSchema . nodes [ "blockGroup" ] ;
@@ -143,12 +142,18 @@ export const serializeBlocksInternalHTML = <
143
142
contentDOM ?: HTMLElement ;
144
143
} ;
145
144
145
+ let listIndex = 0 ;
146
146
for ( const block of blocks ) {
147
+ if ( block . type === "numberedListItem" ) {
148
+ listIndex ++ ;
149
+ } else {
150
+ listIndex = 0 ;
151
+ }
147
152
const blockDOM = serializeBlock (
148
153
editor ,
149
154
block ,
150
155
serializer ,
151
- toExternalHTML ,
156
+ listIndex ,
152
157
options
153
158
) ;
154
159
bg . contentDOM ! . appendChild ( blockDOM ) ;
0 commit comments