Skip to content

Commit a8b6522

Browse files
committed
Refactor
1 parent 9804d53 commit a8b6522

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/mdast-util-to-docx.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ import type {
3535
Writeable,
3636
} from "./types";
3737

38-
const CONTENT_WIDTH =
39-
sectionPageSizeDefaults.WIDTH -
40-
sectionMarginDefaults.LEFT -
41-
sectionMarginDefaults.RIGHT;
4238
const ORDERED_LIST_REF = "ordered";
4339
const TASK_LIST_REF = "task";
4440
const HYPERLINK_STYLE_ID = "Hyperlink";
@@ -269,11 +265,15 @@ export const mdastToDocx = async (
269265
}
270266
return results;
271267
},
268+
width:
269+
sectionPageSizeDefaults.WIDTH -
270+
sectionMarginDefaults.LEFT -
271+
sectionMarginDefaults.RIGHT,
272272
deco: {},
273273
indent: 0,
274274
definition: definition,
275275
footnote,
276-
orderedListId: numbering.createId,
276+
orderedId: numbering.createId,
277277
};
278278

279279
const sections: DocxContent[][] = [[]];
@@ -426,7 +426,7 @@ const buildList: NodeBuilder<"list"> = ({ children, ordered }, ctx) => {
426426
reference:
427427
parentList && parentList.meta.type === "ordered"
428428
? parentList.meta.reference
429-
: ctx.orderedListId(),
429+
: ctx.orderedId(),
430430
};
431431
} else {
432432
meta = { type: "bullet" };
@@ -478,7 +478,7 @@ const buildTable: NodeBuilder<"table"> = ({ children, align }, ctx) => {
478478
});
479479

480480
const columnLength = children[0]!.children.length;
481-
const columnWidth = CONTENT_WIDTH / columnLength;
481+
const columnWidth = ctx.width / columnLength;
482482

483483
return new Table({
484484
columnWidths: Array.from({ length: columnLength }).map(() => columnWidth),

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export type FootnoteRegistry = {
5252

5353
export type Context = Readonly<{
5454
render: (node: readonly mdast.RootContent[], ctx?: Context) => DocxContent[];
55+
/**
56+
* @internal
57+
*/
58+
width: number;
5559
/**
5660
* @internal
5761
*/
@@ -75,7 +79,7 @@ export type Context = Readonly<{
7579
/**
7680
* @internal
7781
*/
78-
orderedListId: () => string;
82+
orderedId: () => string;
7983
}>;
8084

8185
export type NodeBuilder<T extends string> = (

0 commit comments

Comments
 (0)