-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Local styles plugin #454
Local styles plugin #454
Conversation
Hm, jshint fails with build using nodejs release v0.10.40, but with other plugins than this one. |
* | ||
* @return {Array} output items | ||
*/ | ||
function monkeys(items, callFn, selectFn, recurseFn) { |
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.
It seems that recurseFn
isn't actually used.
Also, I'd like if styles were transfered just if there is only one match, not if two or more (non-adjanced, adjanced can be grouped). It seems it can be done easy enough in the current implementation. |
"Also, I'd like if styles were transfered just if there is only one match, not if two or more (non-adjanced, adjanced can be grouped). It seems it can be done easy enough in the current implementation." So this means that when a CSS rule with multiple selectors Like for example using this rule in input:
The rule is cleaned up completely because .test1 matched?:
|
The jshint fails with other files for this PR, should I base it off a different commit that passes the tests? |
No, I don't think it's required. Do it if you want. It's odd that other builds including master branch passed it. |
OK, so the last thing that needs to be clarified is how matched CSS rules are handled. |
I mean remove a rule only if there only one corresponding class in document. E.g. <svg>
<style>
.thick { stroke-width: 10px }
</style>
<path class="thick" d="..."/>
</svg> but not then there are several classes here and there: <svg>
<style>
.thick { stroke-width: 10px }
</style>
...
<circle class="thick" .../>
...
<path class="thick" d="..."/>
...etc...
</svg> |
var i = 0, | ||
length = items.content.length; | ||
|
||
while(i < length) { |
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.
Why not just simple for
loop?
for (var i = 0; i < items.content.length; i++) {
Modern engines optimize it, so there is no need in caching length = items.content.length
.
Yes, I fixed/changed the loop code now. Preserving selectors/rules when they are used multiple times is a bit tricky, |
Don't forget to check with «CDATA», empty |
Do you guys have any update on this? |
Yes, I rewrote the plugin so that it can use the svgo ast as cheerio ast and juice for cleaning up the styles. Edit: The reason why I use juice now in this svgo plugin is that it already solved the quite complicated handling of style cascadation, selectors, etc and comes with tests included. |
OK, the rewrite has been finished: #592 |
This PR adds the local styles plugin.
It is a complete rewrite of previous PR, to make the code simpler and more efficient.