-
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
Refactor removing style tags #72
Conversation
*/ | ||
private function stripOriginalStyleTags($html) | ||
private function stripOriginalStyleTags($xPath) |
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.
Shouldn't we typehint it in the definition too?
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.
Sure
This uses xPath to find the style tags and either remove the style tag completely, or replace them with just the media queries, based on the excludeMediaQueries flag. This follows the logic that if the mediaqueries are excluded from inlining, they should not be stripped from the document, because they aren't processed. If for some reason they are processed (don't know the use case) they can just be removed.
*/ | ||
private function stripOriginalStyleTags($html) | ||
private function stripOriginalStyleTags(\DOMXPath $xPath) |
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.
Shouldn't we add use DOMXPath;
at the start of the file, and then ref this without the slash - just a minor cs point. :)
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.
Could be, but that is also not done for the other classes, so this is more in line with the rest. But Tijs is free to change this of course.
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.
Sure thing. After all the open pulls are closed/merged, I might make a pull to standardise this.
Refactor removing style tags
Thanks! |
This uses xPath to find the style tags and either remove the style tag completely, or replace them with just the media queries, based on the excludeMediaQueries flag.
This follows the logic that if the mediaqueries are excluded from inlining, they should not be stripped from the document, because they aren't processed.
If for some reason they are processed (don't know the use case) they can just be removed.
This uses xPath instead of the earlier regex, because this seems easier/more reliable. I did think about changing the finding of styles to also use xPath, but according to the docs/comments the order in which the results are returned isn't 100% reliable.
Replaces #54