diff --git a/demo/21-bookmarks.ts b/demo/21-bookmarks.ts index 56343c94cd..decb882be0 100644 --- a/demo/21-bookmarks.ts +++ b/demo/21-bookmarks.ts @@ -1,7 +1,7 @@ // This demo shows how to create bookmarks then link to them with internal hyperlinks // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Bookmark, Document, Footer, HeadingLevel, InternalHyperlink, Packer, PageBreak, Paragraph, TextRun, PageRef } from "../build"; +import { Bookmark, Document, Footer, HeadingLevel, InternalHyperlink, Packer, PageBreak, Paragraph, TextRun, PageReference } from "../build"; const LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante."; @@ -65,7 +65,7 @@ const doc = new Document({ ], }), new Paragraph({ - children: [new TextRun("The bookmark can be seen on page "), new PageRef("myAnchorId")], + children: [new TextRun("The bookmark can be seen on page "), new PageReference("myAnchorId")], }), ], }, diff --git a/docs/usage/hyperlinks.md b/docs/usage/hyperlinks.md index d49d9aa0a2..1d7c1355d5 100644 --- a/docs/usage/hyperlinks.md +++ b/docs/usage/hyperlinks.md @@ -44,7 +44,7 @@ You can also get the page number of the bookmark by creating a page reference to const paragraph = new Paragraph({ children: [ new TextRun("Chapter 1 can be seen on page "), - new PageRef("anchorForChapter1"), + new PageReference("anchorForChapter1"), ], }); ``` diff --git a/src/file/paragraph/links/pageref-field-instruction.spec.ts b/src/file/paragraph/links/pageref-field-instruction.spec.ts index de1a28863c..942c108be9 100644 --- a/src/file/paragraph/links/pageref-field-instruction.spec.ts +++ b/src/file/paragraph/links/pageref-field-instruction.spec.ts @@ -1,12 +1,12 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; -import { PageRefFieldInstruction } from "./pageref-field-instruction"; +import { PageReferenceFieldInstruction } from "./pageref-field-instruction"; -describe("PageRef field instruction", () => { +describe("PageReference field instruction", () => { describe("#constructor()", () => { it("should construct a pageref field instruction without options", () => { - const instruction = new PageRefFieldInstruction("anchor"); + const instruction = new PageReferenceFieldInstruction("anchor"); const tree = new Formatter().format(instruction); expect(tree).to.be.deep.equal({ diff --git a/src/file/paragraph/links/pageref-field-instruction.ts b/src/file/paragraph/links/pageref-field-instruction.ts index 198f5427c9..99be950d28 100644 --- a/src/file/paragraph/links/pageref-field-instruction.ts +++ b/src/file/paragraph/links/pageref-field-instruction.ts @@ -1,13 +1,13 @@ import { SpaceType } from "file/space-type"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -import { IPageRefOptions } from "./pageref-properties"; +import { IPageReferenceOptions } 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 = {}) { +export class PageReferenceFieldInstruction extends XmlComponent { + constructor(bookmarkId: string, options: IPageReferenceOptions = {}) { super("w:instrText"); this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); diff --git a/src/file/paragraph/links/pageref-properties.ts b/src/file/paragraph/links/pageref-properties.ts index 963c5331d6..f557cfc322 100644 --- a/src/file/paragraph/links/pageref-properties.ts +++ b/src/file/paragraph/links/pageref-properties.ts @@ -1,6 +1,6 @@ // Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234) -export interface IPageRefOptions { +export interface IPageReferenceOptions { /** * \h option - Creates a hyperlink to the bookmarked paragraph. */ diff --git a/src/file/paragraph/links/pageref.spec.ts b/src/file/paragraph/links/pageref.spec.ts index 459429373b..c26c8c8632 100644 --- a/src/file/paragraph/links/pageref.spec.ts +++ b/src/file/paragraph/links/pageref.spec.ts @@ -1,12 +1,12 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; -import { PageRef } from "./pageref"; +import { PageReference } from "./pageref"; -describe("PageRef", () => { +describe("PageReference", () => { describe("#constructor()", () => { it("should construct a pageref without options", () => { - const pageref = new PageRef("some_bookmark"); + const pageref = new PageReference("some_bookmark"); const tree = new Formatter().format(pageref); expect(tree).to.be.deep.equal({ "w:r": [ @@ -40,8 +40,8 @@ describe("PageRef", () => { }); it("should construct a pageref with all the options", () => { - const pageref = new PageRef("some_bookmark", { hyperlink: true, useRelativePosition: true }); - const tree = new Formatter().format(pageref); + const pageReference = new PageReference("some_bookmark", { hyperlink: true, useRelativePosition: true }); + const tree = new Formatter().format(pageReference); expect(tree).to.be.deep.equal({ "w:r": [ { diff --git a/src/file/paragraph/links/pageref.ts b/src/file/paragraph/links/pageref.ts index 7cb6acfeec..b2f1880d2d 100644 --- a/src/file/paragraph/links/pageref.ts +++ b/src/file/paragraph/links/pageref.ts @@ -1,13 +1,13 @@ // See https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234) import { Begin, End } from "file/paragraph/run/field"; import { Run } from "../run"; -import { PageRefFieldInstruction } from "./pageref-field-instruction"; -import type { IPageRefOptions } from "./pageref-properties"; +import { PageReferenceFieldInstruction } from "./pageref-field-instruction"; +import type { IPageReferenceOptions } from "./pageref-properties"; -export class PageRef extends Run { - constructor(bookmarkId: string, options: IPageRefOptions = {}) { +export class PageReference extends Run { + constructor(bookmarkId: string, options: IPageReferenceOptions = {}) { super({ - children: [new Begin(true), new PageRefFieldInstruction(bookmarkId, options), new End()], + children: [new Begin(true), new PageReferenceFieldInstruction(bookmarkId, options), new End()], }); } }