Add ability to add multiple text runs to a bookmark
This commit is contained in:
@ -2,13 +2,17 @@ import { assert, expect } from "chai";
|
||||
|
||||
import { Utility } from "tests/utility";
|
||||
|
||||
import { TextRun } from "../run";
|
||||
import { Bookmark } from "./bookmark";
|
||||
|
||||
describe("Bookmark", () => {
|
||||
let bookmark: Bookmark;
|
||||
|
||||
beforeEach(() => {
|
||||
bookmark = new Bookmark("anchor", "Internal Link");
|
||||
bookmark = new Bookmark({
|
||||
id: "anchor",
|
||||
children: [new TextRun("Internal Link")],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a bookmark with three root elements", () => {
|
||||
|
@ -6,24 +6,24 @@ import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attri
|
||||
|
||||
export class Bookmark {
|
||||
public readonly start: BookmarkStart;
|
||||
public readonly text: TextRun;
|
||||
public readonly children: TextRun[];
|
||||
public readonly end: BookmarkEnd;
|
||||
|
||||
constructor(name: string, text: string) {
|
||||
constructor(options: { readonly id: string; readonly children: TextRun[] }) {
|
||||
const linkId = shortid.generate().toLowerCase();
|
||||
|
||||
this.start = new BookmarkStart(name, linkId);
|
||||
this.text = new TextRun(text);
|
||||
this.start = new BookmarkStart(options.id, linkId);
|
||||
this.children = options.children;
|
||||
this.end = new BookmarkEnd(linkId);
|
||||
}
|
||||
}
|
||||
|
||||
export class BookmarkStart extends XmlComponent {
|
||||
constructor(name: string, linkId: string) {
|
||||
constructor(id: string, linkId: string) {
|
||||
super("w:bookmarkStart");
|
||||
|
||||
const attributes = new BookmarkStartAttributes({
|
||||
name,
|
||||
name: id,
|
||||
id: linkId,
|
||||
});
|
||||
this.root.push(attributes);
|
||||
|
Reference in New Issue
Block a user