mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-11 22:18:41 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user