react-shiki
Version:
Syntax highlighter component for react using shiki
53 lines (52 loc) • 2.09 kB
JavaScript
import { a as isLoadableLanguage, i as useHighlight, n as isInlineCode, r as rehypeInlineCodeProperty, t as createShikiHighlighterComponent } from "./component-CYq7SnJ0.mjs";
import { bundledLanguages, getSingletonHighlighter } from "shiki";
import { createOnigurumaEngine } from "shiki/engine/oniguruma";
import { createJavaScriptRawEngine, createJavaScriptRegexEngine } from "shiki/engine/javascript";
//#region src/bundles/full.ts
/**
* Creates a highlighter using the full Shiki bundle with all languages and themes.
* This is the largest bundle but provides maximum compatibility.
*/
async function createFullHighlighter(langsToLoad, themesToLoad, engine) {
return await getSingletonHighlighter({
langs: langsToLoad.filter((lang) => isLoadableLanguage(lang, bundledLanguages)),
themes: themesToLoad,
engine: engine ?? createOnigurumaEngine(import("shiki/wasm"))
});
}
//#endregion
//#region src/index.ts
/**
* Highlight code with shiki (full bundle)
*
* @param code - Code to highlight
* @param lang - Language (bundled or custom)
* @param theme - Theme (bundled, multi-theme, or custom)
* @param options - react-shiki options + shiki options
* @returns Highlighted code as React elements or HTML string
*
* @example
* ```tsx
* const highlighted = useShikiHighlighter(
* 'const x = 1;',
* 'typescript',
* {
* light: 'github-light',
* dark: 'github-dark'
* }
* );
* ```
*
* Full bundle (~6.4MB minified, 1.2MB gzipped). For smaller bundles: `react-shiki/web` or `react-shiki/core`
*/
const useShikiHighlighter = (code, lang, themeInput, options = {}) => {
return useHighlight(code, lang, themeInput, options, createFullHighlighter);
};
/**
* ShikiHighlighter component using the full bundle.
* Includes all languages and themes for maximum compatibility.
*/
const ShikiHighlighter = createShikiHighlighterComponent(useShikiHighlighter);
//#endregion
export { ShikiHighlighter, ShikiHighlighter as default, createJavaScriptRawEngine, createJavaScriptRegexEngine, isInlineCode, rehypeInlineCodeProperty, useShikiHighlighter };
//# sourceMappingURL=index.mjs.map