1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Improved export to HTML when note is already HTML

This commit is contained in:
Laurent Cozic 2019-12-17 00:40:25 +00:00
parent df85bb189d
commit 931e7a7795
4 changed files with 11 additions and 6 deletions

View File

@ -43,6 +43,7 @@ class InteropServiceHelper {
const result = await service.export(exportOptions);
console.info('Export result: ', result);
} catch (error) {
console.error(error);
bridge().showErrorMessageBox(_('Could not export notes: %s', error.message));
}

View File

@ -4,6 +4,7 @@ const noteStyle = require('./noteStyle');
class HtmlToHtml {
constructor(options) {
if (!options) options = {};
this.resourceBaseUrl_ = 'resourceBaseUrl' in options ? options.resourceBaseUrl : null;
}

View File

@ -184,10 +184,13 @@ class InteropService {
* https://github.com/laurent22/joplin/pull/1795#pullrequestreview-281574417
*/
newModuleFromPath_(type, options) {
if (!options || !options.modulePath) {
throw new Error('Cannot load module without a defined path to load from.');
let modulePath = options && options.modulePath ? options.modulePath : '';
if (!modulePath) {
const moduleMetadata = this.findModuleByFormat_(type, options.format, options.target);
modulePath = moduleMetadata.path;
}
const ModuleClass = require(options.modulePath);
const ModuleClass = require(modulePath);
const output = new ModuleClass();
const moduleMetadata = this.findModuleByFormat_(type, options.format, options.target);
output.setMetadata({options, ...moduleMetadata}); // TODO: Check that this metadata is equivalent to module above

View File

@ -6,7 +6,7 @@ const Note = require('lib/models/Note');
const Setting = require('lib/models/Setting');
const Resource = require('lib/models/Resource');
const { shim } = require('lib/shim');
const MdToHtml = require('lib/renderers/MdToHtml.js');
const MarkupToHtml = require('lib/renderers/MarkupToHtml.js');
const dataurl = require('dataurl');
const { themeStyle } = require('../../theme.js');
const { dirname } = require('lib/path-utils.js');
@ -26,7 +26,7 @@ class InteropService_Exporter_Html extends InteropService_Exporter_Base {
this.resourceDir_ = this.destDir_ ? `${this.destDir_}/_resources` : null;
await shim.fsDriver().mkdir(this.destDir_);
this.mdToHtml_ = new MdToHtml();
this.markupToHtml_ = new MarkupToHtml();
this.resources_ = [];
this.style_ = themeStyle(Setting.THEME_LIGHT);
}
@ -102,7 +102,7 @@ class InteropService_Exporter_Html extends InteropService_Exporter_Base {
}
const bodyMd = await this.processNoteResources_(item);
const result = this.mdToHtml_.render(bodyMd, this.style_, { resources: this.resources_, plainResourceRendering: true });
const result = this.markupToHtml_.render(item.markup_language, bodyMd, this.style_, { resources: this.resources_, plainResourceRendering: true });
const noteContent = [];
if (item.title) noteContent.push(`<div class="exported-note-title">${item.title}</div>`);
if (result.html) noteContent.push(result.html);