mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
show mermaid errors, fixes #3610
This commit is contained in:
parent
e9a2cacb5b
commit
896a4fe981
@ -73,36 +73,37 @@ export default class MermaidWidget extends NoteContextAwareWidget {
|
|||||||
const wheelZoomLoaded = libraryLoader.requireLibrary(libraryLoader.WHEEL_ZOOM);
|
const wheelZoomLoaded = libraryLoader.requireLibrary(libraryLoader.WHEEL_ZOOM);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const renderedSvg = await this.renderSvg();
|
await this.renderSvg(async renderedSvg => {
|
||||||
this.$display.html(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}`, {
|
WZoom.create(`#mermaid-render-${idCounter}`, {
|
||||||
type: 'html',
|
type: 'html',
|
||||||
maxScale: 10,
|
maxScale: 10,
|
||||||
speed: 20,
|
speed: 20,
|
||||||
zoomOnClick: false
|
zoomOnClick: false
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$errorContainer.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$errorContainer.hide();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.$errorMessage.text(e.message);
|
this.$errorMessage.text(e.message);
|
||||||
this.$errorContainer.show();
|
this.$errorContainer.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSvg() {
|
async renderSvg(cb) {
|
||||||
return new Promise(async res => {
|
idCounter++;
|
||||||
idCounter++;
|
|
||||||
|
|
||||||
const noteComplement = await froca.getNoteComplement(this.noteId);
|
const noteComplement = await froca.getNoteComplement(this.noteId);
|
||||||
const content = noteComplement.content || "";
|
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}) {
|
async entitiesReloadedEvent({loadResults}) {
|
||||||
@ -116,9 +117,9 @@ export default class MermaidWidget extends NoteContextAwareWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderedSvg = await this.renderSvg();
|
await this.renderSvg(renderedSvg => {
|
||||||
|
this.download(`${this.note.title}.svg`, renderedSvg);
|
||||||
this.download(`${this.note.title}.svg`, renderedSvg);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
download(filename, text) {
|
download(filename, text) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user