From 7f01032b6d93a80237ca477e3a661c5adde0757b Mon Sep 17 00:00:00 2001 From: Tom <7283497+thfrei@users.noreply.github.com> Date: Sun, 10 Apr 2022 16:04:13 +0200 Subject: [PATCH] add support for render excalidraw in book view (copy of note_revision) maybe one should think about extract a function there and make it reusable --- .../app/services/note_content_renderer.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/public/app/services/note_content_renderer.js b/src/public/app/services/note_content_renderer.js index f7c970f1b..93bd0d267 100644 --- a/src/public/app/services/note_content_renderer.js +++ b/src/public/app/services/note_content_renderer.js @@ -141,6 +141,33 @@ async function getRenderedContent(note, options = {}) { $renderedContent.append($content); } + else if (type === 'canvas-note') { + await libraryLoader.requireLibrary(libraryLoader.EXCALIDRAW_UTILS); + const {exportToSvg} = window.ExcalidrawUtils + + const noteComplement = await froca.getNoteComplement(note.noteId); + const content = noteComplement.content || ""; + + console.log("canvas-note book", note, noteComplement, content); + + try { + const data = JSON.parse(content) + const excData = { + type: "excalidraw", + version: 2, + source: "trilium", + elements: data.elements, + appState: data.appState, + files: data.files, + } + const svg = await exportToSvg(excData); + console.log("canvas-note content book", data, svg); + $renderedContent.append($('
').html(svg)); + } catch(err) { + console.error("error parsing fullNoteRevision.content as JSON", content, err); + $renderedContent.append($("
").text("Error parsing content. Please check console.error() for more details.")); + } + } else if (!options.tooltip && type === 'protected-session') { const $button = $(``) .on('click', protectedSessionService.enterProtectedSession);