Skip to content

Commit

Permalink
Fix inlineStyles working on foreignObject content. Fixes #823
Browse files Browse the repository at this point in the history
  • Loading branch information
GreLI committed Nov 3, 2017
1 parent f03d832 commit ceccf1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/svgo/jsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ JSAPI.prototype.renameElem = function(name) {

};

/**
* Find the closest ancestor of the current element.
* @param elemName
*
* @return {?Object}
*/

This comment has been minimized.

Copy link
@strarsis

strarsis Nov 3, 2017

Contributor

Nice addition, it resembles closely the Element.closest(...) API (https://developer.mozilla.org/docs/Web/API/Element/closest).

JSAPI.prototype.closestElem = function(elemName) {
var elem = this;

while ((elem = elem.parentNode) && !elem.isElem(elemName));

return elem;
};

/**
* Changes content by removing elements and/or adding new elements.
*
Expand Down
5 changes: 3 additions & 2 deletions plugins/inlineStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ exports.fn = function(document, opts) {
selectors = [];

for (var styleEl of styleEls) {
if (styleEl.isEmpty()) {
// skip empty <style/>s
if (styleEl.isEmpty() || styleEl.closestElem('foreignObject')) {
// skip empty <style/>s or <foreignObject> content.
continue;
}

var cssStr = cssTools.getCssStr(styleEl);

// collect <style/>s and their css ast
Expand Down
5 changes: 4 additions & 1 deletion test/plugins/inlineStyles.17.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ceccf1f

Please sign in to comment.