Skip to content

Build your personal knowledge base with Trilium Notes

show mermaid errors, fixes #3610

zadam896a4fe98184
diff --git a/src/public/app/widgets/mermaid.js b/src/public/app/widgets/mermaid.js
index ad8e94eb8a..35c61f13c2 100644
--- a/src/public/app/widgets/mermaid.js
+++ b/src/public/app/widgets/mermaid.js
@@ -73,36 +73,37 @@ export default class MermaidWidget extends NoteContextAwareWidget {
const wheelZoomLoaded = libraryLoader.requireLibrary(libraryLoader.WHEEL_ZOOM);
try {
- const renderedSvg = await this.renderSvg();
- this.$display.html(renderedSvg);
+ await this.renderSvg(async renderedSvg => {
+ this.$display.html(renderedSvg);
- await wheelZoomLoaded;
+ await wheelZoomLoaded;
- this.$display.attr("id", `mermaid-render-${idCounter}`);
+ this.$display.attr("id", `mermaid-render-${idCounter}`);
- WZoom.create(`#mermaid-render-${idCounter}`, {
- type: 'html',
- maxScale: 10,
- speed: 20,
- zoomOnClick: false
- });
+ WZoom.create(`#mermaid-render-${idCounter}`, {
+ type: 'html',
+ maxScale: 10,
+ speed: 20,
+ zoomOnClick: false
+ });
- this.$errorContainer.hide();
+ this.$errorContainer.hide();
+ });
} catch (e) {
this.$errorMessage.text(e.message);
this.$errorContainer.show();
}
}
- renderSvg() {
- return new Promise(async res => {
- idCounter++;
+ async renderSvg(cb) {
+ idCounter++;
- const noteComplement = await froca.getNoteComplement(this.noteId);
- const content = noteComplement.content || "";
+ const noteComplement = await froca.getNoteComplement(this.noteId);
+ const content = noteComplement.content || "";
- mermaid.mermaidAPI.render(`mermaid-graph-${idCounter}`, content, res);
- });
+ // this can't be promisified since in case of error this both calls callback with error SVG and throws exception
+ // with error details
+ mermaid.mermaidAPI.render(`mermaid-graph-${idCounter}`, content, cb);
}
async entitiesReloadedEvent({loadResults}) {
@@ -116,9 +117,9 @@ export default class MermaidWidget extends NoteContextAwareWidget {
return;
}
- const renderedSvg = await this.renderSvg();
-
- this.download(`${this.note.title}.svg`, renderedSvg);
+ await this.renderSvg(renderedSvg => {
+ this.download(`${this.note.title}.svg`, renderedSvg);
+ });
}
download(filename, text) {