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 { pathExistsSync } from 'fs-extra';
|
||||
const Entities = require('html-entities').AllHtmlEntities;
|
||||
const htmlparser2 = require('@joplin/fork-htmlparser2');
|
||||
const Datauri = require('datauri/sync');
|
||||
@ -102,6 +103,7 @@ const processLinkTag = (baseDir: string, _name: string, attrs: any): string => {
|
||||
|
||||
const filePath = `${baseDir}/${href}`;
|
||||
|
||||
if (!pathExistsSync(filePath)) return null;
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
return `<style>${processCssContent(dirname(filePath), content)}</style>`;
|
||||
};
|
||||
|
@ -15,6 +15,9 @@ const { escapeHtml } = require('../../string-utils.js');
|
||||
import { assetsToHeaders } from '@joplin/renderer';
|
||||
import getPluginSettingValue from '../plugins/utils/getPluginSettingValue';
|
||||
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 {
|
||||
|
||||
@ -136,12 +139,16 @@ export default class InteropService_Exporter_Html extends InteropService_Exporte
|
||||
for (let i = 0; i < result.pluginAssets.length; i++) {
|
||||
const asset = result.pluginAssets[i];
|
||||
const filePath = asset.pathIsAbsolute ? asset.path : `${libRootPath}/node_modules/@joplin/renderer/assets/${asset.name}`;
|
||||
if (!(await shim.fsDriver().exists(filePath))) {
|
||||
logger.warn(`File does not exist and cannot be exported: ${filePath}`);
|
||||
} else {
|
||||
const destPath = `${dirname(noteFilePath)}/pluginAssets/${asset.name}`;
|
||||
const dir = dirname(destPath);
|
||||
await shim.fsDriver().mkdir(dir);
|
||||
this.createdDirs_.push(dir);
|
||||
await shim.fsDriver().copy(filePath, destPath);
|
||||
}
|
||||
}
|
||||
|
||||
const fullHtml = `
|
||||
<!DOCTYPE html>
|
||||
|
Loading…
Reference in New Issue
Block a user