-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: support hex colors with alpha #4090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
edemaine
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! I have a few comments.
src/Parser.js
Outdated
| 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-f0-9]{8}|[a-z]+)$/i).exec(res.text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also 4-digit hex codes. See https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color
Is there some way to avoid the repetition here? I'm not sure.
- Add 4-digit hex color support (#RGBA) - Remove 8-digit color support without # prefix - Optimize regex pattern for better readability - Remove redundant parsing tests - Inline invalid color test cases
|
Hi @edemaine, Thanks for the feedback! Iβve made the requested changes: 1.Added support for 4-digit hex colors. Iβve pushed the updates and opened a new pull request with these fixes. Please take a look when you get a chance. |
Pull Request is not mergeable
|
Tests are failing; could you take a look?
|
- Split regex across lines to meet 84-character limit - Update badCustomColorExpression2 from #fA6f to #fA6f1 (5-digit invalid) - Ensure all tests pass and linting requirements are met
|
fix: resolve linting and test issues
|
|
Hi @edemaine, Thanks for approving the changes! I can see that all the screenshotter tests are passing and the deploy preview looks good. Could you please approve the 2 pending workflows so that the |
## [0.16.24](v0.16.23...v0.16.24) (2025-10-12) ### Features * support hex colors with alpha ([#4090](#4090)) ([8c9b306](8c9b306)), closes [#4067](#4067) [#fA6](https://github.com/KaTeX/KaTeX/issues/fA6) [#fA6f1](https://github.com/KaTeX/KaTeX/issues/fA6f1)
|
π This PR is included in version 0.16.24 π The release is available on: Your semantic-release bot π¦π |
|
Hi @edemaine, Thanks for merging the PR! π |
What is the previous behavior before this PR?
KaTeX only supported 3-digit (#RGB), 6-digit (#RRGGBB), and named colors (red, blue, etc.). 8-digit hex colors with alpha transparency (#RRGGBBAA) were rejected by the parser with "Invalid color" errors.
Example that failed before:
What is the new behavior after this PR?
KaTeX now accepts and processes 8-digit hex colors with alpha transparency in both #RRGGBBAA and RRGGBBAA formats. The alpha channel is preserved and passed through to CSS for browser rendering.
Examples that work after:
\textcolor{#FF000080}{F=ma} % 50% transparent red
\textcolor{#228B2280}{F=ma} % 50% transparent green
\textcolor{00FF0040}{F=ma} % 25% opaque green (no # prefix)
The parser now:
Validates 8-digit hex color format
Automatically adds # prefix when missing for 8-digit colors
Maintains full backward compatibility with existing color formats
Outputs standard CSS #RRGGBBAA format for modern browser alpha support
Fixes #4067