diff --git a/ElectronClient/app/InteropServiceHelper.js b/ElectronClient/app/InteropServiceHelper.js index 0e9314cce..6686d3f76 100644 --- a/ElectronClient/app/InteropServiceHelper.js +++ b/ElectronClient/app/InteropServiceHelper.js @@ -8,13 +8,16 @@ const { shim } = require('lib/shim'); class InteropServiceHelper { - static async exportNoteToHtmlFile(noteId) { + static async exportNoteToHtmlFile(noteId, exportOptions) { const tempFile = `${Setting.value('tempDir')}/${md5(Date.now() + Math.random())}.html`; - const exportOptions = {}; - exportOptions.path = tempFile; - exportOptions.format = 'html'; - exportOptions.target = 'file'; - exportOptions.sourceNoteIds = [noteId]; + + exportOptions = Object.assign({}, { + path: tempFile, + format: 'html', + target: 'file', + sourceNoteIds: [noteId], + customCss: '', + }, exportOptions); const service = new InteropService(); @@ -33,7 +36,11 @@ class InteropServiceHelper { }; try { - htmlFile = await this.exportNoteToHtmlFile(noteId); + const exportOptions = { + customCss: options.customCss ? options.customCss : '', + }; + + htmlFile = await this.exportNoteToHtmlFile(noteId, exportOptions); const windowOptions = { show: false, diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 87c3f56f2..8344ceadf 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -1264,6 +1264,7 @@ class NoteTextComponent extends React.Component { printBackground: true, pageSize: Setting.value('export.pdfPageSize'), landscape: Setting.value('export.pdfPageOrientation') === 'landscape', + customCss: this.props.customCss, }); await shim.fsDriver().writeFile(options.path, pdfData, 'buffer'); } catch (error) { @@ -1274,6 +1275,7 @@ class NoteTextComponent extends React.Component { try { await InteropServiceHelper.printNote(options.noteId, { printBackground: true, + customCss: this.props.customCss, }); } catch (error) { console.error(error); diff --git a/ReactNativeClient/lib/services/InteropService.js b/ReactNativeClient/lib/services/InteropService.js index 6cc314436..229d656ba 100644 --- a/ReactNativeClient/lib/services/InteropService.js +++ b/ReactNativeClient/lib/services/InteropService.js @@ -331,7 +331,7 @@ class InteropService { } const exporter = this.newModuleFromPath_('exporter', options);// this.newModuleByFormat_('exporter', exportFormat); - await exporter.init(exportPath); + await exporter.init(exportPath, options); const typeOrder = [BaseModel.TYPE_FOLDER, BaseModel.TYPE_RESOURCE, BaseModel.TYPE_NOTE, BaseModel.TYPE_TAG, BaseModel.TYPE_NOTE_TAG]; const context = { diff --git a/ReactNativeClient/lib/services/InteropService_Exporter_Base.js b/ReactNativeClient/lib/services/InteropService_Exporter_Base.js index 1fb7d0311..1fd371101 100644 --- a/ReactNativeClient/lib/services/InteropService_Exporter_Base.js +++ b/ReactNativeClient/lib/services/InteropService_Exporter_Base.js @@ -7,7 +7,7 @@ class InteropService_Exporter_Base { this.context_ = {}; } - async init(destDir) {} + async init(destDir, options = {}) {} async prepareForProcessingItemType(type, itemsToExport) {} async processItem(ItemClass, item) {} async processResource(resource, filePath) {} diff --git a/ReactNativeClient/lib/services/InteropService_Exporter_Html.js b/ReactNativeClient/lib/services/InteropService_Exporter_Html.js index a5b0ee3d8..10bc4c752 100644 --- a/ReactNativeClient/lib/services/InteropService_Exporter_Html.js +++ b/ReactNativeClient/lib/services/InteropService_Exporter_Html.js @@ -13,7 +13,9 @@ const { assetsToHeaders } = require('joplin-renderer'); class InteropService_Exporter_Html extends InteropService_Exporter_Base { - async init(path) { + async init(path, options = {}) { + this.customCss_ = options.customCss ? options.customCss : ''; + if (this.metadata().target === 'file') { this.destDir_ = dirname(path); this.filePath_ = path; @@ -88,7 +90,11 @@ class InteropService_Exporter_Html extends InteropService_Exporter_Base { } const bodyMd = await this.processNoteResources_(item); - const result = await this.markupToHtml_.render(item.markup_language, bodyMd, this.style_, { resources: this.resources_, plainResourceRendering: true }); + const result = await this.markupToHtml_.render(item.markup_language, bodyMd, this.style_, { + resources: this.resources_, + plainResourceRendering: true, + userCss: this.customCss_, + }); const noteContent = []; if (item.title) noteContent.push(`