#1528 Adding numbering replacer on header and footer

This commit is contained in:
Dolan Miu
2022-06-16 16:31:34 +01:00
parent 05c053a44d
commit f1ab24c439
2 changed files with 47 additions and 3 deletions

View File

@ -1,7 +1,7 @@
// Numbering and bullet points example // Numbering and bullet points example
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build"; import { AlignmentType, convertInchesToTwip, Document, Footer, Header, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
const doc = new Document({ const doc = new Document({
numbering: { numbering: {
@ -119,6 +119,46 @@ const doc = new Document({
}, },
sections: [ sections: [
{ {
headers: {
default: new Header({
children: [
new Paragraph({
text: "Hey you",
numbering: {
reference: "my-crazy-numbering",
level: 0,
},
}),
new Paragraph({
text: "What's up fam",
numbering: {
reference: "my-crazy-numbering",
level: 1,
},
}),
],
}),
},
footers: {
default: new Footer({
children: [
new Paragraph({
text: "Hey you",
numbering: {
reference: "my-crazy-numbering",
level: 0,
},
}),
new Paragraph({
text: "What's up fam",
numbering: {
reference: "my-crazy-numbering",
level: 1,
},
}),
],
}),
},
children: [ children: [
new Paragraph({ new Paragraph({
text: "Hey you", text: "Hey you",

View File

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