-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec4f0a1
commit f54847d
Showing
2 changed files
with
40 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect, useState } from 'react' | ||
import { getHighlighterCore } from 'shiki/core' | ||
import getWasm from 'shiki/wasm' | ||
|
||
export const HighLighter = (props: { cssCode: string }) => { | ||
const [highlighCode, setHighlightCode] = useState(' ') | ||
|
||
useEffect(() => { | ||
;(async () => { | ||
const highlighter = await getHighlighterCore({ | ||
themes: [ | ||
// or a dynamic import if you want to do chunk splitting | ||
import('shiki/themes/vitesse-light.mjs'), | ||
], | ||
langs: [import('shiki/langs/css.mjs')], | ||
loadWasm: getWasm, | ||
}) | ||
|
||
// optionally, load themes and languages after creation | ||
await highlighter.loadTheme(import('shiki/themes/vitesse-light.mjs')) | ||
|
||
const code = highlighter.codeToHtml(`html{${props.cssCode}}`, { | ||
lang: 'css', | ||
theme: 'vitesse-light', | ||
}) | ||
|
||
setHighlightCode(code) | ||
})() | ||
}) | ||
|
||
return ( | ||
<div | ||
className="px-4 h-auto py-4 lh-4.5 bg-#f5f5f5 cursor-text font-['Roboto_Mono'] scrollbar-hide [&_pre]:bg-transparent! [&_pre]:overflow-auto" | ||
dangerouslySetInnerHTML={{ | ||
__html: highlighCode.replace('html', '').replace('{', '').replace('}', ''), | ||
}} | ||
></div> | ||
) | ||
} |