Add total number of pages in a section
This commit is contained in:
@ -2,7 +2,7 @@ import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { NumberOfPages, Page } from "./page-number";
|
||||
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
||||
|
||||
describe("Page", () => {
|
||||
describe("#constructor()", () => {
|
||||
@ -21,3 +21,12 @@ describe("NumberOfPages", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("NumberOfPagesSection", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("uses the font name for both ascii and hAnsi", () => {
|
||||
const tree = new Formatter().format(new NumberOfPagesSection());
|
||||
expect(tree).to.deep.equal({ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "SECTIONPAGES"] });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -20,3 +20,11 @@ export class NumberOfPages extends XmlComponent {
|
||||
this.root.push("NUMPAGES");
|
||||
}
|
||||
}
|
||||
|
||||
export class NumberOfPagesSection extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:instrText");
|
||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||
this.root.push("SECTIONPAGES");
|
||||
}
|
||||
}
|
||||
|
@ -204,6 +204,21 @@ describe("Run", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#numberOfTotalPagesSection", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
run.numberOfTotalPagesSection();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
||||
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "SECTIONPAGES"] },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#pageNumber", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
run.pageNumber();
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
SizeComplexScript,
|
||||
Strike,
|
||||
} from "./formatting";
|
||||
import { NumberOfPages, Page } from "./page-number";
|
||||
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
||||
import { RunProperties } from "./properties";
|
||||
import { RunFonts } from "./run-fonts";
|
||||
import { SubScript, SuperScript } from "./script";
|
||||
@ -92,6 +92,14 @@ export class Run extends XmlComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public numberOfTotalPagesSection(): Run {
|
||||
this.root.push(new Begin());
|
||||
this.root.push(new NumberOfPagesSection());
|
||||
this.root.push(new Separate());
|
||||
this.root.push(new End());
|
||||
return this;
|
||||
}
|
||||
|
||||
public smallCaps(): Run {
|
||||
this.properties.push(new SmallCaps());
|
||||
return this;
|
||||
|
Reference in New Issue
Block a user