Improve Node.js XMLSerializer workaround for lowercased tagNames.

This commit is contained in:
Jürg Lehni 2013-06-11 14:39:34 -07:00
parent d41f79598e
commit 35f17979df

View file

@ -38,11 +38,18 @@ function XMLSerializer() {
XMLSerializer.prototype.serializeToString = function(node) { XMLSerializer.prototype.serializeToString = function(node) {
var text = domToHtml(node); var text = domToHtml(node);
// Fix a jsdom issue where linearGradient gets converted to lineargradient: // Fix a jsdom issue where all SVG tagNames are lowercased:
// https://github.com/tmpvar/jsdom/issues/620 // https://github.com/tmpvar/jsdom/issues/620
return text.replace(/(linear|radial)gradient/g, function(all, type) { var tagNames = ['linearGradient', 'radialGradient', 'clipPath'];
return type + 'Gradient'; for (var i = 0, l = tagNames.length; i < l; i++) {
}); var tagName = tagNames[i];
text = text.replace(
new RegExp('(<|</)' + tagName.toLowerCase() + '\\b', 'g'),
function(all, start) {
return start + tagName;
});
}
return text;
}; };
function DOMParser() { function DOMParser() {