diff --git a/plugins/removeUnknownsAndDefaults.js b/plugins/removeUnknownsAndDefaults.js index bf33951..0877576 100644 --- a/plugins/removeUnknownsAndDefaults.js +++ b/plugins/removeUnknownsAndDefaults.js @@ -27,6 +27,15 @@ const allowedAttributesPerElement = new Map(); * @type {Map>} */ const attributesDefaultsPerElement = new Map(); +const preserveOverflowElements = new Set([ + 'foreignObject', + 'image', + 'marker', + 'pattern', + 'svg', + 'symbol', + 'text', +]); for (const [name, config] of Object.entries(elems)) { /** @@ -86,17 +95,28 @@ for (const [name, config] of Object.entries(elems)) { } /** - * @param {string} name + * @param {import('../lib/types.js').XastElement} element + * @param {string} propName * @param {string|undefined} value * @param {Map|undefined} defaults * @returns {boolean} */ -function isDefaultPropertyValue(name, value, defaults) { +function isDefaultPropertyValue(element, propName, value, defaults) { if (defaults === undefined) { return false; } - const defaultVals = defaults.get(name); - return value === defaultVals; + const defaultVals = defaults.get(propName); + if (value === defaultVals) { + return true; + } + if ( + propName === 'overflow' && + value === 'visible' && + !preserveOverflowElements.has(element.name) + ) { + return true; + } + return false; } /** @@ -247,7 +267,12 @@ export const fn = (root, params, info) => { origVal !== null && (origVal === newVal || (newVal === undefined && - isDefaultPropertyValue(p, origVal, attributesDefaults))) + isDefaultPropertyValue( + element, + p, + origVal, + attributesDefaults, + ))) ) { propsToDelete.push(p); } @@ -315,6 +340,7 @@ export const fn = (root, params, info) => { // -- has the same value as the parent. // (b) not inheritable, and a default value. const isDefault = isDefaultPropertyValue( + element, name, value.toString(), attributesDefaults, diff --git a/test/plugins/removeUnknownsAndDefaults.34.svg.txt b/test/plugins/removeUnknownsAndDefaults.34.svg.txt new file mode 100644 index 0000000..a1125ac --- /dev/null +++ b/test/plugins/removeUnknownsAndDefaults.34.svg.txt @@ -0,0 +1,13 @@ +Remove overflow:visible where possible. + +=== + + + + + +@@@ + + + +