mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	refactor(highlightjs): get rid of highlight.js in library loader
This commit is contained in:
		
							parent
							
								
									b998dee476
								
							
						
					
					
						commit
						f6728ca931
					
				@ -1,7 +1,3 @@
 | 
				
			|||||||
import mimeTypesService from "./mime_types.js";
 | 
					 | 
				
			||||||
import optionsService from "./options.js";
 | 
					 | 
				
			||||||
import { getStylesheetUrl } from "./syntax_highlight.js";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export interface Library {
 | 
					export interface Library {
 | 
				
			||||||
    js?: string[] | (() => string[]);
 | 
					    js?: string[] | (() => string[]);
 | 
				
			||||||
    css?: string[];
 | 
					    css?: string[];
 | 
				
			||||||
@ -12,29 +8,6 @@ const KATEX: Library = {
 | 
				
			|||||||
    css: ["node_modules/katex/dist/katex.min.css"]
 | 
					    css: ["node_modules/katex/dist/katex.min.css"]
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const HIGHLIGHT_JS: Library = {
 | 
					 | 
				
			||||||
    js: () => {
 | 
					 | 
				
			||||||
        const mimeTypes = mimeTypesService.getMimeTypes();
 | 
					 | 
				
			||||||
        const scriptsToLoad = new Set<string>();
 | 
					 | 
				
			||||||
        scriptsToLoad.add("node_modules/@highlightjs/cdn-assets/highlight.min.js");
 | 
					 | 
				
			||||||
        for (const mimeType of mimeTypes) {
 | 
					 | 
				
			||||||
            const id = mimeType.highlightJs;
 | 
					 | 
				
			||||||
            if (!mimeType.enabled || !id) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (mimeType.highlightJsSource === "libraries") {
 | 
					 | 
				
			||||||
                scriptsToLoad.add(`libraries/highlightjs/${id}.js`);
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                // Built-in module.
 | 
					 | 
				
			||||||
                scriptsToLoad.add(`node_modules/@highlightjs/cdn-assets/languages/${id}.min.js`);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return Array.from(scriptsToLoad);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
async function requireLibrary(library: Library) {
 | 
					async function requireLibrary(library: Library) {
 | 
				
			||||||
    if (library.css) {
 | 
					    if (library.css) {
 | 
				
			||||||
        library.css.map((cssUrl) => requireCss(cssUrl));
 | 
					        library.css.map((cssUrl) => requireCss(cssUrl));
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user