add hyperlink to paragraph and doc
This commit is contained in:
@ -7,7 +7,7 @@ import { FooterWrapper } from "./footer-wrapper";
|
|||||||
import { HeaderWrapper } from "./header-wrapper";
|
import { HeaderWrapper } from "./header-wrapper";
|
||||||
import { Media } from "./media";
|
import { Media } from "./media";
|
||||||
import { Numbering } from "./numbering";
|
import { Numbering } from "./numbering";
|
||||||
import { Paragraph, PictureRun } from "./paragraph";
|
import { Hyperlink, Paragraph, PictureRun } from "./paragraph";
|
||||||
import { Relationships } from "./relationships";
|
import { Relationships } from "./relationships";
|
||||||
import { Styles } from "./styles";
|
import { Styles } from "./styles";
|
||||||
import { DefaultStylesFactory } from "./styles/factory";
|
import { DefaultStylesFactory } from "./styles/factory";
|
||||||
@ -111,6 +111,18 @@ export class File {
|
|||||||
return this.document.createDrawing(mediaData);
|
return this.document.createDrawing(mediaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createHyperlink(link: string, text?: string): Hyperlink {
|
||||||
|
text = text === undefined ? link : text;
|
||||||
|
const hyperlink = new Hyperlink(text, this.docRelationships.RelationshipCount);
|
||||||
|
this.docRelationships.createRelationship(
|
||||||
|
hyperlink.linkId,
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
|
||||||
|
link,
|
||||||
|
"External",
|
||||||
|
);
|
||||||
|
return hyperlink;
|
||||||
|
}
|
||||||
|
|
||||||
public get Document(): Document {
|
public get Document(): Document {
|
||||||
return this.document;
|
return this.document;
|
||||||
}
|
}
|
||||||
|
@ -2,3 +2,4 @@ export * from "./formatting";
|
|||||||
export * from "./paragraph";
|
export * from "./paragraph";
|
||||||
export * from "./properties";
|
export * from "./properties";
|
||||||
export * from "./run";
|
export * from "./run";
|
||||||
|
export * from "./links";
|
||||||
|
@ -13,6 +13,7 @@ import { ISpacingProperties, Spacing } from "./formatting/spacing";
|
|||||||
import { Style } from "./formatting/style";
|
import { Style } from "./formatting/style";
|
||||||
import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
|
import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
|
||||||
import { NumberProperties } from "./formatting/unordered-list";
|
import { NumberProperties } from "./formatting/unordered-list";
|
||||||
|
import { Hyperlink } from "./links";
|
||||||
import { ParagraphProperties } from "./properties";
|
import { ParagraphProperties } from "./properties";
|
||||||
|
|
||||||
export class Paragraph extends XmlComponent {
|
export class Paragraph extends XmlComponent {
|
||||||
@ -32,6 +33,11 @@ export class Paragraph extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addHyperLink(hyperlink: Hyperlink): Paragraph {
|
||||||
|
this.root.push(hyperlink);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public createTextRun(text: string): TextRun {
|
public createTextRun(text: string): TextRun {
|
||||||
const run = new TextRun(text);
|
const run = new TextRun(text);
|
||||||
this.addRun(run);
|
this.addRun(run);
|
||||||
|
Reference in New Issue
Block a user