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

Desktop: Fixes #2324: Apply userstyle again when exporting to PDF or printing

This commit is contained in:
Laurent Cozic 2020-01-24 21:46:48 +00:00
parent 5456dbbf16
commit 18c46851fd
5 changed files with 26 additions and 11 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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 = {

View File

@ -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) {}

View File

@ -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(`<div class="exported-note-title">${escapeHtml(item.title)}</div>`);
if (result.html) noteContent.push(result.html);