Limit the list of supported highlight colors (#2522)
* Limit the list of supported highlight colors * Fix tests: use fixed highlight color values --------- Co-authored-by: ilyasogonov <sogonov.ilya@customscard.ru>
This commit is contained in:
@ -36,6 +36,33 @@ export const TextEffect = {
|
||||
NONE: "none",
|
||||
} as const;
|
||||
|
||||
/*
|
||||
* http://officeopenxml.com/WPtextShading.php
|
||||
*
|
||||
* Limit the list of supported highlight colors
|
||||
*
|
||||
* */
|
||||
|
||||
export const HighlightColor = {
|
||||
BLACK: "black",
|
||||
BLUE: "blue",
|
||||
CYAN: "cyan",
|
||||
DARK_BLUE: "darkBlue",
|
||||
DARK_CYAN: "darkCyan",
|
||||
DARK_GRAY: "darkGray",
|
||||
DARK_GREEN: "darkGreen",
|
||||
DARK_MAGENTA: "darkMagenta",
|
||||
DARK_RED: "darkRed",
|
||||
DARK_YELLOW: "darkYellow",
|
||||
GREEN: "green",
|
||||
LIGHT_GRAY: "lightGray",
|
||||
MAGENTA: "magenta",
|
||||
NONE: "none",
|
||||
RED: "red",
|
||||
WHITE: "white",
|
||||
YELLOW: "yellow",
|
||||
} as const;
|
||||
|
||||
/* eslint-enable */
|
||||
|
||||
export interface IRunStylePropertiesOptions {
|
||||
@ -65,7 +92,7 @@ export interface IRunStylePropertiesOptions {
|
||||
readonly subScript?: boolean;
|
||||
readonly superScript?: boolean;
|
||||
readonly font?: string | IFontOptions | IFontAttributesProperties;
|
||||
readonly highlight?: string;
|
||||
readonly highlight?: (typeof HighlightColor)[keyof typeof HighlightColor];
|
||||
readonly highlightComplexScript?: boolean | string;
|
||||
readonly characterSpacing?: number;
|
||||
readonly shading?: IShadingAttributesProperties;
|
||||
|
@ -7,7 +7,7 @@ import { ShadingType } from "@file/shading";
|
||||
import { EmphasisMarkType } from "./emphasis-mark";
|
||||
import { PageNumber, Run } from "./run";
|
||||
import { UnderlineType } from "./underline";
|
||||
import { TextEffect } from "./properties";
|
||||
import { HighlightColor, TextEffect } from "./properties";
|
||||
describe("Run", () => {
|
||||
describe("#noProof()", () => {
|
||||
it("turns off spelling and grammar checkers for a run", () => {
|
||||
@ -215,18 +215,18 @@ describe("Run", () => {
|
||||
describe("#highlight()", () => {
|
||||
it("it should add highlight to the properties", () => {
|
||||
const run = new Run({
|
||||
highlight: "005599",
|
||||
highlight: HighlightColor.YELLOW,
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:highlight": { _attr: { "w:val": "005599" } } },
|
||||
{ "w:highlight": { _attr: { "w:val": "yellow" } } },
|
||||
{
|
||||
"w:highlightCs": {
|
||||
_attr: {
|
||||
"w:val": "005599",
|
||||
"w:val": "yellow",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user