From b9b991c5feb62b018155cdf8f8190e7e7b0a5ea5 Mon Sep 17 00:00:00 2001 From: Tyler Long Date: Sun, 16 Apr 2017 17:52:09 +0800 Subject: [PATCH] Refactor code in lib/ folder --- lib/cli.js | 3 --- lib/index.js | 2 -- lib/phantomscript.js | 60 -------------------------------------------- 3 files changed, 65 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 1c17f13b4..8ec940397 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -9,7 +9,6 @@ var path = require('path') var PHANTOM_VERSION = '^2.1.0' var info = chalk.blue.bold -// var note = chalk.green.bold module.exports = (function () { return new Cli() @@ -63,7 +62,6 @@ function Cli (options) { Cli.prototype.parse = function (argv, next) { this.errors = [] // clear errors var options = parseArgs(argv, this.options) - // var phantom if (options.version) { var pkg = require('../package.json') @@ -148,7 +146,6 @@ Cli.prototype.parse = function (argv, next) { function createCheckPhantom (_phantomPath) { var phantomPath = _phantomPath - // var phantomVersion return function checkPhantom (_next) { var next = _next || function () { } diff --git a/lib/index.js b/lib/index.js index d5ff5acd4..329ca507f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,3 @@ -// var os = require('os') -// var fs = require('fs') var path = require('path') var spawn = require('child_process').spawn diff --git a/lib/phantomscript.js b/lib/phantomscript.js index 187423337..694167ed3 100644 --- a/lib/phantomscript.js +++ b/lib/phantomscript.js @@ -74,7 +74,6 @@ files.forEach(function (file) { var oParser = new window.DOMParser() var oDOM var svgContent - var allElements console.log('ready to execute png: ' + filename + '.png ') @@ -93,13 +92,6 @@ files.forEach(function (file) { resolveSVGElement(oDOM.firstChild) setSVGStyle(oDOM.firstChild, options.css) - // traverse the SVG, and replace all foreignObject elements - // can be removed when https://github.com/knsv/mermaid/issues/58 is resolved - allElements = traverse(oDOM) - for (var i = 0, len = allElements.length; i < len; i++) { - resolveForeignObjects(allElements[i]) - } - var outputPath = options.outputDir + fs.separator + filename + options.outputSuffix if (options.png) { page.viewportSize = { @@ -139,37 +131,12 @@ function logger (_verbose) { } } -function traverse (obj) { - var tree = [] - - tree.push(obj) - visit(obj) - - function visit (node) { - if (node && node.hasChildNodes()) { - var child = node.firstChild - while (child) { - if (child.nodeType === 1 && child.nodeName !== 'SCRIPT') { - tree.push(child) - visit(child) - } - child = child.nextSibling - } - } - } - - return tree -} - function resolveSVGElement (element) { var prefix = { xmlns: 'http://www.w3.org/2000/xmlns/', xlink: 'http://www.w3.org/1999/xlink', svg: 'http://www.w3.org/2000/svg' } - // var doctype = '' element.setAttribute('version', '1.1') // removing attributes so they aren't doubled up @@ -191,38 +158,12 @@ function setSVGStyle (svg, css) { styles[0].textContent = css } -function resolveForeignObjects (element) { - // return - // var children - // var textElement - // var textSpan - - // if (element.tagName === 'foreignObject') { - // textElement = document.createElement('text') - // textSpan = document.createElement('tspan') - // textSpan.setAttribute( - // 'style' - // , 'font-size: 11.5pt; font-family: "sans-serif";' - // ) - // textSpan.setAttribute('x', 0) - // textSpan.setAttribute('y', 14.5) - // textSpan.textContent = element.textContent - - // textElement.appendChild(textSpan) - // element.parentElement.appendChild(textElement) - // element.parentElement.removeChild(element) - // } -} - // The sandboxed function that's executed in-page by phantom function executeInPage (data) { var xmlSerializer = new window.XMLSerializer() var contents = data.contents var sequenceConfig = JSON.stringify(data.sequenceConfig) var ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, '$1') - // var toRemove - // var el - // var elContent var svg var svgValue var boundingBox @@ -286,6 +227,5 @@ function executeInPage (data) { ) svgValue = xmlSerializer.serializeToString(svg) + '\n' - // console.log('confWidth: '+document.head.outerHTML); return svgValue }