From 996594da9bdf91912faf5b8158e0d55d39aaf080 Mon Sep 17 00:00:00 2001 From: Andrey Savin Date: Thu, 16 Sep 2021 13:01:47 +0300 Subject: [PATCH 1/3] Moving numbering from IParagraphPropertiesOptions to IParagraphStylePropertiesOptions --- src/file/paragraph/properties.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index bafac51776..6a2537f839 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -24,6 +24,12 @@ export interface IParagraphStylePropertiesOptions { readonly keepNext?: boolean; readonly keepLines?: boolean; readonly outlineLevel?: number; + readonly numbering?: { + readonly reference: string; + readonly level: number; + readonly instance?: number; + readonly custom?: boolean; + }; } export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions { @@ -40,12 +46,6 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp readonly bullet?: { readonly level: number; }; - readonly numbering?: { - readonly reference: string; - readonly level: number; - readonly instance?: number; - readonly custom?: boolean; - }; readonly shading?: IShadingAttributesProperties; readonly widowControl?: boolean; readonly frame?: IFrameOptions; From 75290aeaf5ed04bb00f4df3777468d466bc4a775 Mon Sep 17 00:00:00 2001 From: Andrey Savin Date: Thu, 16 Sep 2021 13:03:34 +0300 Subject: [PATCH 2/3] Adding numberingReplacer for styles.xml at next-compiler.ts --- src/export/packer/next-compiler.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index 3311301a61..24cf9d3186 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -123,19 +123,23 @@ export class Compiler { path: "word/document.xml", }, Styles: { - data: xml( - this.formatter.format(file.Styles, { - viewWrapper: file.Document, - file, - }), - { - indent: prettify, - declaration: { - standalone: "yes", - encoding: "UTF-8", + data: (() => { + const xmlStyles = xml( + this.formatter.format(file.Styles, { + viewWrapper: file.Document, + file, + }), + { + indent: prettify, + declaration: { + standalone: "yes", + encoding: "UTF-8", + }, }, - }, - ), + ); + const referencedXmlStyles = this.numberingReplacer.replace(xmlStyles, file.Numbering.ConcreteNumbering); + return referencedXmlStyles; + })(), path: "word/styles.xml", }, Properties: { From bc1bca762e971014d37645d834525405e1439046 Mon Sep 17 00:00:00 2001 From: Andrey Savin Date: Thu, 16 Sep 2021 13:21:21 +0300 Subject: [PATCH 3/3] Demo on numbering attaching to custom styles --- demo/11-declaritive-styles-2.ts | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/demo/11-declaritive-styles-2.ts b/demo/11-declaritive-styles-2.ts index 3881e2f258..1035faab45 100644 --- a/demo/11-declaritive-styles-2.ts +++ b/demo/11-declaritive-styles-2.ts @@ -15,6 +15,7 @@ import { TableRow, TabStopPosition, UnderlineType, + LevelFormat, } from "../build"; const table = new Table({ @@ -51,6 +52,19 @@ const table = new Table({ }); const doc = new Document({ + numbering:{ + config:[{ + reference: 'ref1', + levels: [ + { + level: 0, + format: LevelFormat.DECIMAL, + text: '%1)', + start: 50, + } + ], + }] + }, styles: { default: { heading1: { @@ -155,6 +169,28 @@ const doc = new Document({ spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 }, }, }, + { + id: "numberedPara", + name: "Numbered Para", + basedOn: "Normal", + next: "Normal", + quickFormat: true, + run: { + font: "Calibri", + size: 26, + bold: true, + }, + paragraph: { + spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 }, + rightTabStop: TabStopPosition.MAX, + leftTabStop: 453.543307087, + numbering : { + reference: 'ref1', + instance: 0, + level: 0, + } + }, + }, ], }, sections: [ @@ -260,6 +296,14 @@ const doc = new Document({ text: "Test 2", style: "normalPara2", }), + new Paragraph({ + text: "Numbered paragraph that has numbering attached to custom styles", + style: "numberedPara", + }), + new Paragraph({ + text: "Numbered para would show up in the styles pane at Word", + style: "numberedPara", + }), ], }, ],