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
|
|
|
|
2019-12-21 03:31:09 +00:00
|
|
|
export enum HyperlinkType {
|
|
|
|
INTERNAL = "INTERNAL",
|
|
|
|
EXTERNAL = "EXTERNAL",
|
|
|
|
}
|
|
|
|
|
2019-12-18 21:11:15 +00:00
|
|
|
export class HyperlinkRef {
|
|
|
|
constructor(public readonly id: string) {}
|
|
|
|
}
|
|
|
|
|
2018-05-06 22:20:56 -05:00
|
|
|
export class Hyperlink extends XmlComponent {
|
2019-11-08 10:50:18 +01:00
|
|
|
public readonly linkId: string;
|
2019-02-26 13:26:01 +01:00
|
|
|
private readonly textRun: TextRun;
|
2018-05-06 22:20:56 -05:00
|
|
|
|
2019-11-08 10:50:18 +01:00
|
|
|
constructor(text: string, relationshipId: string, anchor?: string) {
|
2018-05-06 22:20:56 -05:00
|
|
|
super("w:hyperlink");
|
|
|
|
|
2019-11-08 10:50:18 +01:00
|
|
|
this.linkId = relationshipId;
|
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);
|
2019-06-17 01:51:57 +01:00
|
|
|
this.textRun = new TextRun({
|
|
|
|
text: text,
|
|
|
|
style: "Hyperlink",
|
|
|
|
});
|
2019-02-26 13:26:01 +01:00
|
|
|
this.root.push(this.textRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get TextRun(): TextRun {
|
|
|
|
return this.textRun;
|
2018-05-06 22:20:56 -05:00
|
|
|
}
|
|
|
|
}
|