Files
docx-js/src/file/paragraph/links/bookmark.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-07-24 15:56:13 -04:00
// http://officeopenxml.com/WPbookmark.php
import { XmlComponent } from "file/xml-components";
2019-12-21 03:59:40 +00:00
import * as shortid from "shortid";
2018-07-24 15:56:13 -04:00
import { TextRun } from "../run";
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
export class Bookmark {
public readonly start: BookmarkStart;
public readonly text: TextRun;
public readonly end: BookmarkEnd;
2019-12-21 03:59:40 +00:00
constructor(name: string, text: string) {
const linkId = shortid.generate().toLowerCase();
2018-07-24 15:56:13 -04:00
2019-12-21 03:59:40 +00:00
this.start = new BookmarkStart(name, linkId);
2018-07-24 15:56:13 -04:00
this.text = new TextRun(text);
2019-12-21 03:59:40 +00:00
this.end = new BookmarkEnd(linkId);
2018-07-24 15:56:13 -04:00
}
}
export class BookmarkStart extends XmlComponent {
2019-12-21 03:59:40 +00:00
constructor(name: string, linkId: string) {
2018-07-24 15:56:13 -04:00
super("w:bookmarkStart");
const attributes = new BookmarkStartAttributes({
name,
2019-12-21 03:59:40 +00:00
id: linkId,
2018-07-24 15:56:13 -04:00
});
this.root.push(attributes);
}
}
export class BookmarkEnd extends XmlComponent {
2019-12-21 03:59:40 +00:00
constructor(linkId: string) {
2018-07-24 15:56:13 -04:00
super("w:bookmarkEnd");
const attributes = new BookmarkEndAttributes({
2019-12-21 03:59:40 +00:00
id: linkId,
2018-07-24 15:56:13 -04:00
});
this.root.push(attributes);
}
}