Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(share): remove no longer necessary highlight module
Elian Doranea015bc2cf4a
diff --git a/packages/share-theme/src/scripts/index.ts b/packages/share-theme/src/scripts/index.tsindex 6e53929c2d..7b71fcb8fe 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<T extends (...a: unknown[]) => unknown>(func: T, ...args: Parameters<T>) {try {func.apply(func, args);@@ -17,7 +15,6 @@ function $try<T extends (...a: unknown[]) => 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.tsdeleted file mode 100644index 5d59e7708f..0000000000--- 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}<span class="hljs-variable language_">api</span>.`;- });- }-};--// 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}<span class="hljs-variable language_">$(</span>${variable}<span class="hljs-variable language_">)</span>`;- });- }-};---/**- * 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