From 66cbe468f5983930f11dc1dcd229a35fc69c4225 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 18 May 2025 17:50:31 +0300 Subject: [PATCH] chore(highlightjs): load theme by IDs --- apps/client/src/services/syntax_highlight.ts | 15 +- .../options/text_notes/code_block.ts | 14 +- apps/client/webpack.config.cjs | 12 + packages/highlightjs/src/index.ts | 5 +- packages/highlightjs/src/themes.ts | 406 ++++++++++++++---- 5 files changed, 356 insertions(+), 96 deletions(-) diff --git a/apps/client/src/services/syntax_highlight.ts b/apps/client/src/services/syntax_highlight.ts index 39eb3e71f..b6b4dc263 100644 --- a/apps/client/src/services/syntax_highlight.ts +++ b/apps/client/src/services/syntax_highlight.ts @@ -1,4 +1,4 @@ -import { ensureMimeTypes, highlight, highlightAuto, loadTheme } from "@triliumnext/highlightjs"; +import { ensureMimeTypes, highlight, highlightAuto, loadTheme, Themes } from "@triliumnext/highlightjs"; import mime_types from "./mime_types.js"; import options from "./options.js"; @@ -58,8 +58,17 @@ export async function applySingleBlockSyntaxHighlight($codeBlock: JQuery `; -// TODO: Deduplicate -interface Theme { - title: string; - val: string; -} - -type Response = Record; - /** * Contains appearance settings for code blocks within text notes, such as the theme for the syntax highlighter. */ @@ -78,10 +70,10 @@ export default class CodeBlockOptions extends OptionsWidget { this.$widget = $(TPL); this.$themeSelect = this.$widget.find(".theme-select"); // Populate the list of themes. - for (const name of Object.keys(Themes)) { + for (const [ id, theme ] of Object.entries(Themes)) { const option = $("