From 29e83b97e68459f8b86d9eedde2ba306aefc2fd5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 8 Nov 2024 21:50:22 +0200 Subject: [PATCH] client: Fix rendering notes if hljs is not loaded --- src/public/app/services/note_list_renderer.js | 3 ++- src/public/app/services/syntax_highlight.js | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.js index fb6e2981b..bc986e56b 100644 --- a/src/public/app/services/note_list_renderer.js +++ b/src/public/app/services/note_list_renderer.js @@ -371,7 +371,8 @@ class NoteListRenderer { $content.append($renderedContent); $content.addClass(`type-${type}`); } catch (e) { - console.log(`Caught error while rendering note '${note.noteId}' of type '${note.type}': ${e.message}, stack: ${e.stack}`); + console.warn(`Caught error while rendering note '${note.noteId}' of type '${note.type}'`); + console.error(e); $content.append("rendering error"); } diff --git a/src/public/app/services/syntax_highlight.js b/src/public/app/services/syntax_highlight.js index 45d87cd95..1cb76c426 100644 --- a/src/public/app/services/syntax_highlight.js +++ b/src/public/app/services/syntax_highlight.js @@ -23,9 +23,7 @@ export function getStylesheetUrl(theme) { export async function applySyntaxHighlight($container) { if (!isSyntaxHighlightEnabled()) { return; - } - - await library_loader.requireLibrary(library_loader.HIGHLIGHT_JS); + } const codeBlocks = $container.find("pre code"); for (const codeBlock of codeBlocks) { @@ -48,6 +46,10 @@ export async function applySingleBlockSyntaxHighlight($codeBlock, normalizedMime $codeBlock.parent().toggleClass("hljs"); const text = $codeBlock.text(); + if (!window.hljs) { + await library_loader.requireLibrary(library_loader.HIGHLIGHT_JS); + } + let highlightedText = null; if (normalizedMimeType === mime_types.MIME_TYPE_AUTO) { highlightedText = hljs.highlightAuto(text);