diff --git a/.nycrc b/.nycrc index 1e3c3b1e22..d5f12ccbc3 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "lines": 92.34, - "functions": 88.27, + "lines": 92.35, + "functions": 88.28, "branches": 84.64, - "statements": 92.15, + "statements": 92.16, "include": [ "src/**/*.ts" ], diff --git a/src/file/document/body/body.spec.ts b/src/file/document/body/body.spec.ts index b63a95dcd1..a5bc222fb4 100644 --- a/src/file/document/body/body.spec.ts +++ b/src/file/document/body/body.spec.ts @@ -22,6 +22,9 @@ describe("Body", () => { expect(tree).to.deep.equal({ "w:body": [ + { + "w:p": {}, + }, { "w:sectPr": [ { "w:pgSz": { _attr: { "w:w": 10000, "w:h": 10000, "w:orient": "portrait" } } }, diff --git a/src/file/document/body/body.ts b/src/file/document/body/body.ts index c79edfc132..e91b72d59a 100644 --- a/src/file/document/body/body.ts +++ b/src/file/document/body/body.ts @@ -1,5 +1,5 @@ import { IXmlableObject, XmlComponent } from "file/xml-components"; -import { TableOfContents } from "../.."; +import { Paragraph, ParagraphProperties, TableOfContents } from "../.."; import { SectionProperties, SectionPropertiesOptions } from "./section-properties/section-properties"; export class Body extends XmlComponent { @@ -18,6 +18,9 @@ export class Body extends XmlComponent { * @param options new section options */ public addSection(options: SectionPropertiesOptions): void { + const currentSection = this.sections.pop() as SectionProperties; + this.root.push(this.createSectionParagraph(currentSection)); + this.sections.push(new SectionProperties(options)); } @@ -36,4 +39,12 @@ export class Body extends XmlComponent { public getTablesOfContents(): TableOfContents[] { return this.root.filter((child) => child instanceof TableOfContents) as TableOfContents[]; } + + private createSectionParagraph(section: SectionProperties): Paragraph { + const paragraph = new Paragraph({}); + const properties = new ParagraphProperties({}); + properties.addChildElement(section); + paragraph.addChildElement(properties); + return paragraph; + } } diff --git a/src/file/file.spec.ts b/src/file/file.spec.ts index 59b42e009c..b82748ca54 100644 --- a/src/file/file.spec.ts +++ b/src/file/file.spec.ts @@ -20,8 +20,8 @@ describe("File", () => { const tree = new Formatter().format(doc.Document.Body); - expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); - expect(tree["w:body"][0]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default"); }); it("should create with correct headers and footers", () => { @@ -39,8 +39,8 @@ describe("File", () => { const tree = new Formatter().format(doc.Document.Body); - expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); - expect(tree["w:body"][0]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][1]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default"); }); it("should create with first headers and footers", () => { @@ -58,8 +58,8 @@ describe("File", () => { const tree = new Formatter().format(doc.Document.Body); - expect(tree["w:body"][0]["w:sectPr"][5]["w:headerReference"]._attr["w:type"]).to.equal("first"); - expect(tree["w:body"][0]["w:sectPr"][7]["w:footerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][1]["w:sectPr"][5]["w:headerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][1]["w:sectPr"][7]["w:footerReference"]._attr["w:type"]).to.equal("first"); }); it("should create with correct headers", () => { @@ -81,13 +81,13 @@ describe("File", () => { const tree = new Formatter().format(doc.Document.Body); - expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); - expect(tree["w:body"][0]["w:sectPr"][5]["w:headerReference"]._attr["w:type"]).to.equal("first"); - expect(tree["w:body"][0]["w:sectPr"][6]["w:headerReference"]._attr["w:type"]).to.equal("even"); + expect(tree["w:body"][1]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][1]["w:sectPr"][5]["w:headerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][1]["w:sectPr"][6]["w:headerReference"]._attr["w:type"]).to.equal("even"); - expect(tree["w:body"][0]["w:sectPr"][7]["w:footerReference"]._attr["w:type"]).to.equal("default"); - expect(tree["w:body"][0]["w:sectPr"][8]["w:footerReference"]._attr["w:type"]).to.equal("first"); - expect(tree["w:body"][0]["w:sectPr"][9]["w:footerReference"]._attr["w:type"]).to.equal("even"); + expect(tree["w:body"][1]["w:sectPr"][7]["w:footerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][1]["w:sectPr"][8]["w:footerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][1]["w:sectPr"][9]["w:footerReference"]._attr["w:type"]).to.equal("even"); }); });