From 6d7f128b870cc405151e44484a35999a0cbb69b0 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Wed, 24 Aug 2016 10:54:52 -0700 Subject: [PATCH 1/3] Use an EEJS template for HTML export instead of inlining it in the JS code. The semantics of all the substitutions are identical to what they were before. I _did_ take the liberty of formatting the CSS to be a bit more readable (at the cost of adding a little bit of whitespace). --- src/node/utils/ExportHtml.js | 110 ++----------------------- src/templates/export_html.html | 143 +++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 102 deletions(-) create mode 100644 src/templates/export_html.html diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index 836165b16..f2e275eea 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -22,6 +22,7 @@ var ERR = require("async-stacktrace"); var _ = require('underscore'); var Security = require('ep_etherpad-lite/static/js/security'); var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); +var eejs = require('ep_etherpad-lite/node/eejs'); var _analyzeLine = require('./ExportHelper')._analyzeLine; var _encodeWhitespace = require('./ExportHelper')._encodeWhitespace; @@ -490,112 +491,17 @@ exports.getPadHTMLDocument = function (padId, revNum, noDocType, callback) stylesForExport.forEach(function(css){ stylesForExportCSS += css; }); - // Core inclusion of head etc. - var head = - (noDocType ? '' : '\n') + - '\n' + (noDocType ? '' : '\n' + - '' + Security.escapeHTML(padId) + '\n' + - '\n' + - '\n' + - '\n' + - '\n' + - '\n' + '\n') + - ''; - var foot = '\n\n'; getPadHTML(pad, revNum, function (err, html) { if(ERR(err, callback)) return; - callback(null, head + html + foot); + var exportedDoc = eejs.require("ep_etherpad-lite/templates/export_html.html", { + body: html, + doctype: noDocType ? '' : '', + padId: Security.escapeHTML(padId), + extraCSS: stylesForExportCSS + }); + callback(null, exportedDoc); }); }); }); diff --git a/src/templates/export_html.html b/src/templates/export_html.html new file mode 100644 index 000000000..24e83ac2c --- /dev/null +++ b/src/templates/export_html.html @@ -0,0 +1,143 @@ +<%- doctype %> + + +<%- padId %> + + + + + + + +<%- body %> + + From 879ae7c67d6b0c7fa78e0e09435861e5509678a8 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Thu, 8 Sep 2016 09:41:23 -0700 Subject: [PATCH 2/3] Remove the `noDocType` argument, which was only ever passed as `false`. --- src/node/handler/ExportHandler.js | 2 +- src/node/hooks/express/padreadonly.js | 4 ++-- src/node/utils/ExportHtml.js | 3 +-- src/templates/export_html.html | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/node/handler/ExportHandler.js b/src/node/handler/ExportHandler.js index 8f91ced23..7cce6200b 100644 --- a/src/node/handler/ExportHandler.js +++ b/src/node/handler/ExportHandler.js @@ -92,7 +92,7 @@ exports.doExport = function(req, res, padId, type) //render the html document function(callback) { - exporthtml.getPadHTMLDocument(padId, req.params.rev, false, function(err, _html) + exporthtml.getPadHTMLDocument(padId, req.params.rev, function(err, _html) { if(ERR(err, callback)) return; html = _html; diff --git a/src/node/hooks/express/padreadonly.js b/src/node/hooks/express/padreadonly.js index 66be33390..bff8adf7b 100644 --- a/src/node/hooks/express/padreadonly.js +++ b/src/node/hooks/express/padreadonly.js @@ -7,7 +7,7 @@ var exporthtml = require("../../utils/ExportHtml"); exports.expressCreateServer = function (hook_name, args, cb) { //serve read only pad args.app.get('/ro/:id', function(req, res) - { + { var html; var padId; @@ -40,7 +40,7 @@ exports.expressCreateServer = function (hook_name, args, cb) { hasPadAccess(req, res, function() { //render the html document - exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html) + exporthtml.getPadHTMLDocument(padId, null, function(err, _html) { if(ERR(err, callback)) return; html = _html; diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index f2e275eea..bd177ac47 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -479,7 +479,7 @@ function getHTMLFromAtext(pad, atext, authorColors) return pieces.join(''); } -exports.getPadHTMLDocument = function (padId, revNum, noDocType, callback) +exports.getPadHTMLDocument = function (padId, revNum, callback) { padManager.getPad(padId, function (err, pad) { @@ -497,7 +497,6 @@ exports.getPadHTMLDocument = function (padId, revNum, noDocType, callback) if(ERR(err, callback)) return; var exportedDoc = eejs.require("ep_etherpad-lite/templates/export_html.html", { body: html, - doctype: noDocType ? '' : '', padId: Security.escapeHTML(padId), extraCSS: stylesForExportCSS }); diff --git a/src/templates/export_html.html b/src/templates/export_html.html index 24e83ac2c..b8893b717 100644 --- a/src/templates/export_html.html +++ b/src/templates/export_html.html @@ -1,4 +1,4 @@ -<%- doctype %> + <%- padId %> From a0403ffc22da6e94c88f89ea0ff0d65704947415 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Thu, 8 Sep 2016 09:46:13 -0700 Subject: [PATCH 3/3] Remove unused parameter `noDocType`. My editor also auto-stripped some EOL whitespace. --- src/node/handler/ExportHandler.js | 2 +- src/node/utils/ExportTxt.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/node/handler/ExportHandler.js b/src/node/handler/ExportHandler.js index 7cce6200b..fe7ab3db1 100644 --- a/src/node/handler/ExportHandler.js +++ b/src/node/handler/ExportHandler.js @@ -76,7 +76,7 @@ exports.doExport = function(req, res, padId, type) } else if(type == "txt") { - exporttxt.getPadTXTDocument(padId, req.params.rev, false, function(err, txt) + exporttxt.getPadTXTDocument(padId, req.params.rev, function(err, txt) { if(ERR(err)) return; res.send(txt); diff --git a/src/node/utils/ExportTxt.js b/src/node/utils/ExportTxt.js index a6bec4a58..e3ce01520 100644 --- a/src/node/utils/ExportTxt.js +++ b/src/node/utils/ExportTxt.js @@ -192,7 +192,7 @@ function getTXTFromAtext(pad, atext, authorColors) tags2close.push(i); } } - + for (var i = 0; i < propVals.length; i++) { if (propVals[i] === ENTER || propVals[i] === STAY) @@ -208,10 +208,10 @@ function getTXTFromAtext(pad, atext, authorColors) { chars--; // exclude newline at end of line, if present } - + var s = taker.take(chars); - // removes the characters with the code 12. Don't know where they come + // removes the characters with the code 12. Don't know where they come // from but they break the abiword parser and are completly useless // s = s.replace(String.fromCharCode(12), ""); @@ -221,7 +221,7 @@ function getTXTFromAtext(pad, atext, authorColors) assem.append(s); } // end iteration over spans in line - + var tags2close = []; for (var i = propVals.length - 1; i >= 0; i--) { @@ -231,7 +231,7 @@ function getTXTFromAtext(pad, atext, authorColors) propVals[i] = false; } } - + } // end processNextChars processNextChars(text.length - idx); return(assem.toString()); @@ -271,7 +271,7 @@ function getTXTFromAtext(pad, atext, authorColors) } exports.getTXTFromAtext = getTXTFromAtext; -exports.getPadTXTDocument = function (padId, revNum, noDocType, callback) +exports.getPadTXTDocument = function (padId, revNum, callback) { padManager.getPad(padId, function (err, pad) {