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

Add workaround to preserve CSS calc() functions #1116

Merged
merged 2 commits into from
May 4, 2018

Conversation

westonruter
Copy link
Member

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.

@westonruter westonruter requested a review from kienstra May 4, 2018 06:02
@westonruter westonruter added this to the v1.0 milestone May 4, 2018
$open_parens++;
} elseif ( ')' === $css[ $final_offset ] ) {
$open_parens--;
}
Copy link
Member Author

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.

Copy link
Contributor

@kienstra kienstra May 4, 2018

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kienstra that's right. Fixed in 64740c0

Copy link
Contributor

@kienstra kienstra left a 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.

@westonruter westonruter merged commit 2328f71 into develop May 4, 2018
@westonruter westonruter deleted the add/css-calc-workaround branch May 4, 2018 19:54
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

Successfully merging this pull request may close these issues.

2 participants