Skip to content
Merged
11 changes: 9 additions & 2 deletions src/node/handler/ImportHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,15 @@ async function doImport(req, res, padId)
if (!req.directDatabaseAccess) {
text = await fsp_readFile(destFile, "utf8");

// Title needs to be stripped out else it appends it to the pad..
text = text.replace("<title>", "<!-- <title>");
/*
* The <title> tag needs to be stripped out, otherwise it is appended to the
* pad.
*
* Moreover, when using LibreOffice to convert the file, some classes are
* added to the <title> tag. This is a quick & dirty way of matching the
* title and comment it out independently on the classes that are set on it.
*/
text = text.replace("<title", "<!-- <title");
text = text.replace("</title>","</title>-->");

// node on windows has a delay on releasing of the file lock.
Expand Down
14 changes: 11 additions & 3 deletions src/node/utils/LibreOffice.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ var libreOfficeLogger = log4js.getLogger('LibreOffice');
* @param {Function} callback Standard callback function
*/
exports.convertFile = function(srcFile, destFile, type, callback) {
// Used for the moving of the file, not the conversion
var fileExtension = type;

if (type === "html") {
// "html:XHTML Writer File:UTF8" does a better job than normal html exports
type = "html:XHTML Writer File:UTF8";
}

// soffice can't convert from html to doc directly (verified with LO 5 and 6)
// we need to convert to odt first, then to doc
// to avoid `Error: no export filter for /tmp/xxxx.doc` error
Expand All @@ -47,11 +55,11 @@ exports.convertFile = function(srcFile, destFile, type, callback) {
"destFile": destFile.replace(/\.doc$/, '.odt'),
"type": 'odt',
"callback": function () {
queue.push({"srcFile": srcFile.replace(/\.html$/, '.odt'), "destFile": destFile, "type": type, "callback": callback});
queue.push({"srcFile": srcFile.replace(/\.html$/, '.odt'), "destFile": destFile, "type": type, "callback": callback, "fileExtension": fileExtension });
}
});
} else {
queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback});
queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback, "fileExtension": fileExtension});
}
};

Expand Down Expand Up @@ -102,7 +110,7 @@ function doConvertTask(task, callback) {
// Move the converted file to the correct place
function(callback) {
var filename = path.basename(task.srcFile);
var sourceFilename = filename.substr(0, filename.lastIndexOf('.')) + '.' + task.type;
var sourceFilename = filename.substr(0, filename.lastIndexOf('.')) + '.' + task.fileExtension;
var sourcePath = path.join(tmpDir, sourceFilename);
libreOfficeLogger.debug(`Renaming ${sourcePath} to ${task.destFile}`);
fs.rename(sourcePath, task.destFile, callback);
Expand Down
10 changes: 10 additions & 0 deletions src/static/js/contentcollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ function makeContentCollector(collectStyles, abrowser, apool, domInterface, clas
if (isPre) cc.incrementFlag(state, 'preMode');
var oldListTypeOrNull = null;
var oldAuthorOrNull = null;

// LibreOffice Writer puts in weird items during import or copy/paste, we should drop them.
if (cls === "Numbering_20_Symbols" || cls === "Bullet_20_Symbols") {
styl = null;
cls = null;

// We have to return here but this could break things in the future, for now it shows how to fix the problem
return;
}

if (collectStyles)
{
hooks.callAll('collectContentPre', {
Expand Down