1
0
mirror of https://github.com/svg/svgo.git synced 2025-08-06 04:22:39 +03:00

Process “foreignObject”: cleanup editors content and remove itself if is empty.

Remove doctype with entities.
Fixes #533
This commit is contained in:
GreLI
2016-04-24 21:29:01 +03:00
parent b35d828d49
commit 65efced355
4 changed files with 11 additions and 14 deletions

View File

@@ -46,7 +46,7 @@ function perItem(data, plugins, reverse) {
items.content = items.content.filter(function(item) { items.content = items.content.filter(function(item) {
// reverse pass // reverse pass
if (reverse && item.content && item.elem != 'foreignObject') { if (reverse && item.content) {
monkeys(item); monkeys(item);
} }
@@ -62,7 +62,7 @@ function perItem(data, plugins, reverse) {
} }
// direct pass // direct pass
if (!reverse && item.content && item.elem != 'foreignObject') { if (!reverse && item.content) {
monkeys(item); monkeys(item);
} }

View File

@@ -8,7 +8,7 @@ exports.elemsGroups = {
structural: ['defs', 'g', 'svg', 'symbol', 'use'], structural: ['defs', 'g', 'svg', 'symbol', 'use'],
paintServer: ['solidColor', 'linearGradient', 'radialGradient', 'meshGradient', 'pattern', 'hatch'], paintServer: ['solidColor', 'linearGradient', 'radialGradient', 'meshGradient', 'pattern', 'hatch'],
nonRendering: ['linearGradient', 'radialGradient', 'pattern', 'clipPath', 'mask', 'marker', 'symbol', 'filter', 'solidColor'], 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'], textContent: ['altGlyph', 'altGlyphDef', 'altGlyphItem', 'glyph', 'glyphRef', 'textPath', 'text', 'tref', 'tspan'],
textContentChild: ['altGlyph', 'textPath', 'tref', 'tspan'], textContentChild: ['altGlyph', 'textPath', 'tref', 'tspan'],
lightSource: ['feDiffuseLighting', 'feSpecularLighting', 'feDistantLight', 'fePointLight', 'feSpotLight'], lightSource: ['feDiffuseLighting', 'feSpecularLighting', 'feDistantLight', 'fePointLight', 'feSpotLight'],

View File

@@ -33,10 +33,6 @@ exports.description = 'removes doctype declaration';
*/ */
exports.fn = function(item) { exports.fn = function(item) {
// remove doctype only if custom XML entities declaration block does not presents return false;
// http://en.wikipedia.org/wiki/Document_Type_Definition#Entity_declarations
if (item.doctype && item.doctype.substr(-1) !== ']') {
return false;
}
}; };

View File

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