Page number in section (#2485)
* Page number in section * Inline Lorem Ipsum * Re-name current page in section to current section
This commit is contained in:
@ -26,3 +26,11 @@ export class NumberOfPagesSection extends XmlComponent {
|
||||
this.root.push("SECTIONPAGES");
|
||||
}
|
||||
}
|
||||
|
||||
export class CurrentPageInSection extends XmlComponent {
|
||||
public constructor() {
|
||||
super("w:instrText");
|
||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||
this.root.push("SECTION");
|
||||
}
|
||||
}
|
||||
|
@ -432,6 +432,23 @@ describe("Run", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#section", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
const run = new Run({
|
||||
children: [PageNumber.CURRENT_SECTION],
|
||||
});
|
||||
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" } }, "SECTION"] },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#style", () => {
|
||||
it("should set the style to the given styleId", () => {
|
||||
const run = new Run({
|
||||
|
@ -6,7 +6,7 @@ import { FieldInstruction } from "@file/table-of-contents/field-instruction";
|
||||
|
||||
import { Break } from "./break";
|
||||
import { Begin, End, Separate } from "./field";
|
||||
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
||||
import { NumberOfPages, NumberOfPagesSection, Page, CurrentPageInSection } from "./page-number";
|
||||
import { IRunPropertiesOptions, RunProperties } from "./properties";
|
||||
import { Text } from "./run-components/text";
|
||||
import {
|
||||
@ -103,6 +103,7 @@ export const PageNumber = {
|
||||
CURRENT: "CURRENT",
|
||||
TOTAL_PAGES: "TOTAL_PAGES",
|
||||
TOTAL_PAGES_IN_SECTION: "TOTAL_PAGES_IN_SECTION",
|
||||
CURRENT_SECTION: "SECTION",
|
||||
} as const;
|
||||
|
||||
/* eslint-enable */
|
||||
@ -143,6 +144,12 @@ export class Run extends XmlComponent {
|
||||
this.root.push(new Separate());
|
||||
this.root.push(new End());
|
||||
break;
|
||||
case PageNumber.CURRENT_SECTION:
|
||||
this.root.push(new Begin());
|
||||
this.root.push(new CurrentPageInSection());
|
||||
this.root.push(new Separate());
|
||||
this.root.push(new End());
|
||||
break;
|
||||
default:
|
||||
this.root.push(new Text(child));
|
||||
break;
|
||||
|
Reference in New Issue
Block a user