Add footnote support to API
This commit is contained in:
14
demo/demo16.js
Normal file
14
demo/demo16.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const docx = require('../build');
|
||||||
|
|
||||||
|
var doc = new docx.Document();
|
||||||
|
|
||||||
|
var paragraph = new docx.Paragraph("Hello World").referenceFootnote(1);
|
||||||
|
|
||||||
|
doc.addParagraph(paragraph);
|
||||||
|
|
||||||
|
doc.createFootnote(new docx.Paragraph("Test"));
|
||||||
|
|
||||||
|
var exporter = new docx.LocalPacker(doc);
|
||||||
|
exporter.pack('My Document');
|
||||||
|
|
||||||
|
console.log('Document created successfully at project root!');
|
@ -32,5 +32,6 @@ export class ContentTypes extends XmlComponent {
|
|||||||
this.root.push(new Override("application/vnd.openxmlformats-package.core-properties+xml", "/docProps/core.xml"));
|
this.root.push(new Override("application/vnd.openxmlformats-package.core-properties+xml", "/docProps/core.xml"));
|
||||||
this.root.push(new Override("application/vnd.openxmlformats-officedocument.extended-properties+xml", "/docProps/app.xml"));
|
this.root.push(new Override("application/vnd.openxmlformats-officedocument.extended-properties+xml", "/docProps/app.xml"));
|
||||||
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", "/word/numbering.xml"));
|
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", "/word/numbering.xml"));
|
||||||
|
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", "/word/footnotes.xml"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,10 @@ export class File {
|
|||||||
return hyperlink;
|
return hyperlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createFootnote(paragraph: Paragraph): void {
|
||||||
|
this.footNotes.createFootNote(paragraph);
|
||||||
|
}
|
||||||
|
|
||||||
public get Document(): Document {
|
public get Document(): Document {
|
||||||
return this.document;
|
return this.document;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
import { Paragraph } from "../paragraph";
|
import { Paragraph } from "../paragraph";
|
||||||
import { FootNote } from "./footnote/footnote";
|
import { FootNote } from "./footnote/footnote";
|
||||||
|
import { ContinuationSeperatorRun } from "./footnote/run/continuation-seperator-run";
|
||||||
|
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 {
|
||||||
@ -28,32 +30,30 @@ export class FootNotes extends XmlComponent {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const begin = new FootNote(-1);
|
const begin = new FootNote(-1, "separator");
|
||||||
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()),
|
||||||
);
|
);
|
||||||
this.root.push(begin);
|
this.root.push(begin);
|
||||||
|
|
||||||
const spacing = new FootNote(0);
|
const spacing = new FootNote(0, "continuationSeparator");
|
||||||
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()),
|
||||||
);
|
);
|
||||||
this.root.push(spacing);
|
this.root.push(spacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createFootNote(): void {
|
public createFootNote(paragraph: Paragraph): void {
|
||||||
// TODO
|
const footnote = new FootNote(1);
|
||||||
}
|
footnote.addParagraph(paragraph);
|
||||||
|
this.root.push(footnote);
|
||||||
public getFootNote(): void {
|
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// http://officeopenxml.com/WPparagraph.php
|
// http://officeopenxml.com/WPparagraph.php
|
||||||
|
import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run";
|
||||||
import { IMediaData } from "file/media";
|
import { IMediaData } from "file/media";
|
||||||
import { Num } from "file/numbering/num";
|
import { Num } from "file/numbering/num";
|
||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
import { PictureRun, Run, TextRun } from "./run";
|
|
||||||
|
|
||||||
import { Alignment } from "./formatting/alignment";
|
import { Alignment } from "./formatting/alignment";
|
||||||
import { ThematicBreak } from "./formatting/border";
|
import { ThematicBreak } from "./formatting/border";
|
||||||
@ -15,6 +15,7 @@ import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./for
|
|||||||
import { NumberProperties } from "./formatting/unordered-list";
|
import { NumberProperties } from "./formatting/unordered-list";
|
||||||
import { Hyperlink } from "./links";
|
import { Hyperlink } from "./links";
|
||||||
import { ParagraphProperties } from "./properties";
|
import { ParagraphProperties } from "./properties";
|
||||||
|
import { PictureRun, Run, TextRun } from "./run";
|
||||||
|
|
||||||
export class Paragraph extends XmlComponent {
|
export class Paragraph extends XmlComponent {
|
||||||
private properties: ParagraphProperties;
|
private properties: ParagraphProperties;
|
||||||
@ -181,4 +182,9 @@ export class Paragraph extends XmlComponent {
|
|||||||
this.properties.push(new KeepLines());
|
this.properties.push(new KeepLines());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public referenceFootnote(id: number): Paragraph {
|
||||||
|
this.root.push(new FootnoteReferenceRun(id));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import { Underline } from "./underline";
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export class Run extends XmlComponent {
|
export class Run extends XmlComponent {
|
||||||
private properties: RunProperties;
|
protected properties: RunProperties;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:r");
|
super("w:r");
|
||||||
|
Reference in New Issue
Block a user