From ea015bc2cf4a8881b3b693dccf7aca27d1e2ed9f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 9 Jun 2025 19:55:21 +0300 Subject: [PATCH] refactor(share): remove no longer necessary highlight module --- packages/share-theme/src/scripts/index.ts | 3 - .../src/scripts/modules/highlight.ts | 66 ------------------- 2 files changed, 69 deletions(-) delete mode 100644 packages/share-theme/src/scripts/modules/highlight.ts diff --git a/packages/share-theme/src/scripts/index.ts b/packages/share-theme/src/scripts/index.ts index 6e53929c2..7b71fcb8f 100644 --- a/packages/share-theme/src/scripts/index.ts +++ b/packages/share-theme/src/scripts/index.ts @@ -1,11 +1,9 @@ -import highlight from "./modules/highlight"; import setupToC from "./modules/toc"; import setupExpanders from "./modules/expanders"; import setupMobileMenu from "./modules/mobile"; import setupSearch from "./modules/search"; import setupThemeSelector from "./modules/theme"; - function $try unknown>(func: T, ...args: Parameters) { try { func.apply(func, args); @@ -17,7 +15,6 @@ function $try unknown>(func: T, ...args: Paramete $try(setupThemeSelector); $try(setupToC); -$try(highlight); $try(setupExpanders); $try(setupMobileMenu); $try(setupSearch); diff --git a/packages/share-theme/src/scripts/modules/highlight.ts b/packages/share-theme/src/scripts/modules/highlight.ts deleted file mode 100644 index 5d59e7708..000000000 --- a/packages/share-theme/src/scripts/modules/highlight.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {HLJSApi, HLJSPlugin} from "highlight.js"; - - -declare const hljs: HLJSApi; - - -// Custom highlight.js plugin to highlight the `api` globals for Trilium -const highlightTriliumApi: HLJSPlugin = { - "after:highlight": (result) => { - result.value = result.value.replaceAll(/([^A-Za-z0-9])api\./g, function(match, prefix) { - return `${prefix}api.`; - }); - } -}; - -// Custom highlight.js plugin to highlight JQuery function usage -const highlightJQuery: HLJSPlugin = { - "after:highlight": (result) => { - result.value = result.value.replaceAll(/([^A-Za-z0-9.])\$\((.+)\)/g, function(match, prefix, variable) { - return `${prefix}$(${variable})`; - }); - } -}; - - -/** - * Let's highlight some codeblocks! - */ -export default function addHljs() { - const codeblocks = document.querySelectorAll(`.ck-content pre`); - if (!codeblocks.length) return; // If there are none, don't add dependency - - // Add the hightlight.js styles from the child note of this script - const link = document.createElement("link"); - link.rel = "stylesheet"; - link.href = "api/notes/cVaK9ZJwx5Hs/download"; - document.head.append(link); - - // Add the highlight.js script too - const script = document.createElement("script"); - script.src = "api/notes/6PVElIem02b5/download"; - script.addEventListener("load", () => { - // hljs.configure({languageDetectRe: /\blanguage-text-x-([\w-]+)\b/i}); - - const allLanguages = hljs.listLanguages().map(l => { - const definition = hljs.getLanguage(l); - if (definition?.aliases) return [l, ...definition.aliases]; - return [l]; - }); - for (const langs of allLanguages) { - const lang = langs[0]; - for (const l of langs) { - hljs.registerAliases(`text-x-${l}`, {languageName: lang}); - } - } - - // This registers the JS Frontend and JS Backend types as javascript aliases for highlighting purposes - hljs.registerAliases(["application-javascript-env-frontend", "application-javascript-env-backend"], {languageName: "javascript"}); - - // Add our custom plugins and highlight all on page - hljs.addPlugin(highlightTriliumApi); - hljs.addPlugin(highlightJQuery); - hljs.highlightAll(); - }); - document.head.append(script); -} \ No newline at end of file