Files
docx-js/src/file/paragraph/links/hyperlink.ts
Dolan 0de7116b78 #773 Better hyperlink and bookmark syntax
Allow for images to be hyperlinked as well
2021-02-27 19:23:29 +00:00

43 lines
1.3 KiB
TypeScript

// http://officeopenxml.com/WPhyperlink.php
import * as shortid from "shortid";
import { XmlComponent } from "file/xml-components";
import { ParagraphChild } from "../paragraph";
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
export enum HyperlinkType {
INTERNAL = "INTERNAL",
EXTERNAL = "EXTERNAL",
}
export class ConcreteHyperlink extends XmlComponent {
public readonly linkId: string;
constructor(child: ParagraphChild, relationshipId: string, anchor?: string) {
super("w:hyperlink");
this.linkId = relationshipId;
const props: IHyperlinkAttributesProperties = {
history: 1,
anchor: anchor ? anchor : undefined,
id: !anchor ? `rId${this.linkId}` : undefined,
};
const attributes = new HyperlinkAttributes(props);
this.root.push(attributes);
this.root.push(child);
}
}
export class InternalHyperlink extends ConcreteHyperlink {
constructor(options: { readonly child: ParagraphChild; readonly anchor: string }) {
super(options.child, shortid.generate().toLowerCase(), options.anchor);
}
}
export class ExternalHyperlink {
constructor(public readonly options: { readonly child: ParagraphChild; readonly link: string }) {}
}