#627 Add footnotes relationships

This commit is contained in:
Dolan Miu
2021-03-01 23:35:52 +00:00
parent c6e9696be0
commit f90e84a88d
12 changed files with 107 additions and 66 deletions

View File

@ -7,7 +7,10 @@ import { Footnote, FootnoteType } from "./footnote";
describe("Footnote", () => {
describe("#constructor", () => {
it("should create a footnote with a footnote type", () => {
const footnote = new Footnote(1, FootnoteType.SEPERATOR);
const footnote = new Footnote({
id: 1,
type: FootnoteType.SEPERATOR,
});
const tree = new Formatter().format(footnote);
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
@ -15,7 +18,9 @@ describe("Footnote", () => {
});
it("should create a footnote without a footnote type", () => {
const footnote = new Footnote(1);
const footnote = new Footnote({
id: 1,
});
const tree = new Formatter().format(footnote);
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);

View File

@ -9,13 +9,18 @@ export enum FootnoteType {
CONTINUATION_SEPERATOR = "continuationSeparator",
}
export interface IFootnoteOptions {
readonly id: number;
readonly type?: FootnoteType;
}
export class Footnote extends XmlComponent {
constructor(id: number, type?: FootnoteType) {
constructor(options: IFootnoteOptions) {
super("w:footnote");
this.root.push(
new FootnoteAttributes({
type: type,
id: id,
type: options.type,
id: options.id,
}),
);
}

View File

@ -36,7 +36,10 @@ export class FootNotes extends XmlComponent {
}),
);
const begin = new Footnote(-1, FootnoteType.SEPERATOR);
const begin = new Footnote({
id: -1,
type: FootnoteType.SEPERATOR,
});
begin.add(
new Paragraph({
spacing: {
@ -49,7 +52,10 @@ export class FootNotes extends XmlComponent {
);
this.root.push(begin);
const spacing = new Footnote(0, FootnoteType.CONTINUATION_SEPERATOR);
const spacing = new Footnote({
id: 0,
type: FootnoteType.CONTINUATION_SEPERATOR,
});
spacing.add(
new Paragraph({
spacing: {
@ -64,7 +70,7 @@ export class FootNotes extends XmlComponent {
}
public createFootNote(paragraph: Paragraph): void {
const footnote = new Footnote(this.currentId);
const footnote = new Footnote({ id: this.currentId });
footnote.add(paragraph);
this.root.push(footnote);