Skip to content

Build your personal knowledge base with Trilium Notes

fix(import): render application/inkml+xml attachments as text

Elian Doran8efbce8043c0
diff --git a/packages/trilium-core/src/becca/entities/battachment.spec.ts b/packages/trilium-core/src/becca/entities/battachment.spec.ts
index 675d682ad2..81e0830557 100644
--- a/packages/trilium-core/src/becca/entities/battachment.spec.ts
+++ b/packages/trilium-core/src/becca/entities/battachment.spec.ts
@@ -112,9 +112,12 @@ describe("BAttachment (real DB)", () => {
it("hasStringContent reflects the mime via isStringNote", () => {
const stringAtt = new BAttachment(baseRow({ mime: "text/plain", title: "s" }));
const binaryAtt = new BAttachment(baseRow({ mime: "image/png", role: "image", title: "b" }));
+ // InkML is UTF-8 XML, so it must be served as string content for the attachment preview to work.
+ const inkmlAtt = new BAttachment(baseRow({ mime: "application/inkml+xml", role: "importSource", title: "ink" }));
expect(stringAtt.hasStringContent()).toBe(true);
expect(binaryAtt.hasStringContent()).toBe(false);
+ expect(inkmlAtt.hasStringContent()).toBe(true);
});
it("getFileName uses 'image' for image role and 'file' otherwise", () => {
diff --git a/packages/trilium-core/src/services/utils/index.spec.ts b/packages/trilium-core/src/services/utils/index.spec.ts
index 436c013f5e..8ec68cd03b 100644
--- a/packages/trilium-core/src/services/utils/index.spec.ts
+++ b/packages/trilium-core/src/services/utils/index.spec.ts
@@ -281,6 +281,11 @@ describe("#isStringNote", () => {
"w/ non-string note type (file), but mime type starting with 'text/', it should return true",
[ "file", "text/html" ],
true
+ ],
+ [
+ "w/ 'undefined' note type and the InkML mime type, it should return true",
+ [ undefined, "application/inkml+xml" ],
+ true
]
];
diff --git a/packages/trilium-core/src/services/utils/index.ts b/packages/trilium-core/src/services/utils/index.ts
index b31bce5cb0..5bcdc8325b 100644
--- a/packages/trilium-core/src/services/utils/index.ts
+++ b/packages/trilium-core/src/services/utils/index.ts
@@ -14,7 +14,7 @@ export function isWindows() { return getPlatform().isWindows; }
// render and book are string note in the sense that they are expected to contain empty string
const STRING_NOTE_TYPES = new Set(["text", "code", "relationMap", "search", "render", "book", "mermaid", "canvas", "webView"]);
-const STRING_MIME_TYPES = new Set(["application/javascript", "application/x-javascript", "application/json", "application/x-sql", "image/svg+xml"]);
+const STRING_MIME_TYPES = new Set(["application/javascript", "application/x-javascript", "application/json", "application/x-sql", "image/svg+xml", "application/inkml+xml"]);
export function hash(text: string) {
return encodeBase64(getCrypto().createHash("sha1", text.normalize()));