diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index 864e3593e..448d88959 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -16,7 +16,7 @@ const NOTE_TYPE_ICONS = { "relation-map": "bx bx-map-alt", "book": "bx bx-book", "note-map": "bx bx-map-alt", - "mermaid": "bx bx-water" + "mermaid": "bx bx-selection" }; /** diff --git a/src/public/app/services/note_content_renderer.js b/src/public/app/services/note_content_renderer.js index b0e5ae0e9..8852cdec7 100644 --- a/src/public/app/services/note_content_renderer.js +++ b/src/public/app/services/note_content_renderer.js @@ -86,14 +86,15 @@ async function getRenderedContent(note, options = {}) { await libraryLoader.requireLibrary(libraryLoader.MERMAID); const noteComplement = await froca.getNoteComplement(note.noteId); - const graph = noteComplement.content || ""; + const content = noteComplement.content || ""; - const updateWithContent = (content) => { - $renderedContent.append($(content)) - } + $renderedContent + .css("display", "flex") + .css("justify-content", "space-around"); try { - mermaid.mermaidAPI.render('graphDiv', graph, updateWithContent); + mermaid.mermaidAPI.render("mermaid-graph", content, + content => $renderedContent.append($(content))); } catch (e) { const $error = $("
The diagram could not displayed.
"); diff --git a/src/public/app/services/note_create.js b/src/public/app/services/note_create.js index 778cf237d..c166c9bdc 100644 --- a/src/public/app/services/note_create.js +++ b/src/public/app/services/note_create.js @@ -32,6 +32,16 @@ async function createNote(parentNotePath, options = {}) { const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath); + console.log(options); + + if (options.type === 'mermaid' && !options.content) { + options.content = `graph TD; + A-->B; + A-->C; + B-->D; + C-->D;` + } + const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${options.target}&targetBranchId=${options.targetBranchId}`, { title: newNoteName, content: options.content || "", diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index 871d9c91e..f22de134b 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -33,7 +33,7 @@ class TreeContextMenu { { title: "Note Map", command: command, type: "note-map", uiIcon: "map-alt" }, { title: "Render HTML note", command: command, type: "render", uiIcon: "extension" }, { title: "Book", command: command, type: "book", uiIcon: "book" }, - { title: "Mermaid diagram", command: command, type: "mermaid", uiIcon: "water" } + { title: "Mermaid diagram", command: command, type: "mermaid", uiIcon: "selection" } ]; } diff --git a/src/public/app/widgets/mermaid.js b/src/public/app/widgets/mermaid.js index 758406a21..fa26149bd 100644 --- a/src/public/app/widgets/mermaid.js +++ b/src/public/app/widgets/mermaid.js @@ -63,7 +63,7 @@ export default class MermaidWidget extends NoteContextAwareWidget { this.$errorContainer.hide(); } catch (e) { - this.$errorMessage.text(e.message); + this.$errorMessage.text(e.message).append(`See help and examples.
`); this.$errorContainer.show(); } } diff --git a/src/services/notes.js b/src/services/notes.js index 72ba8f380..93ca383b1 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -50,7 +50,7 @@ function deriveMime(type, mime) { if (type === 'text') { mime = 'text/html'; - } else if (type === 'code') { + } else if (type === 'code' || type === 'mermaid') { mime = 'text/plain'; } else if (['relation-map', 'search'].includes(type)) { mime = 'application/json'; @@ -115,6 +115,8 @@ function createNewNote(params) { mime: deriveMime(params.type, params.mime) }).save(); + console.log(params); + note.setContent(params.content); const branch = new Branch({ diff --git a/src/services/utils.js b/src/services/utils.js index 0b923ff2c..2bcdc44e1 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -168,7 +168,7 @@ const STRING_MIME_TYPES = [ function isStringNote(type, mime) { // render and book are string note in the sense that they are expected to contain empty string - return ["text", "code", "relation-map", "search", "render", "book"].includes(type) + return ["text", "code", "relation-map", "search", "render", "book", "mermaid"].includes(type) || mime.startsWith('text/') || STRING_MIME_TYPES.includes(mime); }