mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	client: Apply highlighting theme on refresh
This commit is contained in:
		
							parent
							
								
									e1ae014b74
								
							
						
					
					
						commit
						fe4dbae079
					
				| @ -1,4 +1,5 @@ | ||||
| import mimeTypesService from "./mime_types.js"; | ||||
| import optionsService from "./options.js"; | ||||
| 
 | ||||
| const CKEDITOR = {"js": ["libraries/ckeditor/ckeditor.js"]}; | ||||
| 
 | ||||
| @ -96,9 +97,12 @@ const HIGHLIGHT_JS = { | ||||
|                 scriptsToLoad.add(`node_modules/@highlightjs/cdn-assets/languages/${mimeType.highlightJs}.min.js`); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         const currentTheme = optionsService.get("highlightingTheme"); | ||||
|         loadHighlightingTheme(currentTheme); | ||||
| 
 | ||||
|         return Array.from(scriptsToLoad); | ||||
|     }, | ||||
|     css: [ "node_modules/@highlightjs/cdn-assets/styles/atom-one-dark.css" ] | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| async function requireLibrary(library) { | ||||
| @ -152,6 +156,24 @@ async function requireCss(url, prependAssetPath = true) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| let highlightingThemeEl = null; | ||||
| function loadHighlightingTheme(theme) { | ||||
|     if (!highlightingThemeEl) { | ||||
|         highlightingThemeEl = $(`<link rel="stylesheet" type="text/css" />`); | ||||
|         $("head").append(highlightingThemeEl); | ||||
|     } | ||||
|      | ||||
|     let url; | ||||
|     const defaultPrefix = "default:"; | ||||
|     if (theme.startsWith(defaultPrefix)) {         | ||||
|         url = `${window.glob.assetPath}/node_modules/@highlightjs/cdn-assets/styles/${theme.substr(defaultPrefix.length)}.min.css`; | ||||
|     } | ||||
| 
 | ||||
|     if (url) { | ||||
|         highlightingThemeEl.attr("href", url); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| export default { | ||||
|     requireCss, | ||||
|     requireLibrary, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran