1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-17 18:44:45 +02:00

Desktop: Fixes #9607: Copied and pasted text from Firefox to RTE does not include images

This commit is contained in:
Laurent Cozic 2024-02-08 13:06:18 +00:00
parent b1877fcd0d
commit 11e1a49b5c

View File

@ -12,6 +12,7 @@ import { fileUriToPath } from '@joplin/utils/url';
import { MarkupLanguage } from '@joplin/renderer'; import { MarkupLanguage } from '@joplin/renderer';
import { HtmlToMarkdownHandler, MarkupToHtmlHandler } from './types'; import { HtmlToMarkdownHandler, MarkupToHtmlHandler } from './types';
import markupRenderOptions from './markupRenderOptions'; import markupRenderOptions from './markupRenderOptions';
import { fileExtension, filename, safeFileExtension, safeFilename } from '@joplin/utils/path';
const joplinRendererUtils = require('@joplin/renderer').utils; const joplinRendererUtils = require('@joplin/renderer').utils;
const { clipboard } = require('electron'); const { clipboard } = require('electron');
const mimeUtils = require('@joplin/lib/mime-utils.js').mime; const mimeUtils = require('@joplin/lib/mime-utils.js').mime;
@ -154,7 +155,11 @@ export async function processPastedHtml(html: string, htmlToMd: HtmlToMarkdownHa
const downloadImage = async (imageSrc: string) => { const downloadImage = async (imageSrc: string) => {
try { try {
const filePath = `${Setting.value('tempDir')}/${md5(Date.now() + Math.random())}`; const fileExt = safeFileExtension(fileExtension(imageSrc));
const name = safeFilename(filename(imageSrc));
const pieces = [name ? name : md5(Date.now() + Math.random())];
if (fileExt) pieces.push(fileExt);
const filePath = `${Setting.value('tempDir')}/${pieces.join('.')}`;
await shim.fetchBlob(imageSrc, { path: filePath }); await shim.fetchBlob(imageSrc, { path: filePath });
const createdResource = await shim.createResourceFromPath(filePath); const createdResource = await shim.createResourceFromPath(filePath);
await shim.fsDriver().remove(filePath); await shim.fsDriver().remove(filePath);