11import {
2- type Awaitable ,
32 type BundledHighlighterOptions ,
43 type BundledLanguage ,
54 type CodeOptionsMeta ,
65 type CodeOptionsThemes ,
76 type CodeToHastOptionsCommon ,
87 type Highlighter ,
9- type RegexEngine ,
108} from 'shiki' ;
119import type { BundledTheme } from 'shiki/themes' ;
1210import {
@@ -25,7 +23,12 @@ export const defaultThemes = {
2523
2624export type HighlightOptionsCommon = CodeToHastOptionsCommon < BundledLanguage > &
2725 CodeOptionsMeta & {
28- engine ?: 'js' | 'oniguruma' | Awaitable < RegexEngine > ;
26+ /**
27+ * The Regex Engine for Shiki
28+ *
29+ * @defaultValue 'js'
30+ */
31+ engine ?: 'js' | 'oniguruma' ;
2932 components ?: Partial < Components > ;
3033
3134 fallbackLanguage ?: BundledLanguage ;
@@ -46,7 +49,7 @@ export async function highlightHast(
4649 lang : initialLang ,
4750 fallbackLanguage,
4851 components : _ ,
49- engine = 'oniguruma ' ,
52+ engine = 'js ' ,
5053 ...rest
5154 } = options ;
5255 let lang = initialLang ;
@@ -64,25 +67,10 @@ export async function highlightHast(
6467 themesToLoad = Object . values ( themes . themes ) . filter ( ( v ) => v !== undefined ) ;
6568 }
6669
67- let highlighter ;
68- if ( typeof engine === 'string' ) {
69- highlighter = await getHighlighter ( engine , {
70- langs : [ ] ,
71- themes : themesToLoad ,
72- } ) ;
73- } else {
74- highlighter = await getHighlighter ( 'custom' , {
75- engine,
76- langs : [ ] ,
77- themes : themesToLoad ,
78- } ) ;
79-
80- if ( process . env . NODE_ENV === 'development' ) {
81- console . warn (
82- '[Fumadocs `highlight()`] Avoid passing `engine` directly. For custom engines, use `shiki` directly instead.' ,
83- ) ;
84- }
85- }
70+ const highlighter = await getHighlighter ( engine , {
71+ langs : [ ] ,
72+ themes : themesToLoad ,
73+ } ) ;
8674
8775 try {
8876 await highlighter . loadLanguage ( lang as BundledLanguage ) ;
@@ -110,14 +98,17 @@ export function hastToJsx(hast: Root, options?: Partial<ToJsxOptions>) {
11098}
11199
112100/**
113- * Get Shiki highlighter instance of Fumadocs (mostly for internal use, don't recommend you to use it ).
101+ * Get Shiki highlighter instance of Fumadocs (mostly for internal use, you should use Shiki directly over this ).
114102 *
115- * @param engineType - engine type, the engine specified in `options` will only be effective when this is set to `custom` .
103+ * @param engineType - Shiki Regex engine to use .
116104 * @param options - Shiki options.
117105 */
118106export async function getHighlighter (
119- engineType : 'js' | 'oniguruma' | 'custom' ,
120- options : BundledHighlighterOptions < BundledLanguage , BundledTheme > ,
107+ engineType : 'js' | 'oniguruma' ,
108+ options : Omit <
109+ BundledHighlighterOptions < BundledLanguage , BundledTheme > ,
110+ 'engine'
111+ > ,
121112) {
122113 const { createHighlighter } = await import ( 'shiki' ) ;
123114 let highlighter = highlighters . get ( engineType ) ;
@@ -129,12 +120,10 @@ export async function getHighlighter(
129120 engine = import ( 'shiki/engine/javascript' ) . then ( ( res ) =>
130121 res . createJavaScriptRegexEngine ( ) ,
131122 ) ;
132- } else if ( engineType === 'oniguruma' || ! options . engine ) {
123+ } else {
133124 engine = import ( 'shiki/engine/oniguruma' ) . then ( ( res ) =>
134125 res . createOnigurumaEngine ( import ( 'shiki/wasm' ) ) ,
135126 ) ;
136- } else {
137- engine = options . engine ;
138127 }
139128
140129 highlighter = createHighlighter ( {
0 commit comments