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

Projects
None yet
2 participants
@westonruter
Copy link
Member

westonruter commented May 4, 2018

It turns out that CSS calc() functions aren't parsed properly by the CSS parser. There is an old issue open to support them: sabberworm/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

@westonruter westonruter added this to the v1.0 milestone May 4, 2018

$open_parens++;
} elseif ( ')' === $css[ $final_offset ] ) {
$open_parens--;
}

This comment has been minimized.

Copy link
@westonruter

westonruter May 4, 2018

Author Member

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.

This comment has been minimized.

Copy link
@kienstra

kienstra May 4, 2018

Collaborator

👍 It looks like the elseif block below now handles that case.

This comment has been minimized.

Copy link
@westonruter

westonruter May 4, 2018

Author Member

@kienstra that's right. Fixed in 64740c0

@kienstra
Copy link
Collaborator

kienstra left a comment

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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@westonruter westonruter deleted the add/css-calc-workaround branch May 4, 2018

@westonruter westonruter referenced this pull request Jul 2, 2018

Closed

Update CSS Parser to eliminate CSS3 calc() workaround #1240

0 of 1 task complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.