* Highlights a single line of code, falling back to escaped plaintext when Prism * has not loaded yet or the language grammar is unavailable. * * @param prism - The loaded Prism module, or `null` while loading * @param text - The line of code to highlight * @param language - The language key (e
(prism: PrismModule | null, text: string, language: string)
| 106 | * @returns Highlighted HTML, or escaped plaintext as a fallback |
| 107 | */ |
| 108 | function highlightOrEscape(prism: PrismModule | null, text: string, language: string): string { |
| 109 | if (!prism) return escapeHtml(text) |
| 110 | const grammar = prism.languages[language] || prism.languages.javascript |
| 111 | return prism.highlight(text, grammar, language) |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Code editor configuration and constants. |