@@ -81,39 +81,18 @@ type OrderedListFormat = {
8181 text : string ;
8282} ;
8383
84- const createNumberingRegistry = (
85- orderedList : readonly OrderedListFormat [ ] ,
86- ) : NumberingRegistry => {
84+ const createNumberingRegistry = ( ) : NumberingRegistry => {
8785 let counter = 1 ;
8886
89- const levels : ILevelsOptions [ ] = orderedList . map (
90- ( { format, text } , i ) => {
91- return {
92- level : i ,
93- format : LevelFormat [ format ] ,
94- text : text ,
95- alignment : AlignmentType . START ,
96- style :
97- i === 0
98- ? undefined
99- : {
100- paragraph : {
101- indent : { start : convertInchesToTwip ( INDENT * i ) } ,
102- } ,
103- } ,
104- } ;
105- } ,
106- ) ;
107-
10887 return {
10988 create : ( ) => {
11089 return `${ ORDERED_LIST_REF } -${ counter ++ } ` ;
11190 } ,
11291 toConfig : ( ) => {
113- return Array . from ( { length : counter } , ( _ , i ) => ( {
114- reference : ` ${ ORDERED_LIST_REF } - ${ i } ` ,
115- levels : levels ,
116- } ) ) ;
92+ return Array . from (
93+ { length : counter } ,
94+ ( _ , i ) => ` ${ ORDERED_LIST_REF } - ${ i } ` ,
95+ ) ;
11796 } ,
11897 } ;
11998} ;
@@ -190,7 +169,7 @@ export const mdastToDocx = async (
190169 const definition = definitions ( node ) ;
191170
192171 const footnote = createFootnoteRegistry ( ) ;
193- const numbering = createNumberingRegistry ( orderedListFormat ) ;
172+ const numbering = createNumberingRegistry ( ) ;
194173
195174 const pluginCtx = { root : node , definition } ;
196175
@@ -278,6 +257,25 @@ export const mdastToDocx = async (
278257 }
279258 }
280259
260+ const levels : ILevelsOptions [ ] = orderedListFormat . map (
261+ ( { format, text } , i ) => {
262+ return {
263+ level : i ,
264+ format : LevelFormat [ format ] ,
265+ text : text ,
266+ alignment : AlignmentType . START ,
267+ style :
268+ i === 0
269+ ? undefined
270+ : {
271+ paragraph : {
272+ indent : { start : convertInchesToTwip ( INDENT * i ) } ,
273+ } ,
274+ } ,
275+ } ;
276+ } ,
277+ ) ;
278+
281279 const doc = new Document ( {
282280 title,
283281 subject,
@@ -291,7 +289,10 @@ export const mdastToDocx = async (
291289 . map ( ( s ) => ( { children : s as DocxChild [ ] } ) ) ,
292290 footnotes : footnote . toConfig ( ) ,
293291 numbering : {
294- config : numbering . toConfig ( ) ,
292+ config : numbering . toConfig ( ) . map ( ( ref ) => ( {
293+ reference : ref ,
294+ levels,
295+ } ) ) ,
295296 } ,
296297 } ) ;
297298
@@ -381,6 +382,8 @@ const buildBlockquote: NodeBuilder<"blockquote"> = ({ children }, ctx) => {
381382
382383const buildList : NodeBuilder < "list" > = ( { children, ordered } , ctx ) => {
383384 const isTopLevel = ! ctx . list ;
385+ const level = isTopLevel ? 0 : ctx . list . level + 1 ;
386+
384387 const reference =
385388 isTopLevel && ordered
386389 ? ctx . numbering . create ( )
@@ -389,7 +392,7 @@ const buildList: NodeBuilder<"list"> = ({ children, ordered }, ctx) => {
389392 return ctx . render ( children , {
390393 ...ctx ,
391394 list : {
392- level : isTopLevel ? 0 : ctx . list . level + 1 ,
395+ level,
393396 ordered : ! ! ordered ,
394397 reference,
395398 } ,
0 commit comments