Merge remote-tracking branch 'github.com/master'

This commit is contained in:
Chen Yuncai
2022-06-17 17:53:13 +08:00
27 changed files with 9022 additions and 863 deletions

View File

@ -43,19 +43,27 @@ describe("Compiler", () => {
sections: [
{
headers: {
default: new Header(),
default: new Header({
children: [new Paragraph("test")],
}),
},
footers: {
default: new Footer(),
default: new Footer({
children: [new Paragraph("test")],
}),
},
children: [],
},
{
headers: {
default: new Header(),
default: new Header({
children: [new Paragraph("test")],
}),
},
footers: {
default: new Footer(),
default: new Footer({
children: [new Paragraph("test")],
}),
},
children: [],
},
@ -99,5 +107,39 @@ describe("Compiler", () => {
compiler.compile(file);
expect(spy.callCount).to.equal(12);
});
it("should work with media datas", () => {
// This test is required because before, there was a case where Document was formatted twice, which was inefficient
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
const paragraph = new Paragraph("");
const file = new File({
sections: [
{
properties: {},
children: [paragraph],
},
],
});
// tslint:disable-next-line: no-string-literal
sinon.stub(compiler["imageReplacer"], "getMediaData").returns([
{
stream: Buffer.from(""),
fileName: "test",
transformation: {
pixels: {
x: 100,
y: 100,
},
emus: {
x: 100,
y: 100,
},
},
},
]);
compiler.compile(file);
});
});
});

View File

@ -280,8 +280,10 @@ export class Compiler {
// TODO: 0 needs to be changed when headers get relationships of their own
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
const referenedXmlData = this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
return {
data: xmlData,
data: referenedXmlData,
path: `word/header${index + 1}.xml`,
};
}),
@ -302,8 +304,10 @@ export class Compiler {
// TODO: 0 needs to be changed when headers get relationships of their own
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
const referenedXmlData = this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
return {
data: xmlData,
data: referenedXmlData,
path: `word/footer${index + 1}.xml`,
};
}),