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

Transform within default variables #79

Open
bart-jaskulski opened this issue Nov 9, 2021 · 4 comments
Open

Transform within default variables #79

bart-jaskulski opened this issue Nov 9, 2021 · 4 comments

Comments

@bart-jaskulski
Copy link

Transforming px values to rem is not working inside default values in custom properties.

CSS below would be sufficient to reproduce the issue.

body {
  padding: var(--site-padding, 16px) 
}

Desired outcome should be:

body {
  padding: var(--site-padding, 1rem)
}

Nonetheless, such piece of code is not transformed. Is this a flaw possible to fix or design choice?

@NikolayMakhonin
Copy link

Yes, it is a design choise, see this regexp

/"[^"]+"|'[^']+'|url\([^)]+\)|var\([^)]+\)|(\d*\.?\d+)px/g

it ignored all the var statements, I think it's because of the variable names, which can include something like --1px. We just need to improve regexp and there will be no such problem:

/"[^"]+"|'[^']+'|url\([^)]+\)|((?<=^|[^\w-])-?\d*\.?\d+)px\b/g

NikolayMakhonin added a commit to NikolayMakhonin/postcss-pxtorem that referenced this issue Oct 2, 2022
@AAAAAAAAAdai
Copy link

是的,这是一种设计选择,请参看此正则表达式

/"[^"]+"|'[^']+'|url\([^)]+\)|var\([^)]+\)|(\d*\.?\d+)px/g

它忽略了所有的var语言句子,我认为这是因为变量名,它可以包含类似的--1px。我们只需要改变进入正则表达式就不会出现这样的问题:

/"[^"]+"|'[^']+'|url\([^)]+\)|((?<=^|[^\w-])-?\d*\.?\d+)px\b/g

left: -10px; not working

@citrus327
Copy link

any progress?

@dimitry-blinov
Copy link

dimitry-blinov commented Feb 19, 2024

@yangmingshan @cuth Please add the ability to convert px to em inside var in the callback ignoring custom variables. Can u merge and release a new version?

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

5 participants