Skip to content

Build your personal knowledge base with Trilium Notes

feat(mermaid): save SVG attachment only when needed

Elian Doran3bbb2c3e80d6
diff --git a/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts
index 50df1a09e7..b0a4cd69dd 100644
--- a/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts
+++ b/src/public/app/widgets/type_widgets/abstract_svg_split_type_widget.ts
@@ -50,11 +50,20 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
const blob = await note?.getBlob();
const content = blob?.content || "";
this.onContentChanged(content, true);
+
+ // Save the SVG when entering a note only when it does not have an attachment.
+ this.note?.getAttachments().then((attachments) => {
+ const attachmentName = `${this.attachmentName}.svg`;
+ if (!attachments.find((a) => a.title === attachmentName)) {
+ this.#saveSvg();
+ }
+ });
}
getData(): { content: string; } {
const data = super.getData();
this.onContentChanged(data.content, false);
+ this.#saveSvg();
return data;
}
@@ -89,7 +98,6 @@ export default abstract class AbstractSvgSplitTypeWidget extends AbstractSplitTy
this.$renderContainer.html(svg);
await this.#setupPanZoom(!recenter);
- this.#saveSvg();
}
#saveSvg() {