Add counter to footnotes

This commit is contained in:
Dolan Miu
2018-06-30 23:50:02 +01:00
parent e5fae3af64
commit b8934c68f2
2 changed files with 22 additions and 12 deletions

View File

@ -3,7 +3,6 @@ import { Formatter } from "../../../export/formatter";
import { Footnote, FootnoteType } from "./footnote"; import { Footnote, FootnoteType } from "./footnote";
describe("Footnote", () => { describe("Footnote", () => {
describe("#constructor", () => { describe("#constructor", () => {
it("should create a footnote with a footnote type", () => { it("should create a footnote with a footnote type", () => {
const footnote = new Footnote(1, FootnoteType.SEPERATOR); const footnote = new Footnote(1, FootnoteType.SEPERATOR);

View File

@ -6,8 +6,13 @@ import { SeperatorRun } from "./footnote/run/seperator-run";
import { FootnotesAttributes } from "./footnotes-attributes"; import { FootnotesAttributes } from "./footnotes-attributes";
export class FootNotes extends XmlComponent { export class FootNotes extends XmlComponent {
private counter: number;
constructor() { constructor() {
super("w:footnotes"); super("w:footnotes");
this.counter = 1;
this.root.push( this.root.push(
new FootnotesAttributes({ new FootnotesAttributes({
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
@ -32,28 +37,34 @@ export class FootNotes extends XmlComponent {
const begin = new Footnote(-1, FootnoteType.SEPERATOR); const begin = new Footnote(-1, FootnoteType.SEPERATOR);
begin.addParagraph( begin.addParagraph(
new Paragraph().spacing({ new Paragraph()
.spacing({
after: 0, after: 0,
line: 240, line: 240,
lineRule: "auto", lineRule: "auto",
}).addRun(new SeperatorRun()), })
.addRun(new SeperatorRun()),
); );
this.root.push(begin); this.root.push(begin);
const spacing = new Footnote(0, FootnoteType.CONTINUATION_SEPERATOR); const spacing = new Footnote(0, FootnoteType.CONTINUATION_SEPERATOR);
spacing.addParagraph( spacing.addParagraph(
new Paragraph().spacing({ new Paragraph()
.spacing({
after: 0, after: 0,
line: 240, line: 240,
lineRule: "auto", lineRule: "auto",
}).addRun(new ContinuationSeperatorRun()), })
.addRun(new ContinuationSeperatorRun()),
); );
this.root.push(spacing); this.root.push(spacing);
} }
public createFootNote(paragraph: Paragraph): void { public createFootNote(paragraph: Paragraph): void {
const footnote = new Footnote(1); const footnote = new Footnote(this.counter);
footnote.addParagraph(paragraph); footnote.addParagraph(paragraph);
this.root.push(footnote); this.root.push(footnote);
this.counter++;
} }
} }