summaryrefslogtreecommitdiff
path: root/src/node/utils
diff options
context:
space:
mode:
authorSimon Gaeremynck <gaeremyncks@gmail.com>2015-05-18 16:24:41 +0100
committerSimon Gaeremynck <gaeremyncks@gmail.com>2015-05-18 16:24:41 +0100
commit786b43efc893ceb3fcf3d1d6acb9f46fc4b5426f (patch)
tree8c7bdb8dc80bec7b61243d418a1da5bebd84d561 /src/node/utils
parent9e9207d8b6091375017aba122eb8c3db0fb10e8a (diff)
downloadetherpad-lite-786b43efc893ceb3fcf3d1d6acb9f46fc4b5426f.zip
Tidy HTML before trying to convert it with abiword
Diffstat (limited to 'src/node/utils')
-rw-r--r--src/node/utils/Settings.js9
-rw-r--r--src/node/utils/TidyHtml.js35
2 files changed, 42 insertions, 2 deletions
diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js
index b7d1f0bc..2cc6a926 100644
--- a/src/node/utils/Settings.js
+++ b/src/node/utils/Settings.js
@@ -153,6 +153,11 @@ exports.minify = true;
exports.abiword = null;
/**
+ * The path of the tidy executable
+ */
+exports.tidyHtml = null;
+
+/**
* Should we support none natively supported file types on import?
*/
exports.allowUnknownFileEnds = true;
@@ -167,7 +172,7 @@ exports.loglevel = "INFO";
*/
exports.disableIPlogging = false;
-/**
+/**
* Disable Load Testing
*/
exports.loadTest = false;
@@ -239,7 +244,7 @@ exports.reloadSettings = function reloadSettings() {
} else {
settingsFilename = path.resolve(path.join(exports.root, settingsFilename));
}
-
+
var settingsStr;
try{
//read the settings sync
diff --git a/src/node/utils/TidyHtml.js b/src/node/utils/TidyHtml.js
new file mode 100644
index 00000000..13dc2ece
--- /dev/null
+++ b/src/node/utils/TidyHtml.js
@@ -0,0 +1,35 @@
+/**
+ * Tidy up the HTML in a given file
+ */
+
+var settings = require("./Settings");
+var spawn = require('child_process').spawn;
+
+exports.tidy = function(srcFile, callback) {
+ // Don't do anything if Tidy hasn't been enabled
+ if (!settings.tidyHtml) {
+ return callback(null);
+ }
+
+ var errMessage = '';
+
+ // Spawn a new tidy instance that cleans up the file inline
+ var tidy = spawn(settings.tidyHtml, ['-modify', srcFile]);
+
+ // Keep track of any error messages
+ tidy.stderr.on('data', function (data) {
+ errMessage += data.toString();
+ });
+
+ // Wait until Tidy is done
+ tidy.on('close', function(code) {
+ // Tidy returns a 0 when no errors occur and a 1 exit code when
+ // the file could be tidied but a few warnings were generated
+ if (code === 0 || code === 1) {
+ return callback(null);
+ } else {
+ console.error(errMessage);
+ return callback('Tidy died with exit code ' + code);
+ }
+ });
+};