Merge branch 'master' into build
This commit is contained in:
17
demo/demo20.js
Normal file
17
demo/demo20.js
Normal file
@ -0,0 +1,17 @@
|
||||
const docx = require("../build");
|
||||
|
||||
var doc = new docx.Document();
|
||||
|
||||
const table = doc.createTable(4, 4);
|
||||
table
|
||||
.getCell(2, 2)
|
||||
.addContent(new docx.Paragraph("Hello"))
|
||||
.cellProperties.borders.addTopBorder(docx.BorderStyle.DASH_DOT_STROKED, 3, "red")
|
||||
.addBottomBorder(docx.BorderStyle.DOUBLE, 3, "blue")
|
||||
.addStartBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "green")
|
||||
.addEndBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
||||
|
||||
var exporter = new docx.LocalPacker(doc);
|
||||
exporter.pack("My Document");
|
||||
|
||||
console.log("Document created successfully at project root!");
|
@ -34,7 +34,7 @@ describe("Numbering", () => {
|
||||
]);
|
||||
// Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test:
|
||||
// {"w:lvlText": [{"_attr": {"w:val": "•"}}]},
|
||||
// {"w:rPr": [{"w:rFonts": [{"_attr": {"w:ascii": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}]}]},
|
||||
// {"w:rPr": [{"w:rFonts": [{"_attr": {"w:ascii": "Symbol", "w:cs": "Symbol", "w:eastAsia": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}]}]},
|
||||
// {"w:pPr": [{"_attr": {}},
|
||||
// {"w:ind": [{"_attr": {"w:left": 720, "w:hanging": 360}}]}]},
|
||||
});
|
||||
@ -297,7 +297,9 @@ describe("AbstractNumbering", () => {
|
||||
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").font("Times");
|
||||
const tree = new Formatter().format(level);
|
||||
expect(tree["w:lvl"]).to.include({
|
||||
"w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }],
|
||||
"w:rPr": [
|
||||
{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -123,3 +123,14 @@ export class Size extends XmlComponent {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class RTL extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:rtl");
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -8,14 +8,16 @@ describe("RunFonts", () => {
|
||||
it("uses the font name for both ascii and hAnsi", () => {
|
||||
const tree = new Formatter().format(new RunFonts("Times"));
|
||||
expect(tree).to.deep.equal({
|
||||
"w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }],
|
||||
"w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }],
|
||||
});
|
||||
});
|
||||
|
||||
it("uses hint if given", () => {
|
||||
const tree = new Formatter().format(new RunFonts("Times", "default"));
|
||||
expect(tree).to.deep.equal({
|
||||
"w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default" } }],
|
||||
"w:rFonts": [
|
||||
{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" } },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -2,6 +2,8 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface IRunFontAttributesProperties {
|
||||
ascii: string;
|
||||
cs: string;
|
||||
eastAsia: string;
|
||||
hAnsi: string;
|
||||
hint?: string;
|
||||
}
|
||||
@ -9,6 +11,8 @@ interface IRunFontAttributesProperties {
|
||||
class RunFontAttributes extends XmlAttributeComponent<IRunFontAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
ascii: "w:ascii",
|
||||
cs: "w:cs",
|
||||
eastAsia: "w:eastAsia",
|
||||
hAnsi: "w:hAnsi",
|
||||
hint: "w:hint",
|
||||
};
|
||||
@ -20,6 +24,8 @@ export class RunFonts extends XmlComponent {
|
||||
this.root.push(
|
||||
new RunFontAttributes({
|
||||
ascii: ascii,
|
||||
cs: ascii,
|
||||
eastAsia: ascii,
|
||||
hAnsi: ascii,
|
||||
hint: hint,
|
||||
}),
|
||||
|
@ -108,7 +108,13 @@ describe("Run", () => {
|
||||
run.font("Times");
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }] }],
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -133,6 +139,16 @@ describe("Run", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#rtl", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
run.rtl();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:rtl": [{ _attr: { "w:val": true } }]}]}],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#style", () => {
|
||||
it("should set the style to the given styleId", () => {
|
||||
run.style("myRunStyle");
|
||||
|
@ -1,7 +1,7 @@
|
||||
// http://officeopenxml.com/WPtext.php
|
||||
import { Break } from "./break";
|
||||
import { Caps, SmallCaps } from "./caps";
|
||||
import { Bold, Color, DoubleStrike, Italics, Size, Strike } from "./formatting";
|
||||
import { Bold, Color, DoubleStrike, Italics, Size, RTL, Strike } from "./formatting";
|
||||
import { Begin, End, Page, Separate } from "./page-number";
|
||||
import { RunProperties } from "./properties";
|
||||
import { RunFonts } from "./run-fonts";
|
||||
@ -46,6 +46,11 @@ export class Run extends XmlComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public rtl(): Run {
|
||||
this.properties.push(new RTL());
|
||||
return this;
|
||||
}
|
||||
|
||||
public break(): Run {
|
||||
this.root.splice(1, 0, new Break());
|
||||
return this;
|
||||
|
@ -459,7 +459,11 @@ describe("ParagraphStyle", () => {
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
|
||||
{ "w:pPr": [] },
|
||||
{ "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }] },
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user