diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index ae1c4cf..9603ef2 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -8,6 +8,7 @@ import { isScriptElement, isSelectElement, isStyleElement, + isSVGElementNode, isTextareaElement, isTextNode } from './node-parser'; @@ -409,10 +410,17 @@ export class DocumentCloner { }); anonymousReplacedElement.className = `${PSEUDO_HIDE_ELEMENT_CLASS_BEFORE} ${PSEUDO_HIDE_ELEMENT_CLASS_AFTER}`; - clone.className += + const newClassName = pseudoElt === PseudoElementType.BEFORE ? ` ${PSEUDO_HIDE_ELEMENT_CLASS_BEFORE}` : ` ${PSEUDO_HIDE_ELEMENT_CLASS_AFTER}`; + + if (isSVGElementNode(clone)) { + clone.className.baseValue += newClassName; + } else { + clone.className += newClassName; + } + return anonymousReplacedElement; } diff --git a/src/dom/node-parser.ts b/src/dom/node-parser.ts index 238115e..791247b 100644 --- a/src/dom/node-parser.ts +++ b/src/dom/node-parser.ts @@ -103,7 +103,8 @@ export const isTextNode = (node: Node): node is Text => node.nodeType === Node.T export const isElementNode = (node: Node): node is Element => node.nodeType === Node.ELEMENT_NODE; export const isHTMLElementNode = (node: Node): node is HTMLElement => typeof (node as HTMLElement).style !== 'undefined'; - +export const isSVGElementNode = (element: Element): element is SVGElement => + typeof (element as SVGElement).className === 'object'; export const isLIElement = (node: Element): node is HTMLLIElement => node.tagName === 'LI'; export const isOLElement = (node: Element): node is HTMLOListElement => node.tagName === 'OL'; export const isInputElement = (node: Element): node is HTMLInputElement => node.tagName === 'INPUT'; diff --git a/tests/reftests/images/svg/native_only.html b/tests/reftests/images/svg/native_only.html index 8ab8f5d..a6a7c25 100644 --- a/tests/reftests/images/svg/native_only.html +++ b/tests/reftests/images/svg/native_only.html @@ -11,13 +11,16 @@ body { font-family: Arial; } + svg:before { + content: " "; + }