#532 Make hyperlinks work on the Header and Footer

This commit is contained in:
Dolan Miu
2021-03-01 03:28:35 +00:00
parent 655b40d418
commit c6e9696be0
9 changed files with 53 additions and 36 deletions

View File

@ -1,6 +1,7 @@
import { IViewWrapper } from "file/document-wrapper";
import { IXmlableObject, XmlComponent } from "file/xml-components";
import { Paragraph, ParagraphProperties, TableOfContents } from "../..";
import { File } from "../../../file";
import { SectionProperties, SectionPropertiesOptions } from "./section-properties/section-properties";
export class Body extends XmlComponent {
@ -25,7 +26,7 @@ export class Body extends XmlComponent {
this.sections.push(new SectionProperties(options));
}
public prepForXml(file?: File): IXmlableObject | undefined {
public prepForXml(file?: IViewWrapper): IXmlableObject | undefined {
if (this.sections.length === 1) {
this.root.splice(0, 1);
this.root.push(this.sections.pop() as SectionProperties);

View File

@ -5,7 +5,7 @@ import { stub } from "sinon";
import { Formatter } from "export/formatter";
import { EMPTY_OBJECT } from "file/xml-components";
import { File } from "../file";
import { IViewWrapper } from "../document-wrapper";
import { ShadingType } from "../table/shading";
import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting";
import { Bookmark, ExternalHyperlink } from "./links";
@ -804,12 +804,10 @@ describe("Paragraph", () => {
],
});
const fileMock = ({
Document: {
Relationships: {
createRelationship: () => ({}),
},
Relationships: {
createRelationship: () => ({}),
},
} as unknown) as File;
} as unknown) as IViewWrapper;
paragraph.prepForXml(fileMock);
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({

View File

@ -4,7 +4,7 @@ import * as shortid from "shortid";
import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run";
import { IXmlableObject, XmlComponent } from "file/xml-components";
import { File } from "../file";
import { IViewWrapper } from "../document-wrapper";
import { TargetModeType } from "../relationships/relationship/relationship";
import { DeletedTextRun, InsertedTextRun } from "../track-revision";
import { PageBreak } from "./formatting/page-break";
@ -74,12 +74,12 @@ export class Paragraph extends XmlComponent {
}
}
public prepForXml(file: File): IXmlableObject | undefined {
public prepForXml(file: IViewWrapper): IXmlableObject | undefined {
for (const element of this.root) {
if (element instanceof ExternalHyperlink) {
const index = this.root.indexOf(element);
const concreteHyperlink = new ConcreteHyperlink(element.options.child, shortid.generate().toLowerCase());
file.Document.Relationships.createRelationship(
file.Relationships.createRelationship(
concreteHyperlink.linkId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
element.options.link,

View File

@ -1,9 +1,9 @@
// http://officeopenxml.com/WPtableGrid.php
import { IViewWrapper } from "file/document-wrapper";
import { Paragraph } from "file/paragraph";
import { BorderStyle } from "file/styles";
import { IXmlableObject, XmlComponent } from "file/xml-components";
import { File } from "../../file";
import { ITableShadingAttributesProperties } from "../shading";
import { Table } from "../table";
import { ITableCellMarginOptions } from "./cell-margin/table-cell-margins";
@ -115,7 +115,7 @@ export class TableCell extends XmlComponent {
}
}
public prepForXml(file?: File): IXmlableObject | undefined {
public prepForXml(file?: IViewWrapper): IXmlableObject | undefined {
// Cells must end with a paragraph
if (!(this.root[this.root.length - 1] instanceof Paragraph)) {
this.root.push(new Paragraph({}));

View File

@ -1,4 +1,4 @@
import { File } from "../file";
import { IViewWrapper } from "../document-wrapper";
import { IXmlableObject } from "./xmlable-object";
export abstract class BaseXmlComponent {
@ -10,7 +10,7 @@ export abstract class BaseXmlComponent {
this.rootKey = rootKey;
}
public abstract prepForXml(file?: File): IXmlableObject | undefined;
public abstract prepForXml(file?: IViewWrapper): IXmlableObject | undefined;
public get IsDeleted(): boolean {
return this.deleted;

View File

@ -1,4 +1,4 @@
import { File } from "../file";
import { IViewWrapper } from "../document-wrapper";
import { BaseXmlComponent } from "./base";
import { IXmlableObject } from "./xmlable-object";
@ -13,7 +13,7 @@ export abstract class XmlComponent extends BaseXmlComponent {
this.root = new Array<BaseXmlComponent | string>();
}
public prepForXml(file?: File): IXmlableObject | undefined {
public prepForXml(file?: IViewWrapper): IXmlableObject | undefined {
const children = this.root
.filter((c) => {
if (c instanceof BaseXmlComponent) {