Add ImageRun feature

This commit is contained in:
Dolan Miu
2023-03-03 23:47:50 +00:00
parent fe9b438a51
commit 66a1992da0
9 changed files with 141 additions and 11 deletions

View File

@ -2,7 +2,7 @@ import { Element } from "xml-js";
import * as xml from "xml";
import { Formatter } from "@export/formatter";
import { XmlComponent } from "@file/xml-components";
import { IContext, XmlComponent } from "@file/xml-components";
import { IPatch, PatchType } from "./from-docx";
import { toJson } from "./util";
@ -19,9 +19,13 @@ export const replacer = (
patch: IPatch,
patchText: string,
renderedParagraphs: readonly IRenderedParagraphNode[],
context: IContext,
): Element => {
for (const renderedParagraph of renderedParagraphs) {
const textJson = patch.children.map((c) => toJson(xml(formatter.format(c as XmlComponent)))).map((c) => c.elements![0]);
const textJson = patch.children
// eslint-disable-next-line no-loop-func
.map((c) => toJson(xml(formatter.format(c as XmlComponent, context))))
.map((c) => c.elements![0]);
if (patch.type === PatchType.DOCUMENT) {
const parentElement = goToParentElementFromPath(json, renderedParagraph.path);
@ -30,7 +34,6 @@ export const replacer = (
parentElement.elements?.splice(elementIndex, 1, ...textJson);
} else if (patch.type === PatchType.PARAGRAPH) {
const paragraphElement = goToElementFromPath(json, renderedParagraph.path);
replaceTokenInParagraphElement({
paragraphElement,
renderedParagraph,