diff --git a/packages/parse5/lib/common/foreign-content.ts b/packages/parse5/lib/common/foreign-content.ts index 9981363e5..2b9ffadff 100644 --- a/packages/parse5/lib/common/foreign-content.ts +++ b/packages/parse5/lib/common/foreign-content.ts @@ -10,66 +10,68 @@ const MIME_TYPES = { //Attributes const DEFINITION_URL_ATTR = 'definitionurl'; const ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL'; -const SVG_ATTRS_ADJUSTMENT_MAP = new Map([ - ['attributename', 'attributeName'], - ['attributetype', 'attributeType'], - ['basefrequency', 'baseFrequency'], - ['baseprofile', 'baseProfile'], - ['calcmode', 'calcMode'], - ['clippathunits', 'clipPathUnits'], - ['diffuseconstant', 'diffuseConstant'], - ['edgemode', 'edgeMode'], - ['filterunits', 'filterUnits'], - ['glyphref', 'glyphRef'], - ['gradienttransform', 'gradientTransform'], - ['gradientunits', 'gradientUnits'], - ['kernelmatrix', 'kernelMatrix'], - ['kernelunitlength', 'kernelUnitLength'], - ['keypoints', 'keyPoints'], - ['keysplines', 'keySplines'], - ['keytimes', 'keyTimes'], - ['lengthadjust', 'lengthAdjust'], - ['limitingconeangle', 'limitingConeAngle'], - ['markerheight', 'markerHeight'], - ['markerunits', 'markerUnits'], - ['markerwidth', 'markerWidth'], - ['maskcontentunits', 'maskContentUnits'], - ['maskunits', 'maskUnits'], - ['numoctaves', 'numOctaves'], - ['pathlength', 'pathLength'], - ['patterncontentunits', 'patternContentUnits'], - ['patterntransform', 'patternTransform'], - ['patternunits', 'patternUnits'], - ['pointsatx', 'pointsAtX'], - ['pointsaty', 'pointsAtY'], - ['pointsatz', 'pointsAtZ'], - ['preservealpha', 'preserveAlpha'], - ['preserveaspectratio', 'preserveAspectRatio'], - ['primitiveunits', 'primitiveUnits'], - ['refx', 'refX'], - ['refy', 'refY'], - ['repeatcount', 'repeatCount'], - ['repeatdur', 'repeatDur'], - ['requiredextensions', 'requiredExtensions'], - ['requiredfeatures', 'requiredFeatures'], - ['specularconstant', 'specularConstant'], - ['specularexponent', 'specularExponent'], - ['spreadmethod', 'spreadMethod'], - ['startoffset', 'startOffset'], - ['stddeviation', 'stdDeviation'], - ['stitchtiles', 'stitchTiles'], - ['surfacescale', 'surfaceScale'], - ['systemlanguage', 'systemLanguage'], - ['tablevalues', 'tableValues'], - ['targetx', 'targetX'], - ['targety', 'targetY'], - ['textlength', 'textLength'], - ['viewbox', 'viewBox'], - ['viewtarget', 'viewTarget'], - ['xchannelselector', 'xChannelSelector'], - ['ychannelselector', 'yChannelSelector'], - ['zoomandpan', 'zoomAndPan'], -]); +const SVG_ATTRS_ADJUSTMENT_MAP = new Map( + [ + 'attributeName', + 'attributeType', + 'baseFrequency', + 'baseProfile', + 'calcMode', + 'clipPathUnits', + 'diffuseConstant', + 'edgeMode', + 'filterUnits', + 'glyphRef', + 'gradientTransform', + 'gradientUnits', + 'kernelMatrix', + 'kernelUnitLength', + 'keyPoints', + 'keySplines', + 'keyTimes', + 'lengthAdjust', + 'limitingConeAngle', + 'markerHeight', + 'markerUnits', + 'markerWidth', + 'maskContentUnits', + 'maskUnits', + 'numOctaves', + 'pathLength', + 'patternContentUnits', + 'patternTransform', + 'patternUnits', + 'pointsAtX', + 'pointsAtY', + 'pointsAtZ', + 'preserveAlpha', + 'preserveAspectRatio', + 'primitiveUnits', + 'refX', + 'refY', + 'repeatCount', + 'repeatDur', + 'requiredExtensions', + 'requiredFeatures', + 'specularConstant', + 'specularExponent', + 'spreadMethod', + 'startOffset', + 'stdDeviation', + 'stitchTiles', + 'surfaceScale', + 'systemLanguage', + 'tableValues', + 'targetX', + 'targetY', + 'textLength', + 'viewBox', + 'viewTarget', + 'xChannelSelector', + 'yChannelSelector', + 'zoomAndPan', + ].map((attr) => [attr.toLowerCase(), attr]) +); const XML_ATTRS_ADJUSTMENT_MAP = new Map([ ['xlink:actuate', { prefix: 'xlink', name: 'actuate', namespace: NS.XLINK }], @@ -87,44 +89,46 @@ const XML_ATTRS_ADJUSTMENT_MAP = new Map([ ]); //SVG tag names adjustment map -export const SVG_TAG_NAMES_ADJUSTMENT_MAP = new Map([ - ['altglyph', 'altGlyph'], - ['altglyphdef', 'altGlyphDef'], - ['altglyphitem', 'altGlyphItem'], - ['animatecolor', 'animateColor'], - ['animatemotion', 'animateMotion'], - ['animatetransform', 'animateTransform'], - ['clippath', 'clipPath'], - ['feblend', 'feBlend'], - ['fecolormatrix', 'feColorMatrix'], - ['fecomponenttransfer', 'feComponentTransfer'], - ['fecomposite', 'feComposite'], - ['feconvolvematrix', 'feConvolveMatrix'], - ['fediffuselighting', 'feDiffuseLighting'], - ['fedisplacementmap', 'feDisplacementMap'], - ['fedistantlight', 'feDistantLight'], - ['feflood', 'feFlood'], - ['fefunca', 'feFuncA'], - ['fefuncb', 'feFuncB'], - ['fefuncg', 'feFuncG'], - ['fefuncr', 'feFuncR'], - ['fegaussianblur', 'feGaussianBlur'], - ['feimage', 'feImage'], - ['femerge', 'feMerge'], - ['femergenode', 'feMergeNode'], - ['femorphology', 'feMorphology'], - ['feoffset', 'feOffset'], - ['fepointlight', 'fePointLight'], - ['fespecularlighting', 'feSpecularLighting'], - ['fespotlight', 'feSpotLight'], - ['fetile', 'feTile'], - ['feturbulence', 'feTurbulence'], - ['foreignobject', 'foreignObject'], - ['glyphref', 'glyphRef'], - ['lineargradient', 'linearGradient'], - ['radialgradient', 'radialGradient'], - ['textpath', 'textPath'], -]); +export const SVG_TAG_NAMES_ADJUSTMENT_MAP = new Map( + [ + 'altGlyph', + 'altGlyphDef', + 'altGlyphItem', + 'animateColor', + 'animateMotion', + 'animateTransform', + 'clipPath', + 'feBlend', + 'feColorMatrix', + 'feComponentTransfer', + 'feComposite', + 'feConvolveMatrix', + 'feDiffuseLighting', + 'feDisplacementMap', + 'feDistantLight', + 'feFlood', + 'feFuncA', + 'feFuncB', + 'feFuncG', + 'feFuncR', + 'feGaussianBlur', + 'feImage', + 'feMerge', + 'feMergeNode', + 'feMorphology', + 'feOffset', + 'fePointLight', + 'feSpecularLighting', + 'feSpotLight', + 'feTile', + 'feTurbulence', + 'foreignObject', + 'glyphRef', + 'linearGradient', + 'radialGradient', + 'textPath', + ].map((tn) => [tn.toLowerCase(), tn]) +); //Tags that causes exit from foreign content const EXITS_FOREIGN_CONTENT = new Set([ @@ -198,7 +202,7 @@ export function adjustTokenSVGAttrs(token: TagToken) { for (let i = 0; i < token.attrs.length; i++) { const adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name); - if (adjustedAttrName) { + if (adjustedAttrName != null) { token.attrs[i].name = adjustedAttrName; } } @@ -219,7 +223,7 @@ export function adjustTokenXMLAttrs(token: TagToken) { export function adjustTokenSVGTagName(token: TagToken) { const adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP.get(token.tagName); - if (adjustedTagName) { + if (adjustedTagName != null) { token.tagName = adjustedTagName; } }