@@ -17,6 +17,8 @@ import {
1717 type IPropertiesOptions ,
1818 sectionPageSizeDefaults ,
1919 sectionMarginDefaults ,
20+ type IRunOptions ,
21+ type IParagraphOptions ,
2022} from "docx" ;
2123import type * as mdast from "mdast" ;
2224import { warnOnce } from "./utils" ;
@@ -30,6 +32,7 @@ import type {
3032 NodeBuilders ,
3133 NumberingRegistry ,
3234 RemarkDocxPlugin ,
35+ Writeable ,
3336} from "./types" ;
3437
3538const CONTENT_WIDTH =
@@ -305,37 +308,40 @@ const buildParagraph: NodeBuilder<"paragraph"> = ({ children }, ctx) => {
305308 const list = ctx . list ;
306309 const nodes = ctx . render ( children ) ;
307310
308- if ( list && list . checked != null ) {
309- nodes . unshift (
310- new CheckBox ( {
311- checked : list . checked ,
312- checkedState : { value : "2611" } ,
313- uncheckedState : { value : "2610" } ,
314- } ) ,
315- ) ;
316- }
317- return new Paragraph ( {
311+ const options : Writeable < IParagraphOptions > = {
318312 children : nodes ,
319- indent :
320- ctx . indent > 0
321- ? {
322- start : convertInchesToTwip ( INDENT * ctx . indent ) ,
323- }
324- : undefined ,
325- ...( list &&
326- ( list . ordered
327- ? {
328- numbering : {
329- reference : list . reference ,
330- level : list . level ,
331- } ,
332- }
333- : {
334- bullet : {
335- level : list . level ,
336- } ,
337- } ) ) ,
338- } ) ;
313+ } ;
314+
315+ if ( ctx . indent > 0 ) {
316+ options . indent = {
317+ start : convertInchesToTwip ( INDENT * ctx . indent ) ,
318+ } ;
319+ }
320+
321+ if ( list ) {
322+ if ( list . checked ) {
323+ nodes . unshift (
324+ new CheckBox ( {
325+ checked : list . checked ,
326+ checkedState : { value : "2611" } ,
327+ uncheckedState : { value : "2610" } ,
328+ } ) ,
329+ ) ;
330+ }
331+
332+ if ( list . ordered ) {
333+ options . numbering = {
334+ reference : list . reference ,
335+ level : list . level ,
336+ } ;
337+ } else {
338+ options . bullet = {
339+ level : list . level ,
340+ } ;
341+ }
342+ }
343+
344+ return new Paragraph ( options ) ;
339345} ;
340346
341347const buildHeading : NodeBuilder < "heading" > = ( { children, depth } , ctx ) => {
@@ -443,16 +449,17 @@ const buildTable: NodeBuilder<"table"> = ({ children, align }, ctx) => {
443449} ;
444450
445451const buildText : NodeBuilder < "text" > = ( { value } , { deco } ) => {
446- return new TextRun ( {
452+ const options : Writeable < IRunOptions > = {
447453 text : value ,
448454 bold : deco . bold ,
449455 italics : deco . italic ,
450456 strike : deco . strike ,
451- ...( deco . link && {
452- color : "#0563c1" ,
453- underline : { type : "single" } ,
454- } ) ,
455- } ) ;
457+ } ;
458+ if ( deco . link ) {
459+ options . color = "#0563c1" ;
460+ options . underline = { type : "single" } ;
461+ }
462+ return new TextRun ( options ) ;
456463} ;
457464
458465const buildEmphasis : NodeBuilder < "emphasis" > = ( { children } , ctx ) => {
0 commit comments