diff --git a/src/file/styles/style-options.ts b/src/file/styles/style-options.ts index dcedadbec5..744f4244fb 100644 --- a/src/file/styles/style-options.ts +++ b/src/file/styles/style-options.ts @@ -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; diff --git a/src/file/styles/style/paragraph-style.spec.ts b/src/file/styles/style/paragraph-style.spec.ts index 93b0c6777c..8d9b4da15a 100644 --- a/src/file/styles/style/paragraph-style.spec.ts +++ b/src/file/styles/style/paragraph-style.spec.ts @@ -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", diff --git a/src/file/styles/style/paragraph-style.ts b/src/file/styles/style/paragraph-style.ts index a47a33f492..3adb1edbbe 100644 --- a/src/file/styles/style/paragraph-style.ts +++ b/src/file/styles/style/paragraph-style.ts @@ -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)); }