mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-18 09:35:20 +02:00
Desktop, Cli: Prevent PDF and HTML export from failing when a plugin references a non-existent file
This commit is contained in:
parent
ca9759738f
commit
d1fc69ffbe
@ -1,4 +1,5 @@
|
|||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
|
import { pathExistsSync } from 'fs-extra';
|
||||||
const Entities = require('html-entities').AllHtmlEntities;
|
const Entities = require('html-entities').AllHtmlEntities;
|
||||||
const htmlparser2 = require('@joplin/fork-htmlparser2');
|
const htmlparser2 = require('@joplin/fork-htmlparser2');
|
||||||
const Datauri = require('datauri/sync');
|
const Datauri = require('datauri/sync');
|
||||||
@ -102,6 +103,7 @@ const processLinkTag = (baseDir: string, _name: string, attrs: any): string => {
|
|||||||
|
|
||||||
const filePath = `${baseDir}/${href}`;
|
const filePath = `${baseDir}/${href}`;
|
||||||
|
|
||||||
|
if (!pathExistsSync(filePath)) return null;
|
||||||
const content = fs.readFileSync(filePath, 'utf8');
|
const content = fs.readFileSync(filePath, 'utf8');
|
||||||
return `<style>${processCssContent(dirname(filePath), content)}</style>`;
|
return `<style>${processCssContent(dirname(filePath), content)}</style>`;
|
||||||
};
|
};
|
||||||
|
@ -15,6 +15,9 @@ const { escapeHtml } = require('../../string-utils.js');
|
|||||||
import { assetsToHeaders } from '@joplin/renderer';
|
import { assetsToHeaders } from '@joplin/renderer';
|
||||||
import getPluginSettingValue from '../plugins/utils/getPluginSettingValue';
|
import getPluginSettingValue from '../plugins/utils/getPluginSettingValue';
|
||||||
import { LinkRenderingType } from '@joplin/renderer/MdToHtml';
|
import { LinkRenderingType } from '@joplin/renderer/MdToHtml';
|
||||||
|
import Logger from '@joplin/utils/Logger';
|
||||||
|
|
||||||
|
const logger = Logger.create('InteropService_Exporter_Html');
|
||||||
|
|
||||||
export default class InteropService_Exporter_Html extends InteropService_Exporter_Base {
|
export default class InteropService_Exporter_Html extends InteropService_Exporter_Base {
|
||||||
|
|
||||||
@ -136,11 +139,15 @@ export default class InteropService_Exporter_Html extends InteropService_Exporte
|
|||||||
for (let i = 0; i < result.pluginAssets.length; i++) {
|
for (let i = 0; i < result.pluginAssets.length; i++) {
|
||||||
const asset = result.pluginAssets[i];
|
const asset = result.pluginAssets[i];
|
||||||
const filePath = asset.pathIsAbsolute ? asset.path : `${libRootPath}/node_modules/@joplin/renderer/assets/${asset.name}`;
|
const filePath = asset.pathIsAbsolute ? asset.path : `${libRootPath}/node_modules/@joplin/renderer/assets/${asset.name}`;
|
||||||
const destPath = `${dirname(noteFilePath)}/pluginAssets/${asset.name}`;
|
if (!(await shim.fsDriver().exists(filePath))) {
|
||||||
const dir = dirname(destPath);
|
logger.warn(`File does not exist and cannot be exported: ${filePath}`);
|
||||||
await shim.fsDriver().mkdir(dir);
|
} else {
|
||||||
this.createdDirs_.push(dir);
|
const destPath = `${dirname(noteFilePath)}/pluginAssets/${asset.name}`;
|
||||||
await shim.fsDriver().copy(filePath, destPath);
|
const dir = dirname(destPath);
|
||||||
|
await shim.fsDriver().mkdir(dir);
|
||||||
|
this.createdDirs_.push(dir);
|
||||||
|
await shim.fsDriver().copy(filePath, destPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullHtml = `
|
const fullHtml = `
|
||||||
|
Loading…
Reference in New Issue
Block a user