Skip to content

Commit

Permalink
Process “foreignObject”: cleanup editors content and remove itself if…
Browse files Browse the repository at this point in the history
… is empty.

Remove doctype with entities.
Fixes svg#533
  • Loading branch information
GreLI committed Apr 24, 2016
1 parent b35d828 commit 65efced
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/svgo/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function perItem(data, plugins, reverse) {
items.content = items.content.filter(function(item) {

// reverse pass
if (reverse && item.content && item.elem != 'foreignObject') {
if (reverse && item.content) {
monkeys(item);
}

Expand All @@ -62,7 +62,7 @@ function perItem(data, plugins, reverse) {
}

// direct pass
if (!reverse && item.content && item.elem != 'foreignObject') {
if (!reverse && item.content) {
monkeys(item);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/_collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports.elemsGroups = {
structural: ['defs', 'g', 'svg', 'symbol', 'use'],
paintServer: ['solidColor', 'linearGradient', 'radialGradient', 'meshGradient', 'pattern', 'hatch'],
nonRendering: ['linearGradient', 'radialGradient', 'pattern', 'clipPath', 'mask', 'marker', 'symbol', 'filter', 'solidColor'],
container: ['a', 'defs', 'g', 'marker', 'mask', 'missing-glyph', 'pattern', 'svg', 'switch', 'symbol'],
container: ['a', 'defs', 'g', 'marker', 'mask', 'missing-glyph', 'pattern', 'svg', 'switch', 'symbol', 'foreignObject'],
textContent: ['altGlyph', 'altGlyphDef', 'altGlyphItem', 'glyph', 'glyphRef', 'textPath', 'text', 'tref', 'tspan'],
textContentChild: ['altGlyph', 'textPath', 'tref', 'tspan'],
lightSource: ['feDiffuseLighting', 'feSpecularLighting', 'feDistantLight', 'fePointLight', 'feSpotLight'],
Expand Down
6 changes: 1 addition & 5 deletions plugins/removeDoctype.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ exports.description = 'removes doctype declaration';
*/
exports.fn = function(item) {

// remove doctype only if custom XML entities declaration block does not presents
// http://en.wikipedia.org/wiki/Document_Type_Definition#Entity_declarations
if (item.doctype && item.doctype.substr(-1) !== ']') {
return false;
}
return false;

};
13 changes: 7 additions & 6 deletions plugins/removeUnknownsAndDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ for (var elem in elems) {
if (groupDefaults) {
elem.defaults = elem.defaults || {};

for(var attrName in groupDefaults) {
for (var attrName in groupDefaults) {
elem.defaults[attrName] = groupDefaults[attrName];
}
}
Expand Down Expand Up @@ -74,18 +74,18 @@ exports.fn = function(item, params) {
if (
params.unknownContent &&
!item.isEmpty() &&
elems[elem] && //make sure we know of this element before checking its children
elem !== 'foreignObject'//Don't check foreignObject
elems[elem] && // make sure we know of this element before checking its children
elem !== 'foreignObject' // Don't check foreignObject
) {
item.content.forEach(function(content, i) {
if (
content.isElem() &&
!content.prefix &&
!content.prefix &&
(
(
elems[elem].content && // Do we have a record of its permitted content?
elems[elem].content.indexOf(content.elem) === -1
) ||
) ||
(
!elems[elem].content && // we dont know about its permitted content
!elems[content.elem] // check that we know about the element at all
Expand Down Expand Up @@ -120,7 +120,8 @@ exports.fn = function(item, params) {
elems[elem].defaults[attr.name] === attr.value && (
attrsInheritable.indexOf(attr.name) < 0 ||
!item.parentNode.computedAttr(attr.name)
)) ||
)
) ||
// useless overrides
(
params.uselessOverrides &&
Expand Down

0 comments on commit 65efced

Please sign in to comment.