MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / highlight

Function highlight

docs/components/shiki.js:46–54  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

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

Callers 1

createEditorFunction · 0.85

Calls 2

escapeHtmlFunction · 0.85
isDarkFunction · 0.85

Tested by

no test coverage detected