summaryrefslogtreecommitdiff
path: root/src/node/utils
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2015-05-19 16:44:57 +0100
committerJohn McLear <john@mclear.co.uk>2015-05-19 16:44:57 +0100
commit41d24a8c8f1ab2953811192fdc12c1f1aee18d11 (patch)
treecef25616f9e78b6221c01170f434ccd255ff9962 /src/node/utils
parentb662d5c61802d42ee4214799520e7c3ed95a3ef5 (diff)
parent5615bab0d9e7cd62867991335dbf176055cc2332 (diff)
downloadetherpad-lite-41d24a8c8f1ab2953811192fdc12c1f1aee18d11.zip
Merge branch 'develop' of github.com:ether/etherpad-lite into develop
Diffstat (limited to 'src/node/utils')
-rw-r--r--src/node/utils/Settings.js9
-rw-r--r--src/node/utils/TidyHtml.js41
2 files changed, 48 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..5d4e6ed7
--- /dev/null
+++ b/src/node/utils/TidyHtml.js
@@ -0,0 +1,41 @@
+/**
+ * Tidy up the HTML in a given file
+ */
+
+var log4js = require('log4js');
+var settings = require('./Settings');
+var spawn = require('child_process').spawn;
+
+exports.tidy = function(srcFile, callback) {
+ var logger = log4js.getLogger('TidyHtml');
+
+ // Don't do anything if Tidy hasn't been enabled
+ if (!settings.tidyHtml) {
+ logger.debug('tidyHtml has not been configured yet, ignoring tidy request');
+ return callback(null);
+ }
+
+ var errMessage = '';
+
+ // Spawn a new tidy instance that cleans up the file inline
+ logger.debug('Tidying ' + srcFile);
+ 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) {
+ logger.debug('Tidied ' + srcFile + ' successfully');
+ return callback(null);
+ } else {
+ logger.error('Failed to tidy ' + srcFile + '\n' + errMessage);
+ return callback('Tidy died with exit code ' + code);
+ }
+ });
+};