2018-07-24 15:56:13 -04:00
|
|
|
// http://officeopenxml.com/WPbookmark.php
|
2021-03-12 03:58:05 +00:00
|
|
|
import { uniqueId } from "convenience-functions";
|
2018-07-24 15:56:13 -04:00
|
|
|
import { XmlComponent } from "file/xml-components";
|
2021-03-12 03:58:05 +00:00
|
|
|
|
2021-09-01 12:20:54 -06:00
|
|
|
import { ParagraphChild } from "../paragraph";
|
2018-07-24 15:56:13 -04:00
|
|
|
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
|
|
|
|
|
|
|
|
export class Bookmark {
|
|
|
|
public readonly start: BookmarkStart;
|
2021-09-01 12:20:54 -06:00
|
|
|
public readonly children: ParagraphChild[];
|
2018-07-24 15:56:13 -04:00
|
|
|
public readonly end: BookmarkEnd;
|
|
|
|
|
2021-09-01 12:20:54 -06:00
|
|
|
constructor(options: { readonly id: string; readonly children: ParagraphChild[] }) {
|
2021-03-12 03:58:05 +00:00
|
|
|
const linkId = uniqueId();
|
2018-07-24 15:56:13 -04:00
|
|
|
|
2020-01-01 22:54:42 +00:00
|
|
|
this.start = new BookmarkStart(options.id, linkId);
|
|
|
|
this.children = options.children;
|
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 {
|
2020-01-01 22:54:42 +00:00
|
|
|
constructor(id: string, linkId: string) {
|
2018-07-24 15:56:13 -04:00
|
|
|
super("w:bookmarkStart");
|
|
|
|
|
|
|
|
const attributes = new BookmarkStartAttributes({
|
2020-01-01 22:54:42 +00:00
|
|
|
name: id,
|
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);
|
|
|
|
}
|
|
|
|
}
|