Skip to content
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

Short (3 character) hex color codes are converted to black #29

Open
Daio-io opened this issue Aug 7, 2024 · 0 comments
Open

Short (3 character) hex color codes are converted to black #29

Daio-io opened this issue Aug 7, 2024 · 0 comments

Comments

@Daio-io
Copy link

Daio-io commented Aug 7, 2024

Some SVG optimisers will shorten hex codes for colors like white and black to be a 3 character hex https://svgo.dev/docs/plugins/convertColors/ (It is also possible design teams may export icons with optimised short hex values as well)

The current regex only looks for 6-8 character code hex

private val hexRegex = "^[0-9a-fA-F]{6,8}".toRegex()

Meaning a short character code for white (FFF) will be converted to black

private fun String.toHexColor(): String {
return removePrefix("#")
.let {
if(hexRegex.matches(it)) {
if (it.length > 6) it
else "FF$it"
} else {
"FF000000"
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant