Files
docx-js/src/file/paragraph/links/pageref-field-instruction.ts

26 lines
864 B
TypeScript
Raw Normal View History

import { SpaceType } from "file/space-type";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
2021-09-08 00:41:40 +01:00
import { IPageReferenceOptions } from "./pageref-properties";
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
protected readonly xmlKeys = { space: "xml:space" };
}
2021-09-08 00:41:40 +01:00
export class PageReferenceFieldInstruction extends XmlComponent {
constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
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);
}
}