-
Notifications
You must be signed in to change notification settings - Fork 186
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
Replaced the regex-based transformation of CSS to XPath #52
Replaced the regex-based transformation of CSS to XPath #52
Conversation
The library now uses the Symfony CssSelector component, which supports more cases than the custom logic used previously. Closes tijsverkoyen#34
👍 Much simpler |
This searches all style tags for Media Queries, and replaces the content with just those. Fixes tijsverkoyen#45 Also set the default to strip mediaqueries from inline tags, because that doesn't work as expected. (at least, not after tijsverkoyen#52) Not sure if this is the most performant/optimal way, so open for ideas ;)
This does seem to have some side-effects when using mediaqueries, probably because it handles them more strict? |
@barryvdh what is the issue you face with media queries ? |
This example html: http://zurb.com/ink/downloads/templates/sidebar-hero.html This php:
Results in 2 different outputs: http://i.imgur.com/f6Y7d1C.png Adding |
anyway, excluding media queries is the sensible default when inlining, as media queries cannot get inlined. but the difference is strange indeed. This make me think that some of the rules may have been transformed to the wrong XPath previously, and so not matching. |
A think to note is that does hurt performance a bit. In the referenced template, converting 10 templates go from 550ms to 1100 ms, so it's about twice as slow in some cases. Not sure if there is anything we can do to speed it up? |
The Zend class mentioned in the original issue, seems to bit a bit faster (when just copying the tokenize/csstoxpath function): https://github.com/zendframework/zf2/blob/master/library/Zend/Dom/Document/Query.php, around 700 ms with the same template. Not sure if that's less good or misses some cases. |
well, the Zend class is also based on regex transformations, which will handle less cases (and produce broken XPath queries for cases they don't support, leading to error messages which are impossible to understand) |
Okay cool, as long as it's better I'm fine with losing some performance :) |
note that we may improve performance in future versions of Symfony (btw, if you can run your CssSelector benchmark with xhprof to identify the bottleneck, it might even happen faster). @tijsverkoyen what do you think about this PR ? |
Hi @stof, first of all: big thanks. I will review the code soon. |
Merged, thx @stof! |
The library now uses the Symfony CssSelector component, which supports more cases than the custom logic used previously.
Closes #34
I updated the doc to mention composer as the recommended installation way, as this takes care of including the CssSelector component automatically.
Btw, don't forget to update the composer.json again when bumping the version after this change :)