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

Refactor removing style tags #72

Merged
merged 1 commit into from
Jul 31, 2014
Merged

Conversation

barryvdh
Copy link
Contributor

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

@barryvdh barryvdh mentioned this pull request Jul 26, 2014
*/
private function stripOriginalStyleTags($html)
private function stripOriginalStyleTags($xPath)
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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. :)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

tijsverkoyen added a commit that referenced this pull request Jul 31, 2014
Refactor removing style tags
@tijsverkoyen tijsverkoyen merged commit fd6464c into tijsverkoyen:master Jul 31, 2014
@barryvdh
Copy link
Contributor Author

Thanks!

@barryvdh barryvdh deleted the patch-6 branch September 18, 2014 07:51
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.

3 participants