MCPcopy Create free account
hub / github.com/KaTeX/KaTeX / parseColorGroup

Method parseColorGroup

src/Parser.ts:678–702  ·  view source on GitHub ↗

* Parses a color description.

(optional: boolean)

Source from the content-addressed store, hash-verified

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

Callers 1

parseGroupOfTypeMethod · 0.95

Calls 1

parseStringGroupMethod · 0.95

Tested by

no test coverage detected