initial functionality

This commit is contained in:
Michael Myers
2018-07-24 15:56:13 -04:00
parent 0186450221
commit 8ceb38963e
7 changed files with 118 additions and 7 deletions

View File

@ -0,0 +1,23 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IBookmarkStartAttributesProperties {
id: string;
name: string;
}
export class BookmarkStartAttributes extends XmlAttributeComponent<IBookmarkStartAttributesProperties> {
protected xmlKeys = {
id: "w:id",
name: "w:name",
};
}
export interface IBookmarkEndAttributesProperties {
id: string;
}
export class BookmarkEndAttributes extends XmlAttributeComponent<IBookmarkEndAttributesProperties> {
protected xmlKeys = {
id: "w:id",
};
}

View File

@ -0,0 +1,57 @@
// http://officeopenxml.com/WPbookmark.php
import { XmlComponent } from "file/xml-components";
import { TextRun } from "../run";
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
export class Bookmark {
public linkId: number;
public readonly start: BookmarkStart;
public readonly text: TextRun;
public readonly end: BookmarkEnd;
constructor(name: string, text: string, relationshipsCount: number) {
this.linkId = relationshipsCount + 1;
this.start = new BookmarkStart(name, text, this.linkId);
this.text = new TextRun(text);
this.end = new BookmarkEnd(this.linkId);
}
}
export class BookmarkStart extends XmlComponent {
public linkId: number;
constructor(name: string, text: string, relationshipsCount: number) {
super("w:bookmarkStart");
this.linkId = relationshipsCount;
const id = `${this.linkId}`;
const attributes = new BookmarkStartAttributes({
name,
id,
});
this.root.push(attributes);
}
}
export class BookmarkEnd extends XmlComponent {
public linkId: number;
constructor(relationshipsCount: number) {
super("w:bookmarkEnd");
this.linkId = relationshipsCount;
const id = `${this.linkId}`;
const attributes = new BookmarkEndAttributes({
id,
});
this.root.push(attributes);
}
}

View File

@ -2,6 +2,7 @@ import { XmlAttributeComponent } from "file/xml-components";
export interface IHyperlinkAttributesProperties {
id?: string;
anchor?: string;
history: number;
}
@ -9,5 +10,6 @@ export class HyperlinkAttributes extends XmlAttributeComponent<IHyperlinkAttribu
protected xmlKeys = {
id: "r:id",
history: "w:history",
anchor: "w:anchor",
};
}

View File

@ -2,19 +2,27 @@
import { XmlComponent } from "file/xml-components";
import { TextRun } from "../run";
import { HyperlinkAttributes } from "./hyperlink-attributes";
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
export class Hyperlink extends XmlComponent {
public linkId: number;
constructor(text: string, relationshipsCount: number) {
constructor(text: string, relationshipsCount: number, anchor?: string) {
super("w:hyperlink");
this.linkId = relationshipsCount + 1;
const attributes = new HyperlinkAttributes({
id: `rId${this.linkId}`,
const props: IHyperlinkAttributesProperties = {
history: 1,
});
};
if (anchor) {
props.anchor = anchor;
} else {
props.id = `rId${this.linkId}`;
}
const attributes = new HyperlinkAttributes(props);
this.root.push(attributes);
this.root.push(new TextRun(text).style("Hyperlink"));
}

View File

@ -1 +1,2 @@
export * from "./hyperlink";
export * from "./bookmark";