Skip to content

Build your personal knowledge base with Trilium Notes

fix(notion): drop the source copy repeated on an image figure

Elian Doran9f8826c4ccb2
diff --git a/packages/trilium-core/src/services/import/notion/converter.spec.ts b/packages/trilium-core/src/services/import/notion/converter.spec.ts
index 0ea7521293..1b9dc4a654 100644
--- a/packages/trilium-core/src/services/import/notion/converter.spec.ts
+++ b/packages/trilium-core/src/services/import/notion/converter.spec.ts
@@ -413,6 +413,16 @@ describe("convertNotionHtml — images", () => {
`<figure class="image"><img src="x.png"></figure>`
);
});
+
+ it("drops the data-notion-image copy of the source the figure carries", () => {
+ // Notion repeats the whole source on the figure, so a data-URI image is stored twice — and for a
+ // bundled file the copy still names the zip path after the importer has rewritten the <img>.
+ const input = `<figure id="386c5eca" class="image" data-notion-image="Page/Screenshot.png"><a href="Page/Screenshot.png"><img src="Page/Screenshot.png"/></a></figure>`;
+ expect(convertNotionHtml(input)).toBe(`<figure class="image"><img src="Page/Screenshot.png"></figure>`);
+
+ const inline = `<figure class="image" data-notion-image="data:image/png;base64,AAAA"><img src="data:image/png;base64,AAAA"></figure>`;
+ expect(convertNotionHtml(inline)).toBe(`<figure class="image"><img src="data:image/png;base64,AAAA"></figure>`);
+ });
});
describe("convertNotionHtml — attachments", () => {
diff --git a/packages/trilium-core/src/services/import/notion/converter.ts b/packages/trilium-core/src/services/import/notion/converter.ts
index a76c299e97..6a3014e4f9 100644
--- a/packages/trilium-core/src/services/import/notion/converter.ts
+++ b/packages/trilium-core/src/services/import/notion/converter.ts
@@ -487,10 +487,11 @@ function stripTableAttributes(table: HTMLElement) {
// #region Images
/**
- * Notion image blocks are `<figure class="image"><a href="…"><img src="…"></a></figure>`, where the
- * `<a>` is a self-link to the file and the `<img>` carries an inline pixel width. Reduce each to Trilium's
- * canonical `<figure class="image"><img src="…"></figure>` (unwrap the link, drop the sizing and the
- * Notion id). The `src` still points at the zip-relative path; the importer rewrites it to an attachment.
+ * Notion image blocks are `<figure class="image" data-notion-image="…"><a href="…"><img src="…"></a></figure>`,
+ * where the `<a>` is a self-link to the file, `data-notion-image` repeats that same source and the `<img>`
+ * carries an inline pixel width. Reduce each to Trilium's canonical `<figure class="image"><img src="…"></figure>`
+ * (unwrap the link, drop the sizing, the Notion id and the repeated source). The `src` still points at the
+ * zip-relative path; the importer rewrites it to an attachment.
*/
function convertImages(root: HTMLElement) {
for (const figure of root.querySelectorAll("figure.image")) {
@@ -500,6 +501,7 @@ function convertImages(root: HTMLElement) {
}
img.removeAttribute("style");
figure.removeAttribute("id");
+ figure.removeAttribute("data-notion-image");
figure.set_content(img.toString());
}
}