diff --git a/docs/usage/numbering.md b/docs/usage/numbering.md index 444ad51b360..489b5783252 100644 --- a/docs/usage/numbering.md +++ b/docs/usage/numbering.md @@ -130,6 +130,62 @@ new Paragraph({ }), ``` +## Disabling numbering inherited from paragraph style + +If the numbering is set on a paragraph style, you may wish to disable it for a specific paragraph: + +```ts +const doc = new Document({ + ... + numbering: { + config: [ + { + reference: "my-bullet-points", + levels: [ + { + level: 0, + format: LevelFormat.BULLET, + text: "\u1F60", + alignment: AlignmentType.LEFT, + style: { + paragraph: { + indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) }, + }, + }, + }, + ], + }, + ], + }, + styles: { + paragraphStyles: [ + { + id: 'bullet', + name: 'Bullet', + basedOn: 'Normal', + next: 'Normal', + run: {}, + paragraph: { + numbering: { + reference: 'my-bullet-points', + level: 0, + }, + }, + }, + ], + }, + ... +}); +``` + +```ts +new Paragraph({ + text: "No bullet points!", + style: "Bullet", + numbering: false, +}), +``` + ## Full Example [Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/3-numbering-and-bullet-points.ts ":include") diff --git a/src/file/paragraph/properties.spec.ts b/src/file/paragraph/properties.spec.ts index 40879566f31..6aaf76f033c 100644 --- a/src/file/paragraph/properties.spec.ts +++ b/src/file/paragraph/properties.spec.ts @@ -65,6 +65,36 @@ describe("ParagraphProperties", () => { }); }); + it("should create with numbering disabled", () => { + const properties = new ParagraphProperties({ + numbering: false, + }); + const tree = new Formatter().format(properties); + + expect(tree).to.deep.equal({ + "w:pPr": [ + { + "w:numPr": [ + { + "w:ilvl": { + _attr: { + "w:val": 0, + }, + }, + }, + { + "w:numId": { + _attr: { + "w:val": 0, + }, + }, + }, + ], + }, + ], + }); + }); + it("should create with widowControl", () => { const properties = new ParagraphProperties({ widowControl: true, diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index c03cbc9c65f..4105fa252f6 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -37,12 +37,14 @@ export interface ILevelParagraphStylePropertiesOptions { } export interface IParagraphStylePropertiesOptions extends ILevelParagraphStylePropertiesOptions { - readonly numbering?: { - readonly reference: string; - readonly level: number; - readonly instance?: number; - readonly custom?: boolean; - }; + readonly numbering?: + | { + readonly reference: string; + readonly level: number; + readonly instance?: number; + readonly custom?: boolean; + } + | false; } export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions { @@ -135,6 +137,8 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { }); this.push(new NumberProperties(`${options.numbering.reference}-${options.numbering.instance ?? 0}`, options.numbering.level)); + } else if (options.numbering === false) { + this.push(new NumberProperties(0, 0)); } if (options.border) {