Allow 6-digit color spec w/o # (#1690)

* Allow 6-digit color spec w/o #

* Improve RegEx pattern

* Pick up comment

* fix lint
This commit is contained in:
Ron Kok
2018-09-01 10:27:17 -07:00
committed by Kevin Barabash
parent d3ec100d02
commit 9b7e10e4f7
4 changed files with 18 additions and 7 deletions

View File

@@ -296,10 +296,10 @@ describe("Lexer:", function() {
});
describe("#_innerLexColor", function() {
it("reject hex notation without #", function() {
expect`\textcolor{1a2b3c}{foo}`.toFailWithParseError(
"Invalid color: '1a2b3c'" +
" at position 12: \\textcolor{1̲a̲2̲b̲3̲c̲}{foo}");
it("reject 3-digit hex notation without #", function() {
expect`\textcolor{1a2}{foo}`.toFailWithParseError(
"Invalid color: '1a2'" +
" at position 12: \\textcolor{1̲a̲2̲}{foo}");
});
});

View File

@@ -780,6 +780,7 @@ describe("A color parser", function() {
const newColorExpression = r`\redA{x}`;
const customColorExpression1 = r`\textcolor{#fA6}{x}`;
const customColorExpression2 = r`\textcolor{#fA6fA6}{x}`;
const customColorExpression3 = r`\textcolor{fA6fA6}{x}`;
const badCustomColorExpression1 = r`\textcolor{bad-color}{x}`;
const badCustomColorExpression2 = r`\textcolor{#fA6f}{x}`;
const badCustomColorExpression3 = r`\textcolor{#gA6}{x}`;
@@ -800,14 +801,17 @@ describe("A color parser", function() {
it("should parse a custom color", function() {
expect(customColorExpression1).toParse();
expect(customColorExpression2).toParse();
expect(customColorExpression3).toParse();
});
it("should correctly extract the custom color", function() {
const parse1 = getParsed(customColorExpression1)[0];
const parse2 = getParsed(customColorExpression2)[0];
const parse3 = getParsed(customColorExpression3)[0];
expect(parse1.color).toEqual("#fA6");
expect(parse2.color).toEqual("#fA6fA6");
expect(parse3.color).toEqual("#fA6fA6");
});
it("should not parse a bad custom color", function() {