Add the pageref element

This instruction is useful if you want to get the number of the page
containing a specific bookmark.
This commit is contained in:
Thomas Gerbet
2021-08-03 15:58:26 +02:00
parent 14013273af
commit 3f257bf5a4
8 changed files with 173 additions and 1 deletions

View File

@ -0,0 +1,25 @@
import { SpaceType } from "file/space-type";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { IPageRefOptions } from "./pageref-properties";
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
protected readonly xmlKeys = { space: "xml:space" };
}
export class PageRefFieldInstruction extends XmlComponent {
constructor(bookmarkId: string, options: IPageRefOptions = {}) {
super("w:instrText");
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
let instruction = `PAGEREF ${bookmarkId}`;
if (options.hyperlink) {
instruction = `${instruction} \\h`;
}
if (options.useRelativePosition) {
instruction = `${instruction} \\p`;
}
this.root.push(instruction);
}
}