Merge pull request #474 from kalda341/allow-contextual-spacing-paragraph-style

Allow contextual spacing to be specified as an argument to paragraph style
This commit is contained in:
Dolan
2019-12-13 23:22:39 +00:00
committed by GitHub
3 changed files with 42 additions and 1 deletions

View File

@ -29,6 +29,7 @@ export interface IRunStyleOptions {
export interface IParagraphStyleOptions2 {
readonly alignment?: AlignmentType;
readonly thematicBreak?: boolean;
readonly contextualSpacing?: boolean;
readonly rightTabStop?: number;
readonly leftTabStop?: number;
readonly indent?: IIndentAttributesProperties;

View File

@ -220,6 +220,32 @@ describe("ParagraphStyle", () => {
});
});
it("#contextualSpacing", () => {
const style = new ParagraphStyle({
id: "myStyleId",
paragraph: {
contextualSpacing: true,
},
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:pPr": [
{
"w:contextualSpacing": {
_attr: {
"w:val": 1,
},
},
},
],
},
],
});
});
it("#leftTabStop", () => {
const style = new ParagraphStyle({
id: "myStyleId",

View File

@ -1,4 +1,14 @@
import { Alignment, Indent, KeepLines, KeepNext, OutlineLevel, ParagraphProperties, Spacing, ThematicBreak } from "file/paragraph";
import {
Alignment,
ContextualSpacing,
Indent,
KeepLines,
KeepNext,
OutlineLevel,
ParagraphProperties,
Spacing,
ThematicBreak,
} from "file/paragraph";
import { TabStop, TabStopType } from "file/paragraph/formatting";
import * as formatting from "file/paragraph/run/formatting";
import { RunProperties } from "file/paragraph/run/properties";
@ -134,6 +144,10 @@ export class ParagraphStyle extends Style {
this.paragraphProperties.push(new ThematicBreak());
}
if (options.paragraph.contextualSpacing) {
this.paragraphProperties.push(new ContextualSpacing(options.paragraph.contextualSpacing));
}
if (options.paragraph.rightTabStop) {
this.paragraphProperties.push(new TabStop(TabStopType.RIGHT, options.paragraph.rightTabStop));
}