Implement XMLSerializer for node.

This commit is contained in:
Jürg Lehni 2013-05-08 20:18:46 -07:00
parent 892640172b
commit 3fb22f0380

View file

@ -16,6 +16,7 @@ var fs = require('fs'),
// Node Canvas library: https://github.com/learnboost/node-canvas
Canvas = require('canvas'),
jsdom = require('jsdom'),
domToHtml = require('jsdom/lib/jsdom/browser/domtohtml').domToHtml,
dirname = path.resolve(__dirname, '..');
var options = {
@ -30,6 +31,20 @@ var options = {
var win = jsdom.createWindow(),
doc = win.document = jsdom.jsdom("<html><body></body></html>");
// Define XMLSerializer.
// TODO: Put this into a simple node module, with dependency on jsdom
function XMLSerializer() {
}
XMLSerializer.prototype.serializeToString = function(node) {
var text = domToHtml(node);
// Fix a jsdom issue where linearGradient gets converted to lineargradient:
// https://github.com/tmpvar/jsdom/issues/620
return text.replace(/(linear|radial)(gradient)/g, function(all, type) {
return type + 'Gradient';
});
};
// Create the context within which we will run the source files:
var context = vm.createContext({
// Used to load and run source files within the same context: