* Parses a color description.
(optional: boolean)
| 682 | * Parses a color description. |
| 683 | */ |
| 684 | parseColorGroup(optional: boolean): ParseNode<"color-token"> | null { |
| 685 | const res = this.parseStringGroup(optional); |
| 686 | if (res == null) { |
| 687 | return null; |
| 688 | } |
| 689 | const match = ( |
| 690 | /^(#[a-f0-9]{3,4}|#[a-f0-9]{6}|#[a-f0-9]{8}|[a-f0-9]{6}|[a-z]+)$/i |
| 691 | ).exec(res.text); |
| 692 | if (!match) { |
| 693 | throw new ParseError("Invalid color: '" + res.text + "'", res); |
| 694 | } |
| 695 | let color = match[0]; |
| 696 | if (/^[0-9a-f]{6}$/i.test(color)) { |
| 697 | // We allow a 6-digit HTML color spec without a leading "#". |
| 698 | // This follows the xcolor package's HTML color model. |
| 699 | // Predefined color names are all missed by this RegEx pattern. |
| 700 | color = "#" + color; |
| 701 | } |
| 702 | |
| 703 | return { |
| 704 | type: "color-token", |
| 705 | mode: this.mode, |
| 706 | color, |
| 707 | }; |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * Parses a size specification, consisting of magnitude and unit. |
no test coverage detected