Multiple paragraphs in footnotes
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IFootnoteAttributesProperties {
|
||||
export class FootnoteAttributes extends XmlAttributeComponent<{
|
||||
readonly type?: string;
|
||||
readonly id: number;
|
||||
}
|
||||
|
||||
export class FootnoteAttributes extends XmlAttributeComponent<IFootnoteAttributesProperties> {
|
||||
}> {
|
||||
protected readonly xmlKeys = {
|
||||
type: "w:type",
|
||||
id: "w:id",
|
||||
|
@ -7,7 +7,11 @@ 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,
|
||||
children: [],
|
||||
});
|
||||
const tree = new Formatter().format(footnote);
|
||||
|
||||
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
||||
@ -15,7 +19,10 @@ describe("Footnote", () => {
|
||||
});
|
||||
|
||||
it("should create a footnote without a footnote type", () => {
|
||||
const footnote = new Footnote(1);
|
||||
const footnote = new Footnote({
|
||||
id: 1,
|
||||
children: [],
|
||||
});
|
||||
const tree = new Formatter().format(footnote);
|
||||
|
||||
expect(Object.keys(tree)).to.deep.equal(["w:footnote"]);
|
||||
|
@ -10,18 +10,23 @@ export enum FootnoteType {
|
||||
}
|
||||
|
||||
export class Footnote extends XmlComponent {
|
||||
constructor(id: number, type?: FootnoteType) {
|
||||
constructor(options: { readonly id: number; readonly type?: FootnoteType; readonly children: Paragraph[] }) {
|
||||
super("w:footnote");
|
||||
this.root.push(
|
||||
new FootnoteAttributes({
|
||||
type: type,
|
||||
id: id,
|
||||
type: options.type,
|
||||
id: options.id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public add(paragraph: Paragraph): void {
|
||||
paragraph.addRunToFront(new FootnoteRefRun());
|
||||
this.root.push(paragraph);
|
||||
for (let i = 0; i < options.children.length; i++) {
|
||||
const child = options.children[i];
|
||||
|
||||
if (i === 0) {
|
||||
child.addRunToFront(new FootnoteRefRun());
|
||||
}
|
||||
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,9 @@ import { Run } from "file/paragraph/run";
|
||||
import { Style } from "file/paragraph/run/style";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface IFootNoteReferenceRunAttributesProperties {
|
||||
export class FootNoteReferenceRunAttributes extends XmlAttributeComponent<{
|
||||
readonly id: number;
|
||||
}
|
||||
|
||||
export class FootNoteReferenceRunAttributes extends XmlAttributeComponent<IFootNoteReferenceRunAttributesProperties> {
|
||||
}> {
|
||||
protected readonly xmlKeys = {
|
||||
id: "w:id",
|
||||
};
|
||||
|
Reference in New Issue
Block a user