chore(highlightjs): introduce client-level list of themes

This commit is contained in:
Elian Doran
2025-05-18 17:12:45 +03:00
parent 488761d4b9
commit 8b11f25f0c
9 changed files with 108 additions and 117 deletions

View File

@@ -1,8 +1,11 @@
import hljs from "../node_modules/highlight.js/es/core.js";
import { normalizeMimeTypeForCKEditor, type MimeType } from "@triliumnext/commons";
import definitions from "./syntax_highlighting.js";
import syntaxDefinitions from "./syntax_highlighting.js";
import { type Theme } from "./themes.js";
import { type HighlightOptions } from "highlight.js";
export { default as Themes } from "./themes.js";
const registeredMimeTypes = new Set<string>();
const unsupportedMimeTypes = new Set<string>();
@@ -18,7 +21,7 @@ export async function ensureMimeTypes(mimeTypes: MimeType[]) {
}
registeredMimeTypes.add(mime);
const loader = definitions[mime];
const loader = syntaxDefinitions[mime];
if (!loader) {
unsupportedMimeTypes.add(mime);
continue;
@@ -42,4 +45,8 @@ export function highlight(code: string, options: HighlightOptions) {
return hljs.highlight(code, options);
}
export async function loadTheme(theme: Theme) {
console.log("Got", theme.default);
}
export const { highlightAuto } = hljs;

View File

@@ -0,0 +1,85 @@
export type Theme = { default: typeof import("*.css", { with: { "resolution-mode": "import" } }); };
const themeDefinitions: Record<string, () => Promise<Theme>> = {
"a11y (Dark)": () => import("../node_modules/highlight.js/styles/a11y-dark.css?raw"),
"a11y (Light)": () => import("../node_modules/highlight.js/styles/a11y-light.css?raw"),
"Agate (Dark)": () => import("../node_modules/highlight.js/styles/agate.css?raw"),
"An Old Hope (Dark)": () => import("../node_modules/highlight.js/styles/an-old-hope.css?raw"),
"Android Studio (Dark)": () => import("../node_modules/highlight.js/styles/androidstudio.css?raw"),
"Arduino (Light)": () => import("../node_modules/highlight.js/styles/arduino-light.css?raw"),
"Arta (Dark)": () => import("../node_modules/highlight.js/styles/arta.css?raw"),
"Ascetic (Light)": () => import("../node_modules/highlight.js/styles/ascetic.css?raw"),
"Atom One with ReasonML support (Dark)": () => import("../node_modules/highlight.js/styles/atom-one-dark-reasonable.css?raw"),
"Atom One (Dark)": () => import("../node_modules/highlight.js/styles/atom-one-dark.css?raw"),
"Atom One (Light)": () => import("../node_modules/highlight.js/styles/atom-one-light.css?raw"),
"Brown Paper (Light)": () => import("../node_modules/highlight.js/styles/brown-paper.css?raw"),
"CodePen Embed (Dark)": () => import("../node_modules/highlight.js/styles/codepen-embed.css?raw"),
"Color Brewer (Light)": () => import("../node_modules/highlight.js/styles/color-brewer.css?raw"),
"Cybertopia Cherry (Dark)": () => import("../node_modules/highlight.js/styles/cybertopia-cherry.css?raw"),
"Cybertopia Dimmer (Dark)": () => import("../node_modules/highlight.js/styles/cybertopia-dimmer.css?raw"),
"Cybertopia Icecap (Dark)": () => import("../node_modules/highlight.js/styles/cybertopia-icecap.css?raw"),
"Cybertopia Saturated (Dark)": () => import("../node_modules/highlight.js/styles/cybertopia-saturated.css?raw"),
"Dark": () => import("../node_modules/highlight.js/styles/dark.css?raw"),
"Original highlight.js Theme (Light)": () => import("../node_modules/highlight.js/styles/default.css?raw"),
"devibeans (Dark)": () => import("../node_modules/highlight.js/styles/devibeans.css?raw"),
"Docco (Light)": () => import("../node_modules/highlight.js/styles/docco.css?raw"),
"FAR (Dark)": () => import("../node_modules/highlight.js/styles/far.css?raw"),
"FelipeC (Dark)": () => import("../node_modules/highlight.js/styles/felipec.css?raw"),
"Foundation 4 Docs (Light)": () => import("../node_modules/highlight.js/styles/foundation.css?raw"),
"GitHub Dimmed (Dark)": () => import("../node_modules/highlight.js/styles/github-dark-dimmed.css?raw"),
"GitHub (Dark)": () => import("../node_modules/highlight.js/styles/github-dark.css?raw"),
"GitHub (Light)": () => import("../node_modules/highlight.js/styles/github.css?raw"),
"GML (Dark)": () => import("../node_modules/highlight.js/styles/gml.css?raw"),
"Google Code (Light)": () => import("../node_modules/highlight.js/styles/googlecode.css?raw"),
"Gradient (Dark)": () => import("../node_modules/highlight.js/styles/gradient-dark.css?raw"),
"Gradient (Light)": () => import("../node_modules/highlight.js/styles/gradient-light.css?raw"),
"Grayscale (Light)": () => import("../node_modules/highlight.js/styles/grayscale.css?raw"),
"hybrid (Dark)": () => import("../node_modules/highlight.js/styles/hybrid.css?raw"),
"Idea (Light)": () => import("../node_modules/highlight.js/styles/idea.css?raw"),
"IntelliJ (Light)": () => import("../node_modules/highlight.js/styles/intellij-light.css?raw"),
"IR Black (Dark)": () => import("../node_modules/highlight.js/styles/ir-black.css?raw"),
"ISBL Editor (Dark)": () => import("../node_modules/highlight.js/styles/isbl-editor-dark.css?raw"),
"ISBL Editor (Light)": () => import("../node_modules/highlight.js/styles/isbl-editor-light.css?raw"),
"Kimbie (Dark)": () => import("../node_modules/highlight.js/styles/kimbie-dark.css?raw"),
"Kimbie (Light)": () => import("../node_modules/highlight.js/styles/kimbie-light.css?raw"),
"Lightfair (Light)": () => import("../node_modules/highlight.js/styles/lightfair.css?raw"),
"Lioshi (Dark)": () => import("../node_modules/highlight.js/styles/lioshi.css?raw"),
"Magula (Light)": () => import("../node_modules/highlight.js/styles/magula.css?raw"),
"Mono Blue (Light)": () => import("../node_modules/highlight.js/styles/mono-blue.css?raw"),
"Monokai Sublime (Dark)": () => import("../node_modules/highlight.js/styles/monokai-sublime.css?raw"),
"Monokai (Dark)": () => import("../node_modules/highlight.js/styles/monokai.css?raw"),
"Night Owl (Dark)": () => import("../node_modules/highlight.js/styles/night-owl.css?raw"),
"NNFX (Dark)": () => import("../node_modules/highlight.js/styles/nnfx-dark.css?raw"),
"NNFX (Light)": () => import("../node_modules/highlight.js/styles/nnfx-light.css?raw"),
"Nord (Dark)": () => import("../node_modules/highlight.js/styles/nord.css?raw"),
"Obsidian (Dark)": () => import("../node_modules/highlight.js/styles/obsidian.css?raw"),
"Panda (Dark)": () => import("../node_modules/highlight.js/styles/panda-syntax-dark.css?raw"),
"Panda (Light)": () => import("../node_modules/highlight.js/styles/panda-syntax-light.css?raw"),
"Paraiso (Dark)": () => import("../node_modules/highlight.js/styles/paraiso-dark.css?raw"),
"Paraiso (Light)": () => import("../node_modules/highlight.js/styles/paraiso-light.css?raw"),
"Pojoaque (Dark)": () => import("../node_modules/highlight.js/styles/pojoaque.css?raw"),
"PureBasic (Light)": () => import("../node_modules/highlight.js/styles/purebasic.css?raw"),
"Qt Creator (Dark)": () => import("../node_modules/highlight.js/styles/qtcreator-dark.css?raw"),
"Qt Creator (Light)": () => import("../node_modules/highlight.js/styles/qtcreator-light.css?raw"),
"Rainbow (Dark)": () => import("../node_modules/highlight.js/styles/rainbow.css?raw"),
"RouterOS Script (Light)": () => import("../node_modules/highlight.js/styles/routeros.css?raw"),
"Rose Pine Dawn (Light)": () => import("../node_modules/highlight.js/styles/rose-pine-dawn.css?raw"),
"Rose Pine Moon (Dark)": () => import("../node_modules/highlight.js/styles/rose-pine-moon.css?raw"),
"Rose Pine (Dark)": () => import("../node_modules/highlight.js/styles/rose-pine.css?raw"),
"School Book (Light)": () => import("../node_modules/highlight.js/styles/school-book.css?raw"),
"Shades of Purple (Dark)": () => import("../node_modules/highlight.js/styles/shades-of-purple.css?raw"),
"Srcery (Dark)": () => import("../node_modules/highlight.js/styles/srcery.css?raw"),
"Stack Overflow (Dark)": () => import("../node_modules/highlight.js/styles/stackoverflow-dark.css?raw"),
"Stack Overflow (Light)": () => import("../node_modules/highlight.js/styles/stackoverflow-light.css?raw"),
"Sunburst (Dark)": () => import("../node_modules/highlight.js/styles/sunburst.css?raw"),
"Tokyo Night (Dark)": () => import("../node_modules/highlight.js/styles/tokyo-night-dark.css?raw"),
"Tokyo Night (Light)": () => import("../node_modules/highlight.js/styles/tokyo-night-light.css?raw"),
"Tomorrow Night Blue (Dark)": () => import("../node_modules/highlight.js/styles/tomorrow-night-blue.css?raw"),
"Tomorrow Night Bright (Dark)": () => import("../node_modules/highlight.js/styles/tomorrow-night-bright.css?raw"),
"Visual Studio (Light)": () => import("../node_modules/highlight.js/styles/vs.css?raw"),
"Visual Studio 2015 (Dark)": () => import("../node_modules/highlight.js/styles/vs2015.css?raw"),
"Xcode (Light)": () => import("../node_modules/highlight.js/styles/xcode.css?raw"),
"xt256 (Dark)": () => import("../node_modules/highlight.js/styles/xt256.css?raw")
}
export default themeDefinitions;