Merge pull request #1325 from dolanmiu/feature/fix-bidi

Feature/fix bidi
This commit is contained in:
Dolan
2021-12-03 10:45:41 +00:00
committed by GitHub
5 changed files with 60 additions and 30 deletions

View File

@ -202,13 +202,14 @@ jobs:
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo
run: npm run ts-node -- ./demo/19-export-to-base64.ts
- name: Extract Word Document
run: npm run extract
- name: Validate XML
uses: ChristophWurst/xmllint-action@v1
with:
xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
# Base 64 No longer works, abruptly. Node issue?
# - name: Extract Word Document
# run: npm run extract
# - name: Validate XML
# uses: ChristophWurst/xmllint-action@v1
# with:
# xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo
run: npm run ts-node -- ./demo/20-table-cell-borders.ts
- name: Extract Word Document

6
.nycrc
View File

@ -1,9 +1,9 @@
{
"check-coverage": true,
"lines": 99.32,
"functions": 99.11,
"branches": 96.27,
"statements": 99.32,
"branches": 96.27,
"functions": 99.11,
"lines": 99.32,
"include": [
"src/**/*.ts"
],

View File

@ -44,14 +44,9 @@ export class Compiler {
public compile(file: File, prettifyXml?: boolean): JSZip {
const zip = new JSZip();
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
const map = new Map<string, IXmlifyedFile | IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
for (const key in xmlifiedFileMapping) {
if (!xmlifiedFileMapping[key]) {
continue;
}
const obj = xmlifiedFileMapping[key] as IXmlifyedFile | IXmlifyedFile[];
for (const [, obj] of map) {
if (Array.isArray(obj)) {
for (const subFile of obj) {
zip.file(subFile.path, subFile.data);

View File

@ -70,18 +70,7 @@ describe("ParagraphProperties", () => {
const properties = new ParagraphProperties({
widowControl: true,
});
const tree = new Formatter().format(properties, {
// tslint:disable-next-line: no-object-literal-type-assertion
file: {
Numbering: {
createConcreteNumberingInstance: (_: string, __: number) => {
return;
},
},
} as File,
// tslint:disable-next-line: no-object-literal-type-assertion
viewWrapper: new DocumentWrapper({ background: {} }),
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({
"w:pPr": [
@ -91,5 +80,50 @@ describe("ParagraphProperties", () => {
],
});
});
it("should create with the bidirectional property", () => {
const properties = new ParagraphProperties({
bidirectional: true,
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({
"w:pPr": [
{
"w:bidi": {},
},
],
});
});
it("should create with the contextualSpacing property", () => {
const properties = new ParagraphProperties({
contextualSpacing: true,
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({
"w:pPr": [
{
"w:contextualSpacing": {},
},
],
});
});
it("should create with the suppressLineNumbers property", () => {
const properties = new ParagraphProperties({
suppressLineNumbers: true,
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({
"w:pPr": [
{
"w:suppressLineNumbers": {},
},
],
});
});
});
});

View File

@ -146,7 +146,7 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
}
if (options.bidirectional !== undefined) {
this.push(new OnOffElement("w:bidi", options.contextualSpacing));
this.push(new OnOffElement("w:bidi", options.bidirectional));
}
if (options.spacing) {