Re-name PageRef to PageReference
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
// 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 from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
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 =
|
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.";
|
"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({
|
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")],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -44,7 +44,7 @@ You can also get the page number of the bookmark by creating a page reference to
|
|||||||
const paragraph = new Paragraph({
|
const paragraph = new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
new TextRun("Chapter 1 can be seen on page "),
|
new TextRun("Chapter 1 can be seen on page "),
|
||||||
new PageRef("anchorForChapter1"),
|
new PageReference("anchorForChapter1"),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
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()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should construct a pageref field instruction without options", () => {
|
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);
|
const tree = new Formatter().format(instruction);
|
||||||
|
|
||||||
expect(tree).to.be.deep.equal({
|
expect(tree).to.be.deep.equal({
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { SpaceType } from "file/space-type";
|
import { SpaceType } from "file/space-type";
|
||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
import { IPageRefOptions } from "./pageref-properties";
|
import { IPageReferenceOptions } from "./pageref-properties";
|
||||||
|
|
||||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||||
protected readonly xmlKeys = { space: "xml:space" };
|
protected readonly xmlKeys = { space: "xml:space" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PageRefFieldInstruction extends XmlComponent {
|
export class PageReferenceFieldInstruction extends XmlComponent {
|
||||||
constructor(bookmarkId: string, options: IPageRefOptions = {}) {
|
constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||||
super("w:instrText");
|
super("w:instrText");
|
||||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
// 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.
|
* \h option - Creates a hyperlink to the bookmarked paragraph.
|
||||||
*/
|
*/
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
import { PageRef } from "./pageref";
|
import { PageReference } from "./pageref";
|
||||||
|
|
||||||
describe("PageRef", () => {
|
describe("PageReference", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should construct a pageref without options", () => {
|
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);
|
const tree = new Formatter().format(pageref);
|
||||||
expect(tree).to.be.deep.equal({
|
expect(tree).to.be.deep.equal({
|
||||||
"w:r": [
|
"w:r": [
|
||||||
@ -40,8 +40,8 @@ describe("PageRef", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should construct a pageref with all the options", () => {
|
it("should construct a pageref with all the options", () => {
|
||||||
const pageref = new PageRef("some_bookmark", { hyperlink: true, useRelativePosition: true });
|
const pageReference = new PageReference("some_bookmark", { hyperlink: true, useRelativePosition: true });
|
||||||
const tree = new Formatter().format(pageref);
|
const tree = new Formatter().format(pageReference);
|
||||||
expect(tree).to.be.deep.equal({
|
expect(tree).to.be.deep.equal({
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// See https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
// 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 { Begin, End } from "file/paragraph/run/field";
|
||||||
import { Run } from "../run";
|
import { Run } from "../run";
|
||||||
import { PageRefFieldInstruction } from "./pageref-field-instruction";
|
import { PageReferenceFieldInstruction } from "./pageref-field-instruction";
|
||||||
import type { IPageRefOptions } from "./pageref-properties";
|
import type { IPageReferenceOptions } from "./pageref-properties";
|
||||||
|
|
||||||
export class PageRef extends Run {
|
export class PageReference extends Run {
|
||||||
constructor(bookmarkId: string, options: IPageRefOptions = {}) {
|
constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||||
super({
|
super({
|
||||||
children: [new Begin(true), new PageRefFieldInstruction(bookmarkId, options), new End()],
|
children: [new Begin(true), new PageReferenceFieldInstruction(bookmarkId, options), new End()],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user