1- import { ClassList , PropsOf , component$ , useSignal , useTask$ } from '@builder.io/qwik' ;
1+ import { ClassList , PropsOf , component$ , useSignal , useTask$ , $ } from '@builder.io/qwik' ;
22import { CodeCopy } from '../code-copy/code-copy' ;
33import { cn } from '@qwik-ui/utils' ;
4- import poimandres from 'shiki/themes/poimandres.mjs' ;
5- import html from 'shiki/langs/html.mjs' ;
6- import css from 'shiki/langs/css.mjs' ;
7- import tsx from 'shiki/langs/tsx.mjs' ;
8- import { createHighlighterCore , BundledLanguage } from 'shiki/index.mjs' ;
9-
10- // Create a single highlighter instance
11- const highlighterPromise = createHighlighterCore ( {
12- themes : [ poimandres ] ,
13- langs : [ html , css , tsx ] ,
14- loadWasm : import ( 'shiki/wasm' ) ,
15- } ) ;
4+ import { codeToHtml } from 'shiki' ;
165
176export type HighlightProps = PropsOf < 'div' > & {
187 code : string ;
198 copyCodeClass ?: ClassList ;
20- language ?: BundledLanguage ;
9+ language ?: 'tsx' | 'html' | 'css' ;
2110 splitCommentStart ?: string ;
2211 splitCommentEnd ?: string ;
2312} ;
@@ -33,26 +22,31 @@ export const Highlight = component$(
3322 } : HighlightProps ) => {
3423 const codeSig = useSignal ( '' ) ;
3524
36- useTask$ ( async ( { track } ) => {
37- track ( ( ) => code ) ;
25+ const addShiki$ = $ ( async ( ) => {
3826 let modifiedCode : string = code ;
3927
4028 let partsOfCode = modifiedCode . split ( splitCommentStart ) ;
29+
4130 if ( partsOfCode . length > 1 ) {
4231 modifiedCode = partsOfCode [ 1 ] ;
4332 }
4433
4534 partsOfCode = modifiedCode . split ( splitCommentEnd ) ;
35+
4636 if ( partsOfCode . length > 1 ) {
4737 modifiedCode = partsOfCode [ 0 ] ;
4838 }
4939
50- const highlighter = await highlighterPromise ;
51- const str = highlighter . codeToHtml ( modifiedCode , {
40+ const str = await codeToHtml ( modifiedCode , {
5241 lang : language ,
5342 theme : 'poimandres' ,
5443 } ) ;
55- codeSig . value = str ;
44+
45+ codeSig . value = str . toString ( ) ;
46+ } ) ;
47+
48+ useTask$ ( async ( ) => {
49+ await addShiki$ ( ) ;
5650 } ) ;
5751
5852 return (
0 commit comments