Context
This becomes handy when we want to transform a LaTeX, AsciiDoc, etc. document into docx.
Example:
// Parser
function parse(input: string) : Paragraph[] {
// ...
return [
new Paragraph({
children: "..."
})
]
}
// Later
const paras = parse(`
Hello
World!
`);
const mapped = paras.flatMap(p => {
return p.map({
indent: { left: 720, right: 720 },
spacing: { before: 240, after: 120 },
alignment: AlignmentType.RIGHT,
})
});
Right now Paragraphs are "immutable" in TypeScript and accomplishing this needs casting to any:
const result = parseToParagraphs(body).map((par) => {
const runs = (par as any).root;
return new Paragraph({
indent: { left: 720, right: 720 },
spacing: { before: 240, after: 120 },
children: runs,
});
});
Context
This becomes handy when we want to transform a LaTeX, AsciiDoc, etc. document into
docx.Example:
Right now
Paragraphs are "immutable" in TypeScript and accomplishing this needs casting toany: