@ -1,7 +1,7 @@
|
|||||||
// Creates two paragraphs, one with a border and one without
|
// Creates two paragraphs, one with a border and one without
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { BorderStyle, Document, Packer, Paragraph } from "../build";
|
import { BorderStyle, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -25,6 +25,25 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "This will ",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "have a border.",
|
||||||
|
border: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " This will not.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { ChangeAttributes, IChangedAttributesProperties } from "../../track-revision/track-revision";
|
import { ChangeAttributes, IChangedAttributesProperties } from "../../track-revision/track-revision";
|
||||||
|
|
||||||
|
import { BorderElement, IBorderOptions } from "file/border";
|
||||||
import { IShadingAttributesProperties, Shading } from "file/shading";
|
import { IShadingAttributesProperties, Shading } from "file/shading";
|
||||||
import { HpsMeasureElement, IgnoreIfEmptyXmlComponent, OnOffElement, StringValueElement, XmlComponent } from "file/xml-components";
|
import { HpsMeasureElement, IgnoreIfEmptyXmlComponent, OnOffElement, StringValueElement, XmlComponent } from "file/xml-components";
|
||||||
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
|
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
|
||||||
@ -43,6 +44,7 @@ export interface IRunStylePropertiesOptions {
|
|||||||
readonly emboss?: boolean;
|
readonly emboss?: boolean;
|
||||||
readonly imprint?: boolean;
|
readonly imprint?: boolean;
|
||||||
readonly revision?: IRunPropertiesChangeOptions;
|
readonly revision?: IRunPropertiesChangeOptions;
|
||||||
|
readonly border?: IBorderOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
|
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
|
||||||
@ -209,6 +211,10 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
if (options.revision) {
|
if (options.revision) {
|
||||||
this.push(new RunPropertiesChange(options.revision));
|
this.push(new RunPropertiesChange(options.revision));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.border) {
|
||||||
|
this.push(new BorderElement("w:bdr", options.border));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public push(item: XmlComponent): void {
|
public push(item: XmlComponent): void {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
import { BorderStyle } from "file/border";
|
||||||
// import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run";
|
// import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run";
|
||||||
import { ShadingType } from "file/shading";
|
import { ShadingType } from "file/shading";
|
||||||
|
|
||||||
@ -488,4 +489,36 @@ describe("Run", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#border", () => {
|
||||||
|
it("should correctly set the border", () => {
|
||||||
|
const run = new Run({
|
||||||
|
border: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:bdr": {
|
||||||
|
_attr: {
|
||||||
|
"w:color": "auto",
|
||||||
|
"w:space": 1,
|
||||||
|
"w:sz": 6,
|
||||||
|
"w:val": "single",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user