mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	client: Group color themes by dark/light
This commit is contained in:
		
							parent
							
								
									90dffdc6ed
								
							
						
					
					
						commit
						ae60f8c842
					
				| @ -84,13 +84,17 @@ export default class CodeBlockOptions extends OptionsWidget { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async optionsLoaded(options) { |     async optionsLoaded(options) { | ||||||
|         const themes = await server.get("options/codeblock-themes"); |         const themeGroups = await server.get("options/codeblock-themes"); | ||||||
|         this.$themeSelect.empty(); |         this.$themeSelect.empty(); | ||||||
| 
 | 
 | ||||||
|         for (const theme of themes) { |         for (const [ key, themes ] of Object.entries(themeGroups)) { | ||||||
|             this.$themeSelect.append($("<option>") |             const $group = $("<optgroup>").attr("label", key); | ||||||
|                 .attr("value", theme.val) |             for (const theme of themes) { | ||||||
|                 .text(theme.title)); |                 $group.append($("<option>") | ||||||
|  |                     .attr("value", theme.val) | ||||||
|  |                     .text(theme.title)); | ||||||
|  |             } | ||||||
|  |             this.$themeSelect.append($group); | ||||||
|         } |         } | ||||||
|         this.$themeSelect.val(options.codeBlockTheme); |         this.$themeSelect.val(options.codeBlockTheme); | ||||||
|         this.setCheckboxState(this.$wordWrap, options.codeBlockWordWrap); |         this.setCheckboxState(this.$wordWrap, options.codeBlockWordWrap); | ||||||
|  | |||||||
| @ -2,10 +2,27 @@ import fs from "fs"; | |||||||
| import themeNames from "./code_block_theme_names.json" assert { type: "json" } | import themeNames from "./code_block_theme_names.json" assert { type: "json" } | ||||||
| import { t } from "i18next"; | import { t } from "i18next"; | ||||||
| 
 | 
 | ||||||
|  | interface ColorTheme { | ||||||
|  |     val: string; | ||||||
|  |     title: string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export function listSyntaxHighlightingThemes() { | export function listSyntaxHighlightingThemes() { | ||||||
|     const path = "node_modules/@highlightjs/cdn-assets/styles"; |     const path = "node_modules/@highlightjs/cdn-assets/styles"; | ||||||
|     const systemThemes = fs |     const systemThemes = readThemesFromFileSystem(path); | ||||||
|         .readdirSync(path) |     const allThemes = [ | ||||||
|  |         { | ||||||
|  |             val: "none", | ||||||
|  |             title: t("code_block.theme_none") | ||||||
|  |         }, | ||||||
|  |         ...systemThemes | ||||||
|  |     ]; | ||||||
|  | 
 | ||||||
|  |     return groupThemesByLightOrDark(allThemes); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function readThemesFromFileSystem(path: string): ColorTheme[] { | ||||||
|  |     return fs.readdirSync(path) | ||||||
|         .filter((el) => el.endsWith(".min.css")) |         .filter((el) => el.endsWith(".min.css")) | ||||||
|         .map((name) => { |         .map((name) => { | ||||||
|             const nameWithoutExtension = name.replace(".min.css", "");             |             const nameWithoutExtension = name.replace(".min.css", "");             | ||||||
| @ -20,11 +37,21 @@ export function listSyntaxHighlightingThemes() { | |||||||
|                 title: title |                 title: title | ||||||
|             }; |             }; | ||||||
|         }); |         }); | ||||||
|     return [ | } | ||||||
|         { | 
 | ||||||
|             val: "none", | function groupThemesByLightOrDark(listOfThemes: ColorTheme[]) { | ||||||
|             title: t("code_block.theme_none") |     const result: Record<string, ColorTheme[]> = { | ||||||
|         }, |         light: [], | ||||||
|         ...systemThemes |         dark: [] | ||||||
|     ]; |     }; | ||||||
|  | 
 | ||||||
|  |     for (const theme of listOfThemes) { | ||||||
|  |         if (theme.title.includes("Dark")) { | ||||||
|  |             result.dark.push(theme); | ||||||
|  |         } else { | ||||||
|  |             result.light.push(theme); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return result; | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran