-
Notifications
You must be signed in to change notification settings - Fork 381
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
Add workaround to preserve CSS calc() functions #1116
Conversation
$open_parens++; | ||
} elseif ( ')' === $css[ $final_offset ] ) { | ||
$open_parens--; | ||
} |
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.
Probably should add a case here to catch ;
or }
and break
because clearly that indicates unbalanced parentheses and we should skip to looking for the next match from that point forward.
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.
👍 It looks like the elseif
block below now handles that case.
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 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.
Approved
Hi @westonruter,
Thanks, this pull request looks good, and it allowed outputting calc
values to <style amp-custom>
, like:
calc(100% + 2rem)
calc(70vmax - 300px)
calc(0px - 3.5rem)
Good idea to store them in placeholders, and replace them later.
It turns out that CSS
calc()
functions aren't parsed properly by the CSS parser. There is an old issue open to support them: MyIntervals/PHP-CSS-Parser#79. In the mean time, this makes sure that these functions are preserved by replacing them with placeholders prior to parsing, and then returning the original functions after parsing.