Merge pull request #819 from dolanmiu/feat/widow-control
#750 Add widow control
This commit is contained in:
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
||||
{
|
||||
"check-coverage": true,
|
||||
"lines": 97.86,
|
||||
"functions": 94.33,
|
||||
"branches": 94.99,
|
||||
"statements": 97.85,
|
||||
"lines": 98.19,
|
||||
"functions": 94.79,
|
||||
"branches": 95.23,
|
||||
"statements": 98.17,
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
|
19
src/file/paragraph/formatting/alignment.spec.ts
Normal file
19
src/file/paragraph/formatting/alignment.spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
import { Alignment, AlignmentType } from "./alignment";
|
||||
|
||||
describe("Alignment", () => {
|
||||
it("should create", () => {
|
||||
const alignment = new Alignment(AlignmentType.BOTH);
|
||||
const tree = new Formatter().format(alignment);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:jc": {
|
||||
_attr: {
|
||||
"w:val": "both",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
20
src/file/paragraph/formatting/widow-control.spec.ts
Normal file
20
src/file/paragraph/formatting/widow-control.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { WidowControl } from "./widow-control";
|
||||
|
||||
describe("WidowControl", () => {
|
||||
it("should create", () => {
|
||||
const widowControl = new WidowControl(true);
|
||||
const tree = new Formatter().format(widowControl);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:widowControl": {
|
||||
_attr: {
|
||||
"w:val": true,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
13
src/file/paragraph/formatting/widow-control.ts
Normal file
13
src/file/paragraph/formatting/widow-control.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-w_widowControl-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export class WidowControlAttributes extends XmlAttributeComponent<{ readonly val: boolean }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class WidowControl extends XmlComponent {
|
||||
constructor(value: boolean) {
|
||||
super("w:widowControl");
|
||||
this.root.push(new WidowControlAttributes({ val: value }));
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ describe("ParagraphProperties", () => {
|
||||
expect(() => new Formatter().format(properties)).to.throw("XMLComponent did not format correctly");
|
||||
});
|
||||
|
||||
it("should create", () => {
|
||||
it("should create with numbering", () => {
|
||||
const properties = new ParagraphProperties({
|
||||
numbering: {
|
||||
reference: "test-reference",
|
||||
@ -65,5 +65,35 @@ describe("ParagraphProperties", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create with widowControl", () => {
|
||||
const properties = new ParagraphProperties({
|
||||
widowControl: true,
|
||||
});
|
||||
const tree = new Formatter().format(properties, {
|
||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||
file: {
|
||||
Numbering: {
|
||||
createConcreteNumberingInstance: (_: string, __: number) => {
|
||||
return;
|
||||
},
|
||||
},
|
||||
} as File,
|
||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||
viewWrapper: new DocumentWrapper({ background: {} }),
|
||||
});
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:widowControl": {
|
||||
_attr: {
|
||||
"w:val": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -12,6 +12,7 @@ import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spa
|
||||
import { HeadingLevel, Style } from "./formatting/style";
|
||||
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
|
||||
import { NumberProperties } from "./formatting/unordered-list";
|
||||
import { WidowControl } from "./formatting/widow-control";
|
||||
import { OutlineLevel } from "./links";
|
||||
import { Shading } from "./run/formatting";
|
||||
|
||||
@ -53,6 +54,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
||||
readonly fill: string;
|
||||
readonly color: string;
|
||||
};
|
||||
readonly widowControl?: boolean;
|
||||
}
|
||||
|
||||
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
@ -153,6 +155,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
if (options.shading) {
|
||||
this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
|
||||
}
|
||||
|
||||
if (options.widowControl) {
|
||||
this.push(new WidowControl(options.widowControl));
|
||||
}
|
||||
}
|
||||
|
||||
public push(item: XmlComponent): void {
|
||||
|
Reference in New Issue
Block a user