2018-05-06 22:20:56 -05:00
|
|
|
// http://officeopenxml.com/WPhyperlink.php
|
|
|
|
import { XmlComponent } from "file/xml-components";
|
|
|
|
import { TextRun } from "../run";
|
2018-07-24 15:56:13 -04:00
|
|
|
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
|
2018-05-06 22:20:56 -05:00
|
|
|
|
|
|
|
export class Hyperlink extends XmlComponent {
|
2018-11-02 02:51:57 +00:00
|
|
|
public readonly linkId: number;
|
2018-05-06 22:20:56 -05:00
|
|
|
|
2018-07-24 15:56:13 -04:00
|
|
|
constructor(text: string, relationshipsCount: number, anchor?: string) {
|
2018-05-06 22:20:56 -05:00
|
|
|
super("w:hyperlink");
|
|
|
|
|
|
|
|
this.linkId = relationshipsCount + 1;
|
2018-07-24 15:56:13 -04:00
|
|
|
|
|
|
|
const props: IHyperlinkAttributesProperties = {
|
2018-05-06 22:20:56 -05:00
|
|
|
history: 1,
|
2018-11-02 02:51:57 +00:00
|
|
|
anchor: anchor ? anchor : undefined,
|
|
|
|
id: !anchor ? `rId${this.linkId}` : undefined,
|
2018-07-24 15:56:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const attributes = new HyperlinkAttributes(props);
|
2018-05-06 23:18:00 -05:00
|
|
|
this.root.push(attributes);
|
2018-05-06 22:20:56 -05:00
|
|
|
this.root.push(new TextRun(text).style("Hyperlink"));
|
|
|
|
}
|
|
|
|
}
|