mirror of
				https://github.com/livebook-dev/livebook.git
				synced 2025-10-31 15:56:05 +08:00 
			
		
		
		
	Ensure the highlighter CSS is loaded when highlighting snippets
This commit is contained in:
		
							parent
							
								
									80534d27fa
								
							
						
					
					
						commit
						d1e8f68525
					
				
					 1 changed files with 7 additions and 1 deletions
				
			
		|  | @ -1,5 +1,6 @@ | |||
| import { LanguageDescription } from "@codemirror/language"; | ||||
| import { highlightCode } from "@lezer/highlight"; | ||||
| import { StyleModule } from "style-mod"; | ||||
| import { languages } from "./codemirror/languages"; | ||||
| import { highlightStyle, lightHighlightStyle } from "./codemirror/theme"; | ||||
| import { escapeHtml } from "../../../lib/utils"; | ||||
|  | @ -15,6 +16,11 @@ export function highlight(code, language) { | |||
|     return escapeHtml(code); | ||||
|   } | ||||
| 
 | ||||
|   const highlightStyle = getHighlightStyle(); | ||||
| 
 | ||||
|   // Ensure the highlighter CSS is added to the page
 | ||||
|   StyleModule.mount(window.document, highlightStyle.module); | ||||
| 
 | ||||
|   const tree = languageDesc.support.language.parser.parse(code); | ||||
| 
 | ||||
|   let html = ""; | ||||
|  | @ -22,7 +28,7 @@ export function highlight(code, language) { | |||
|   highlightCode( | ||||
|     code, | ||||
|     tree, | ||||
|     getHighlightStyle(), | ||||
|     highlightStyle, | ||||
|     (code, classes) => { | ||||
|       html += `<span class="${classes}">${escapeHtml(code)}</span>`; | ||||
|     }, | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue