mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Removed tidy html. (#6039)
This commit is contained in:
parent
8d014fb7e9
commit
d5fc948705
7 changed files with 0 additions and 132 deletions
|
@ -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`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}`;
|
||||
|
|
|
@ -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?
|
||||
*/
|
||||
|
|
|
@ -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}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
|
@ -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, '<html><body><p>a paragraph</p><li>List without outer UL</li>trailing closing p</p></body></html>');
|
||||
tidy(tmpFile, (err) => {
|
||||
assert.ok(!err);
|
||||
|
||||
// Read the file again
|
||||
const cleanedHtml = fs.readFileSync(tmpFile).toString();
|
||||
|
||||
const expectedHtml = [
|
||||
'<title></title>',
|
||||
'</head>',
|
||||
'<body>',
|
||||
'<p>a paragraph</p>',
|
||||
'<ul>',
|
||||
'<li>List without outer UL</li>',
|
||||
'<li style="list-style: none">trailing closing p</li>',
|
||||
'</ul>',
|
||||
'</body>',
|
||||
'</html>',
|
||||
].join('\n');
|
||||
assert.notStrictEqual(cleanedHtml.indexOf(expectedHtml), -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can deal with errors', 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();
|
||||
}
|
||||
|
||||
tidy('/some/none/existing/file.html', (err) => {
|
||||
assert.ok(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue