From 11d81a4b7c79746546cc8c718e6a5d4e7b756c47 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:28:48 +0100 Subject: [PATCH] Removed tidy html. --- doc/docker.adoc | 4 -- settings.json.docker | 8 ---- settings.json.template | 8 ---- src/node/handler/ExportHandler.js | 3 -- src/node/utils/Settings.js | 5 --- src/node/utils/TidyHtml.js | 43 -------------------- src/tests/backend/specs/api/tidy.js | 61 ----------------------------- 7 files changed, 132 deletions(-) delete mode 100644 src/node/utils/TidyHtml.js delete mode 100644 src/tests/backend/specs/api/tidy.js diff --git a/doc/docker.adoc b/doc/docker.adoc index d49c4651002..5f4b7812010 100644 --- a/doc/docker.adoc +++ b/doc/docker.adoc @@ -441,10 +441,6 @@ For the editor container, you can also make it full width by adding `full-width- | This is the absolute path to the soffice executable. LibreOffice can be used in lieu of Abiword to export pads. Setting it to null disables LibreOffice exporting. | `null` -| `TIDY_HTML` -| Path to the Tidy executable. Tidy is used to improve the quality of exported pads. Setting it to null disables Tidy. -| `null` - | `ALLOW_UNKNOWN_FILE_ENDS` | Allow import of file types other than the supported ones: txt, doc, docx, rtf, odt, html & htm | `true` diff --git a/settings.json.docker b/settings.json.docker index dbe6bebee02..79f72f05e5d 100644 --- a/settings.json.docker +++ b/settings.json.docker @@ -322,14 +322,6 @@ */ "soffice": "${SOFFICE:null}", - /* - * Path to the Tidy executable. - * - * Tidy is used to improve the quality of exported pads. - * Setting it to null disables Tidy. - */ - "tidyHtml": "${TIDY_HTML:null}", - /* * Allow import of file types other than the supported ones: * txt, doc, docx, rtf, odt, html & htm diff --git a/settings.json.template b/settings.json.template index ea8f4181220..735b9d5e7df 100644 --- a/settings.json.template +++ b/settings.json.template @@ -323,14 +323,6 @@ */ "soffice": null, - /* - * Path to the Tidy executable. - * - * Tidy is used to improve the quality of exported pads. - * Setting it to null disables Tidy. - */ - "tidyHtml": null, - /* * Allow import of file types other than the supported ones: * txt, doc, docx, rtf, odt, html & htm diff --git a/src/node/handler/ExportHandler.js b/src/node/handler/ExportHandler.js index e0a89e6d057..250221d186c 100644 --- a/src/node/handler/ExportHandler.js +++ b/src/node/handler/ExportHandler.js @@ -27,7 +27,6 @@ const fs = require('fs'); const settings = require('../utils/Settings'); const os = require('os'); const hooks = require('../../static/js/pluginfw/hooks'); -const TidyHtml = require('../utils/TidyHtml'); const util = require('util'); const { checkValidRev } = require('../utils/checkValidRev'); @@ -93,10 +92,8 @@ exports.doExport = async (req, res, padId, readOnlyId, type) => { const srcFile = `${tempDirectory}/etherpad_export_${randNum}.html`; await fsp_writeFile(srcFile, html); - // Tidy up the exported HTML // ensure html can be collected by the garbage collector html = null; - await TidyHtml.tidy(srcFile); // send the convert job to the converter (abiword, libreoffice, ..) const destFile = `${tempDirectory}/etherpad_export_${randNum}.${type}`; diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index c9a85daea33..9646c1f89ff 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -260,11 +260,6 @@ exports.abiword = null; */ exports.soffice = null; -/** - * The path of the tidy executable - */ -exports.tidyHtml = null; - /** * Should we support none natively supported file types on import? */ diff --git a/src/node/utils/TidyHtml.js b/src/node/utils/TidyHtml.js deleted file mode 100644 index 5b48cdbad37..00000000000 --- a/src/node/utils/TidyHtml.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; -/** - * Tidy up the HTML in a given file - */ - -const log4js = require('log4js'); -const settings = require('./Settings'); -const spawn = require('child_process').spawn; - -exports.tidy = (srcFile) => { - const logger = log4js.getLogger('TidyHtml'); - - return new Promise((resolve, reject) => { - // 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 resolve(null); - } - - let errMessage = ''; - - // Spawn a new tidy instance that cleans up the file inline - logger.debug(`Tidying ${srcFile}`); - const tidy = spawn(settings.tidyHtml, ['-modify', srcFile]); - - // Keep track of any error messages - tidy.stderr.on('data', (data) => { - errMessage += data.toString(); - }); - - tidy.on('close', (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`); - resolve(null); - } else { - logger.error(`Failed to tidy ${srcFile}\n${errMessage}`); - reject(`Tidy died with exit code ${code}`); - } - }); - }); -}; diff --git a/src/tests/backend/specs/api/tidy.js b/src/tests/backend/specs/api/tidy.js deleted file mode 100644 index 6a8bd6a2abe..00000000000 --- a/src/tests/backend/specs/api/tidy.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -const Settings = require('../../../../node/utils/Settings'); -const TidyHtml = require('../../../../node/utils/TidyHtml'); -const assert = require('assert'); -const os = require('os'); -const fs = require('fs'); -const path = require('path'); -const nodeify = require('nodeify'); - -describe(__filename, function () { - describe('tidyHtml', function () { - const tidy = (file, callback) => nodeify(TidyHtml.tidy(file), callback); - - it('Tidies HTML', function (done) { - // If the user hasn't configured Tidy, we skip this tests as it's required for this test - if (!Settings.tidyHtml) { - this.skip(); - } - - // Try to tidy up a bad HTML file - const tmpDir = os.tmpdir(); - - const tmpFile = path.join(tmpDir, `tmp_${Math.floor(Math.random() * 1000000)}.html`); - fs.writeFileSync(tmpFile, '
a paragraph
a paragraph
', - '