Add shading to paragraph
This commit is contained in:
@ -9,6 +9,7 @@ import { File } from "../file";
|
||||
import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting";
|
||||
import { Bookmark, HyperlinkRef } from "./links";
|
||||
import { Paragraph } from "./paragraph";
|
||||
import { ShadingType } from "../table/shading";
|
||||
|
||||
describe("Paragraph", () => {
|
||||
describe("#constructor()", () => {
|
||||
@ -761,6 +762,36 @@ describe("Paragraph", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#shading", () => {
|
||||
it("should set paragraph outline level to the given value", () => {
|
||||
const paragraph = new Paragraph({
|
||||
shading: {
|
||||
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
|
||||
color: "00FFFF",
|
||||
fill: "FF0000",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:shd": {
|
||||
_attr: {
|
||||
"w:color": "00FFFF",
|
||||
"w:fill": "FF0000",
|
||||
"w:val": "reverseDiagStripe",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#prepForXml", () => {
|
||||
it("should set paragraph outline level to the given value", () => {
|
||||
const paragraph = new Paragraph({
|
||||
|
@ -1,5 +1,6 @@
|
||||
// http://officeopenxml.com/WPparagraphProperties.php
|
||||
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
|
||||
import { ShadingType } from "../table/shading";
|
||||
import { Alignment, AlignmentType } from "./formatting/alignment";
|
||||
import { Bidirectional } from "./formatting/bidirectional";
|
||||
import { Border, IBorderOptions, ThematicBreak } from "./formatting/border";
|
||||
@ -11,6 +12,7 @@ import { HeadingLevel, Style } from "./formatting/style";
|
||||
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
|
||||
import { NumberProperties } from "./formatting/unordered-list";
|
||||
import { OutlineLevel } from "./links";
|
||||
import { Shading } from "./run/formatting";
|
||||
|
||||
export interface IParagraphStylePropertiesOptions {
|
||||
readonly alignment?: AlignmentType;
|
||||
@ -44,6 +46,11 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
||||
readonly level: number;
|
||||
readonly custom?: boolean;
|
||||
};
|
||||
readonly shading?: {
|
||||
readonly type: ShadingType;
|
||||
readonly fill: string;
|
||||
readonly color: string;
|
||||
};
|
||||
}
|
||||
|
||||
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
@ -131,6 +138,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
if (options.leftTabStop) {
|
||||
this.push(new TabStop(TabStopType.LEFT, options.leftTabStop));
|
||||
}
|
||||
|
||||
if (options.shading) {
|
||||
this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
|
||||
}
|
||||
}
|
||||
|
||||
public push(item: XmlComponent): void {
|
||||
|
Reference in New Issue
Block a user