From ed72d60951288e03eab5a08c154ea0243eb3b09a Mon Sep 17 00:00:00 2001 From: Igor Bulovski Date: Wed, 27 Jun 2018 21:55:15 +0200 Subject: [PATCH] external-styles: create correct XmlComponents from imported style --- .../styles/external-styles-factory.spec.ts | 69 ++++++++++++++++++- src/file/styles/external-styles-factory.ts | 9 ++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/file/styles/external-styles-factory.spec.ts b/src/file/styles/external-styles-factory.spec.ts index 861a6f05d8..e34bfbaa8d 100644 --- a/src/file/styles/external-styles-factory.spec.ts +++ b/src/file/styles/external-styles-factory.spec.ts @@ -10,6 +10,17 @@ describe("External styles factory", () => { + + + + + + + + + + + @@ -52,7 +63,63 @@ describe("External styles factory", () => { expect(importedStyle.root.length).to.equal(5); expect(importedStyle.root[1]).to.eql({ deleted: false, - root: [], + root: [ + { + deleted: false, + root: [ + { + deleted: false, + root: [ + { + _attr: { + "w:ascii": "Arial", + "w:cstheme": "minorHAnsi", + "w:eastAsiaTheme": "minorHAnsi", + "w:hAnsi": "Arial", + }, + deleted: false, + root: [], + rootKey: "w:rFonts", + }, + { + _attr: { + "w:bidi": "ar-SA", + "w:eastAsia": "en-US", + "w:val": "en-US", + }, + deleted: false, + root: [], + rootKey: "w:lang", + }, + ], + rootKey: "w:rPr", + }, + ], + rootKey: "w:rPrDefault", + }, + { + deleted: false, + root: [ + { + deleted: false, + root: [ + { + _attr: { + "w:after": "160", + "w:line": "259", + "w:lineRule": "auto", + }, + deleted: false, + root: [], + rootKey: "w:spacing", + }, + ], + rootKey: "w:pPr", + }, + ], + rootKey: "w:pPrDefault", + }, + ], rootKey: "w:docDefaults", }); expect(importedStyle.root[2]).to.eql({ diff --git a/src/file/styles/external-styles-factory.ts b/src/file/styles/external-styles-factory.ts index 9757faf8d9..7f54f03d4e 100644 --- a/src/file/styles/external-styles-factory.ts +++ b/src/file/styles/external-styles-factory.ts @@ -1,6 +1,6 @@ import { Styles } from "./"; import * as fastXmlParser from "fast-xml-parser"; -import { ImportedXmlComponent, ImportedRootElementAttributes, parseOptions, convertToXmlComponent } from "./../../file/xml-components"; +import { ImportedRootElementAttributes, parseOptions, convertToXmlComponent } from "./../../file/xml-components"; export class ExternalStylesFactory { /** @@ -34,7 +34,12 @@ export class ExternalStylesFactory { Object.keys(xmlStyles) .filter((element) => element !== "_attr" && element !== "w:style") .forEach((element) => { - importedStyle.push(new ImportedXmlComponent(element, xmlStyles[element]._attr)); + const converted = convertToXmlComponent(element, xmlStyles[element]); + if (Array.isArray(converted)) { + converted.forEach((c) => importedStyle.push(c)); + } else { + importedStyle.push(converted); + } }); // convert the styles one by one