diff --git a/src/file/numbering/level.spec.ts b/src/file/numbering/level.spec.ts index 5748a9c610..608474888a 100644 --- a/src/file/numbering/level.spec.ts +++ b/src/file/numbering/level.spec.ts @@ -1,5 +1,7 @@ import { expect } from "chai"; +import { Formatter } from "@export/formatter"; + import { LevelFormat, LevelSuffix } from "."; import { AlignmentType } from ".."; @@ -22,4 +24,41 @@ describe("Level", () => { ).to.throw(); }); }); + + describe("isLegalNumberingStyle", () => { + it("should work", () => { + const concreteNumbering = new Level({ + level: 9, + isLegalNumberingStyle: true, + }); + const tree = new Formatter().format(concreteNumbering); + expect(tree).to.deep.equal({ + "w:lvl": [ + { + "w:start": { + _attr: { + "w:val": 1, + }, + }, + }, + { + "w:isLgl": {}, + }, + { + "w:lvlJc": { + _attr: { + "w:val": "start", + }, + }, + }, + { + _attr: { + "w15:tentative": 1, + "w:ilvl": 9, + }, + }, + ], + }); + }); + }); }); diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index 225a1f2004..cedf0745a7 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -87,6 +87,7 @@ export interface ILevelsOptions { readonly alignment?: AlignmentType; readonly start?: number; readonly suffix?: LevelSuffix; + readonly isLegalNumberingStyle?: boolean; readonly style?: { readonly run?: IRunStylePropertiesOptions; readonly paragraph?: ILevelParagraphStylePropertiesOptions; @@ -114,6 +115,14 @@ class Suffix extends XmlComponent { } } +// http://officeopenxml.com/WPnumbering-isLgl.php +// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.islegalnumberingstyle?view=openxml-2.8.1 +class IsLegalNumberingStyle extends XmlComponent { + constructor() { + super("w:isLgl"); + } +} + // // // @@ -137,7 +146,7 @@ export class LevelBase extends XmlComponent { private readonly paragraphProperties: ParagraphProperties; private readonly runProperties: RunProperties; - constructor({ level, format, text, alignment = AlignmentType.START, start = 1, style, suffix }: ILevelsOptions) { + constructor({ level, format, text, alignment = AlignmentType.START, start = 1, style, suffix, isLegalNumberingStyle }: ILevelsOptions) { super("w:lvl"); this.root.push(new NumberValueElement("w:start", decimalNumber(start))); @@ -150,6 +159,10 @@ export class LevelBase extends XmlComponent { this.root.push(new Suffix(suffix)); } + if (isLegalNumberingStyle) { + this.root.push(new IsLegalNumberingStyle()); + } + if (text) { this.root.push(new LevelText(text)); }