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

@@ -743,14 +743,21 @@ export default class Parser {
if (!res) {
return null;
}
const match = (/^(#[a-f0-9]{3}|#[a-f0-9]{6}|[a-z]+)$/i).exec(res.text);
const match = (/^(#[a-f0-9]{3}|#?[a-f0-9]{6}|[a-z]+)$/i).exec(res.text);
if (!match) {
throw new ParseError("Invalid color: '" + res.text + "'", res);
}
let color = match[0];
if (/^[0-9a-f]{6}$/i.test(color)) {
// We allow a 6-digit HTML color spec without a leading "#".
// This follows the xcolor package's HTML color model.
// Predefined color names are all missed by this RegEx pattern.
color = "#" + color;
}
return newArgument({
type: "color-token",
mode: this.mode,
color: match[0],
color,
}, res);
}