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

Values that include color-names are rewritten to have hex-codes in them #450

Closed
fangel opened this issue Jan 30, 2015 · 4 comments
Closed
Milestone

Comments

@fangel
Copy link

fangel commented Jan 30, 2015

Hi,

I have a font with a -black variation that I load through a @font-face. E.g.

@font-face {
  font-family: 'alrightsanslp-black';
  src: url('../fonts/alrightsanslp-black.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

.font-black {
  font-family: alrightsanslp-black, 'helvetica neue', helvetica, arial, sans-serif;
}

However, because alightsanslp-black matches the regexp in /lib/colors/hex-name-shortener.js, this will get optimised into (white-space added back in, to look like the input-file)

@font-face{
  font-family:alrightsanslp-black;
  src:url(../fonts/alrightsanslp-black.woff) format('woff');
  font-weight:400;
  font-style:normal
}

.font-black{
  font-family:alrightsanslp-#000,'helvetica neue',helvetica,arial,sans-serif
}

That is, the font-family in .font-black is now alrightsanslp-#000 instead of alrightsanslp-black, because the hex-name-shortener replace black with #000.

The pattern is:

var toHexPattern = new RegExp('(' + Object.keys(toHex).join('|') + ')( |,|\\)|$)', 'ig');

In my opinion the pattern should have some sort of guard in front of it, so that -black or similar isn't converted.

Kind regards
Morten

@jakubpawlowicz
Copy link
Collaborator

Good catch @fangel! It sneaked into 3.x as it was fine in <= 2.2. Please quote the value for the time being, i.e.: font-family:'alrightsanslp-black';, until it's fixed!

@jakubpawlowicz jakubpawlowicz added this to the 3.0.8 milestone Jan 30, 2015
@fangel
Copy link
Author

fangel commented Jan 30, 2015

Using quotes is a much better fix than the kludge I snuck into my Grunt build-process - namely doing string-replace post-processing, hahaha.

But thanks for looking at this issue, and thanks for a great library!

@jakubpawlowicz
Copy link
Collaborator

I'll fix it soon. Cheers!

jakubpawlowicz added a commit that referenced this issue Jan 31, 2015
Regexp matching color names was too greedy and was matching some
other values as well.

On the downside we need to run the replacement twice.

On the upside it extracts replacement functions so we get a slight
speed boost.
jakubpawlowicz added a commit that referenced this issue Jan 31, 2015
Regexp matching color names was too greedy and was matching some
other values as well.

On the downside we need to run the replacement twice.

On the upside it extracts replacement functions so we get a slight
speed boost.
@jakubpawlowicz
Copy link
Collaborator

@fangel Fixed in 3.0.8!

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

2 participants