From 624bfd91754e30656ffa00310a203397a13b4b6b Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:25:23 -0700 Subject: [PATCH] Desktop: Fixes #10733: Fix not-yet-created images lost while editing with the Rich Text Editor (#10734) --- packages/app-cli/tests/MdToHtml.ts | 9 ++- .../html_to_md/resource_placeholder.html | 48 ++++++++++++++++ .../tests/html_to_md/resource_placeholder.md | 9 +++ .../resource_nonexistent_image.html | 15 +++++ .../md_to_html/resource_nonexistent_image.md | 3 + packages/lib/HtmlToMd.ts | 1 + .../renderer/MdToHtml/rules/html_image.ts | 2 +- packages/renderer/MdToHtml/rules/image.ts | 5 +- packages/renderer/utils.ts | 33 ++++++++++- packages/turndown/src/commonmark-rules.js | 55 +++++++++++++++++-- 10 files changed, 168 insertions(+), 12 deletions(-) create mode 100644 packages/app-cli/tests/html_to_md/resource_placeholder.html create mode 100644 packages/app-cli/tests/html_to_md/resource_placeholder.md create mode 100644 packages/app-cli/tests/md_to_html/resource_nonexistent_image.html create mode 100644 packages/app-cli/tests/md_to_html/resource_nonexistent_image.md diff --git a/packages/app-cli/tests/MdToHtml.ts b/packages/app-cli/tests/MdToHtml.ts index 6cebadf36..a5571bb89 100644 --- a/packages/app-cli/tests/MdToHtml.ts +++ b/packages/app-cli/tests/MdToHtml.ts @@ -2,13 +2,16 @@ import MdToHtml from '@joplin/renderer/MdToHtml'; const { filename } = require('@joplin/lib/path-utils'); import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils'; import shim from '@joplin/lib/shim'; +import { RenderOptions } from '@joplin/renderer/types'; +import { isResourceUrl, resourceUrlToId } from '@joplin/lib/models/utils/resourceUtils'; const { themeStyle } = require('@joplin/lib/theme'); // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied function newTestMdToHtml(options: any = null) { options = { ResourceModel: { - isResourceUrl: () => false, + isResourceUrl: isResourceUrl, + urlToId: resourceUrlToId, }, fsDriver: shim.fsDriver(), ...options, @@ -39,7 +42,7 @@ describe('MdToHtml', () => { // if (mdFilename !== 'sanitize_9.md') continue; // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied - const mdToHtmlOptions: any = { + const mdToHtmlOptions: RenderOptions = { bodyOnly: true, }; @@ -51,6 +54,8 @@ describe('MdToHtml', () => { }; } else if (mdFilename.startsWith('sourcemap_')) { mdToHtmlOptions.mapsToLine = true; + } else if (mdFilename.startsWith('resource_')) { + mdToHtmlOptions.resources = {}; } const markdown = await shim.fsDriver().readFile(mdFilePath); diff --git a/packages/app-cli/tests/html_to_md/resource_placeholder.html b/packages/app-cli/tests/html_to_md/resource_placeholder.html new file mode 100644 index 000000000..188c13e08 --- /dev/null +++ b/packages/app-cli/tests/html_to_md/resource_placeholder.html @@ -0,0 +1,48 @@ +
Markdown images:
+HTML images:
+