-
Notifications
You must be signed in to change notification settings - Fork 154
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
remove the class="xxx" from html after converting to inline-css #380
Comments
Removing the CSS classes from HTML will break any media queries that rely on these classes. So I propose we always keep the classes. @jjriv, @zoliszabo, @xenDE Thoughts? |
IMHO, if to be implemented, only as an option/switch (which would default to |
@zoliszabo I was more thinking along the lines of "not adding the automatic removal option", i.e., to always keep existing class attributes, i.e., to not implement the feature proposed in this ticket. |
@oliverklee, of course. I just cannot make up my mind whether implementing this feature or not would better suit Emogrifier. Implementing the feature with a |
I'd like Emogrifier to be (or become) a tool that does one thing, and does it well, with good, opiniated default behavior. I'd like to have only those options where there are really big benefits for having different behaviors. Having as few options as possible will make usage simpler, and it will keep the code simple and the different test cases few. |
Minimizing the HTML should go into a separate tool (or at least a separate class). |
I agree that Emogrifier should be a tool that does one thing. It's definitely better to have fewer options for usability, but that means saying no to some features that may seem desirable by a vocal minority. That said, I agree, let's keep the minimizing of the HTML out of this. One argument in favor of this is that other libraries may handle minimization better,. And when those libraries are updated do we also update Emogrifier to have the latest and greatest? Another question to ask is this. How much complexity does this feature add? And how much effort does it take to support this feature and keep it working correctly? If this feature is easily broken and a pain to maintain, I say get rid of it. I don't feel strongly about keeping it or getting rid of it, but I'm hoping my insight might help you guys decide. Thanks! |
So we'll handling this with a new class. Keeping this ticket open for this. |
When #280 is implemented, this becomes much simpler, as it would then be known which rules have been applied inline, and only the classes used in selectors in the added style element need to be retained - these can be determined by a simple regex. |
Now that we have For the DOM manipulation, I propose the following method in that class: public function removeRedundantClassAttributes(array $classesToKeep) : HtmlPruner; This would iterate elements with a class attribute; compute the intersection of the whitespace-separated class names in that attribute value and those in the passed-in parameter; and update (or remove) the class attribute with the resultant list of classes. According to https://stackoverflow.com/questions/6329211/php-array-intersect-efficiency it should be more efficient to do an This would be a lower-level method, and there’s an argument for it to be private – most users would want a method that can (somehow) determine the list of classes to keep and then call on to this. Determining the List of Classes to Keep There are two possible approaches here:
Expanding on the second approach, we see that The aforementioned property ( public function getMatchingUninlineableSelectors() : string[]; We can put this all together with the following public function removeRedundantClassAttributesAfterCssInlined(CssInliner $cssInliner) : HtmlPruner; Obviously the Implementation can be broken down into 3-4 separate PRs. @oliverklee, @zoliszabo, What do you think? Also, could the proposed method names be improved, e.g.
(*Note that a more accurate regular expression for class names in a selector would be |
@JakeQZ I like this plan a lot! I'd prefer approach 2 (adding a method to
For the return type, we can replace |
Though until PHP 7 is a minimum requirement we can't type hint the return value, only specify it in the PHPDoc. (I didn't know that Let me know if you have any thoughts on the method names, which will become part of the public interface. I'm not 100% sure at present myself... |
I think the more correct spelling of the word meaning "can be inlined" is "inlinable" (without an "e" before "-able"). Searching the web for both spellings together turns up many more highly-ranked results without the "e"; dictionaries which give the main entry without the "e" (for example) while listing the spelling with an "e" as an alternative form (for example); and a changeset where someone has 'corrected' the spelling to remove the "e". (Similarly-constructed words like "writable", "parsable", "combinable", "definable", "declinable", "refinable", "finable", "minable", and, most pertinently, "linable", are usually spelt without an "e" preceding "-able".) I am strongly persuaded to change the spelling of this throughout to remove the "e" before we introduce a public method based on it… |
Let's go for it! |
… in method, property and variable names. Research indicates that whilst “inlineable” may be a permitted alternative variant, “inlinable” is more correct and mainstream. Part of #380.
… in method, property and variable names. Research indicates that whilst “inlineable” may be a permitted alternative variant, “inlinable” is more correct and mainstream. Part of #380.
Added new method `determineMatchingUninlinableCssRules` to do the first part of the job (filtering CSS rules for those relevant to the document) and store the result as a class property. Part of #380.
Added new method `determineMatchingUninlinableCssRules` to do the first part of the job (filtering CSS rules for those relevant to the document) and store the result as a class property. Part of #380.
Part of #380. The basic functionality of the method is unit-tested. More extensive unit tests involving all kinds CSS rules and HTML already exist for testing the full content of the `<style>` element containing the uninlinable rules.
Part of #380. The basic functionality of the method is unit-tested. More extensive unit tests involving all kinds of CSS rules and HTML already exist for testing the full content of the `<style>` element containing the uninlinable rules.
I’m thinking now that And I don’t think the suggested possible suffix So we'd have these methods in public function removeRedundantClasses(array $classesToKeep) : self;
public function removeRedundantClassesAfterCssInlined(CssInliner $cssInliner) : self; |
Sounds good. |
Also added section for `HtmlPruner` to the README. Closes #380.
Also added section for `HtmlPruner` to the README. Closes #380.
Also added section for `HtmlPruner` to the README. Closes #380.
the classes are perfect converted, but the class is still present in the html tag:
<span class="f3" style="color: #AA5500;">
this blows up the output size.
A switch like
private $shouldClassesBeRemoved = true;
would be fine.
The text was updated successfully, but these errors were encountered: