(code)
| 44 | } |
| 45 | |
| 46 | const highlight = (code) => { |
| 47 | if (!hl) return escapeHtml(code) // plain text until Shiki finishes loading |
| 48 | const html = hl.codeToHtml(code, { lang: 'python', theme: isDark() ? 'github-dark' : 'github-light' }) |
| 49 | // CodeJar sets the return value as the editor's innerHTML, so drop Shiki's <pre><code> wrapper. |
| 50 | let inner = html.replace(/^<pre[^>]*>\s*<code[^>]*>/, '').replace(/<\/code>\s*<\/pre>\s*$/, '') |
| 51 | // For code ending in \n, Shiki adds a trailing empty `<span class="line"></span>` the caret can't reach. Drop it so the HTML ends with the \n text node (Prism-style) and stays editable. |
| 52 | if (code.endsWith('\n')) inner = inner.replace(/<span class="line"><\/span>$/, '') |
| 53 | return inner |
| 54 | } |
| 55 | // Disconnect the <html> observer and ignore a late getHighlighter() resolve, so the editor closure can be GC'd on unmount. |
| 56 | highlight.dispose = () => { disposed = true; observer?.disconnect() } |
| 57 | return highlight |
no test coverage detected