external-styles: create correct XmlComponents from imported style

This commit is contained in:
Igor Bulovski
2018-06-27 21:55:15 +02:00
parent 52007785af
commit ed72d60951
2 changed files with 75 additions and 3 deletions

View File

@ -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