mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Implement XMLSerializer for node.
This commit is contained in:
parent
892640172b
commit
3fb22f0380
1 changed files with 15 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue