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

30 lines
841 B
TypeScript
Raw Normal View History

2018-05-06 22:20:56 -05:00
// http://officeopenxml.com/WPhyperlink.php
2018-05-06 23:18:00 -05:00
2018-05-06 22:20:56 -05:00
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 {
public linkId: number;
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-07-24 15:56:13 -04:00
};
if (anchor) {
props.anchor = anchor;
} else {
props.id = `rId${this.linkId}`;
}
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"));
}
}