Skip to content

Build your personal knowledge base with Trilium Notes

client: Enable syntax highlight for read-only notes

Elian Doran6c4513fb2e43
diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js
index ffab9fcef8..c382dc1897 100644
--- a/src/public/app/widgets/type_widgets/read_only_text.js
+++ b/src/public/app/widgets/type_widgets/read_only_text.js
@@ -90,6 +90,7 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
// we could load just ckeditor-content.css but that causes CSS conflicts when both build CSS and this content CSS is loaded at the same time
// (see https://github.com/zadam/trilium/issues/1590 for example of such conflict)
await libraryLoader.requireLibrary(libraryLoader.CKEDITOR);
+ await libraryLoader.requireLibrary(libraryLoader.HIGHLIGHT_JS);
const blob = await note.getBlob();
@@ -110,6 +111,14 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
renderMathInElement(this.$content[0], {trust: true});
}
+
+ // Enable syntax highlight
+ const codeBlocks = this.$content.find("pre code");
+ for (const codeBlock of codeBlocks) {
+ const text = codeBlock.innerText;
+ const highlightedText = hljs.highlightAuto(text).value;
+ codeBlock.innerHTML = highlightedText;
+ }
}
async refreshIncludedNoteEvent({noteId}) {