Merge branch 'master' of https://github.com/h4buli/docx into feat/h4-update

# Conflicts:
#	package.json
#	src/file/document/body/body.ts
#	src/file/document/body/section-properties/section-properties.ts
#	src/file/file.ts
#	src/file/media/media.ts
#	src/file/styles/external-styles-factory.ts
#	src/file/table/table-cell.ts
This commit is contained in:
Dolan
2018-08-09 23:21:24 +01:00
19 changed files with 366 additions and 37 deletions

View File

@ -0,0 +1,29 @@
export enum BorderStyle {
SINGLE = "single",
DASH_DOT_STROKED = "dashDotStroked",
DASHED = "dashed",
DASH_SMALL_GAP = "dashSmallGap",
DOT_DASH = "dotDash",
DOT_DOT_DASH = "dotDotDash",
DOTTED = "dotted",
DOUBLE = "double",
DOUBLE_WAVE = "doubleWave",
INSET = "inset",
NIL = "nil",
NONE = "none",
OUTSET = "outset",
THICK = "thick",
THICK_THIN_LARGE_GAP = "thickThinLargeGap",
THICK_THIN_MEDIUM_GAP = "thickThinMediumGap",
THICK_THIN_SMALL_GAP = "thickThinSmallGap",
THIN_THICK_LARGE_GAP = "thinThickLargeGap",
THIN_THICK_MEDIUM_GAP = "thinThickMediumGap",
THIN_THICK_SMALL_GAP = "thinThickSmallGap",
THIN_THICK_THIN_LARGE_GAP = "thinThickThinLargeGap",
THIN_THICK_THIN_MEDIUM_GAP = "thinThickThinMediumGap",
THIN_THICK_THIN_SMALL_GAP = "thinThickThinSmallGap",
THREE_D_EMBOSS = "threeDEmboss",
THREE_D_ENGRAVE = "threeDEngrave",
TRIPLE = "triple",
WAVE = "wave",
}

View File

@ -0,0 +1 @@
export * from "./border-style";

View File

@ -10,6 +10,17 @@ describe("External styles factory", () => {
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:styles xmlns:mc="first" xmlns:r="second">
<w:docDefaults>
<w:rPrDefault>
<w:rPr>
<w:rFonts w:ascii="Arial" w:eastAsiaTheme="minorHAnsi" w:hAnsi="Arial" w:cstheme="minorHAnsi"/>
<w:lang w:val="en-US" w:eastAsia="en-US" w:bidi="ar-SA"/>
</w:rPr>
</w:rPrDefault>
<w:pPrDefault>
<w:pPr>
<w:spacing w:after="160" w:line="259" w:lineRule="auto"/>
</w:pPr>
</w:pPrDefault>
</w:docDefaults>
<w:latentStyles w:defLockedState="1" w:defUIPriority="99">
@ -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({

View File

@ -1,5 +1,7 @@
import * as fastXmlParser from "fast-xml-parser";
import { ImportedXmlComponent, ImportedRootElementAttributes, parseOptions, convertToXmlComponent } from "./../../file/xml-components";
import { convertToXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, parseOptions } from "file/xml-components";
import { ImportedRootElementAttributes, parseOptions, convertToXmlComponent } from "./../../file/xml-components";
import { Styles } from "./";
export class ExternalStylesFactory {
@ -34,7 +36,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

View File

@ -1,6 +1,7 @@
import { BaseXmlComponent, XmlComponent } from "file/xml-components";
import { DocumentDefaults } from "./defaults";
import { ParagraphStyle } from "./style";
export * from "./border";
export class Styles extends XmlComponent {
constructor(initialStyles?: BaseXmlComponent) {