* Parses a color description.
(optional)
| 15506 | |
| 15507 | |
| 15508 | parseColorGroup(optional) { |
| 15509 | const res = this.parseStringGroup("color", optional); |
| 15510 | |
| 15511 | if (!res) { |
| 15512 | return null; |
| 15513 | } |
| 15514 | |
| 15515 | const match = /^(#[a-f0-9]{3}|#?[a-f0-9]{6}|[a-z]+)$/i.exec(res.text); |
| 15516 | |
| 15517 | if (!match) { |
| 15518 | throw new ParseError("Invalid color: '" + res.text + "'", res); |
| 15519 | } |
| 15520 | |
| 15521 | let color = match[0]; |
| 15522 | |
| 15523 | if (/^[0-9a-f]{6}$/i.test(color)) { |
| 15524 | // We allow a 6-digit HTML color spec without a leading "#". |
| 15525 | // This follows the xcolor package's HTML color model. |
| 15526 | // Predefined color names are all missed by this RegEx pattern. |
| 15527 | color = "#" + color; |
| 15528 | } |
| 15529 | |
| 15530 | return { |
| 15531 | type: "color-token", |
| 15532 | mode: this.mode, |
| 15533 | color |
| 15534 | }; |
| 15535 | } |
| 15536 | /** |
| 15537 | * Parses a size specification, consisting of magnitude and unit. |
| 15538 | */ |
no test coverage detected