fix(highlightjs): integrate with the rest of the application

This commit is contained in:
Elian Doran
2025-05-18 10:05:02 +03:00
parent 5205320d44
commit 51f2b9fc81
4 changed files with 5 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
import library_loader from "./library_loader.js";
import { highlight, highlightAuto } from "@triliumnext/highlightjs";
import mime_types from "./mime_types.js";
import options from "./options.js";
@@ -43,17 +43,13 @@ export async function applySingleBlockSyntaxHighlight($codeBlock: JQuery<HTMLEle
$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);
highlightedText = highlightAuto(text);
} else if (normalizedMimeType) {
const language = mime_types.getHighlightJsNameForMime(normalizedMimeType);
if (language) {
highlightedText = hljs.highlight(text, { language });
highlightedText = highlight(text, { language });
} else {
console.warn(`Unknown mime type: ${normalizedMimeType}.`);
}