mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	client: Set up simple preview for syntax highlight
This commit is contained in:
		
							parent
							
								
									2fdff29067
								
							
						
					
					
						commit
						83f5b47c99
					
				| @ -2,6 +2,15 @@ import library_loader from "../../../../services/library_loader.js"; | |||||||
| import server from "../../../../services/server.js"; | import server from "../../../../services/server.js"; | ||||||
| import OptionsWidget from "../options_widget.js"; | import OptionsWidget from "../options_widget.js"; | ||||||
| 
 | 
 | ||||||
|  | const SAMPLE_LANGUAGE = "javascript"; | ||||||
|  | const SAMPLE_CODE = `\
 | ||||||
|  | function test(name) { | ||||||
|  | 	console.log("Works"); | ||||||
|  | 	console.info("Test"); | ||||||
|  | 	// Hello world.
 | ||||||
|  | } | ||||||
|  | ` | ||||||
|  | 
 | ||||||
| const TPL = ` | const TPL = ` | ||||||
| <div class="options-section"> | <div class="options-section"> | ||||||
|     <h4>Syntax highlighting</h4> |     <h4>Syntax highlighting</h4> | ||||||
| @ -12,6 +21,18 @@ const TPL = ` | |||||||
|             <select class="theme-select form-select"></select> |             <select class="theme-select form-select"></select> | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
|  | 
 | ||||||
|  |     <div class="form-group row"> | ||||||
|  |         <div class="note-detail-readonly-text-content ck-content code-sample-wrapper"> | ||||||
|  |             <pre><code class="code-sample"></code></pre> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | 
 | ||||||
|  |     <style> | ||||||
|  |         .code-sample-wrapper { | ||||||
|  |             margin-top: 1em; | ||||||
|  |         } | ||||||
|  |     </style> | ||||||
| </div> | </div> | ||||||
| `;
 | `;
 | ||||||
| 
 | 
 | ||||||
| @ -24,6 +45,17 @@ export default class HighlightingOptions extends OptionsWidget { | |||||||
|             library_loader.loadHighlightingTheme(newTheme); |             library_loader.loadHighlightingTheme(newTheme); | ||||||
|             await server.put(`options/highlightingTheme/${newTheme}`); |             await server.put(`options/highlightingTheme/${newTheme}`); | ||||||
|         }); |         }); | ||||||
|  | 
 | ||||||
|  |         // Set up preview
 | ||||||
|  |         const sampleEl = this.$widget.find(".code-sample"); | ||||||
|  |         library_loader | ||||||
|  |             .requireLibrary(library_loader.HIGHLIGHT_JS) | ||||||
|  |             .then(() => { | ||||||
|  |                 const highlightedText = hljs.highlight(SAMPLE_CODE, { | ||||||
|  |                     language: SAMPLE_LANGUAGE | ||||||
|  |                 }); | ||||||
|  |                 sampleEl.html(highlightedText.value); | ||||||
|  |             }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async optionsLoaded(options) { |     async optionsLoaded(options) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran