-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
43 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
import { createHighlighter } from 'shiki' | ||
import { once } from 'lodash-es' | ||
import type { Highlighter } from 'shiki' | ||
import type { | ||
Highlighter, | ||
LanguageInput, | ||
SpecialLanguage, | ||
StringLiteralUnion, | ||
} from 'shiki' | ||
|
||
export const SUPPORT_LANGUAGES: ( | ||
| LanguageInput | ||
| StringLiteralUnion<string> | ||
| SpecialLanguage | ||
)[] = [ | ||
'typescript', | ||
'javascript', | ||
'jsx', | ||
'tsx', | ||
'html', | ||
'css', | ||
'scss', | ||
'less', | ||
'json5', | ||
'vue', | ||
'json', | ||
'svelte', | ||
'xml', | ||
'yaml', | ||
'yml', | ||
'rust', | ||
'java', | ||
'kotlin', | ||
] | ||
|
||
let _highlighter: Highlighter | ||
async function _getHighlighter() { | ||
if (!_highlighter) { | ||
_highlighter = await createHighlighter({ | ||
themes: ['github-light', 'github-dark'], | ||
langs: [ | ||
'typescript', | ||
'javascript', | ||
'jsx', | ||
'tsx', | ||
'json', | ||
'svelte', | ||
'xml', | ||
'html', | ||
'yaml', | ||
'yml', | ||
'json5', | ||
'rust', | ||
'java', | ||
'kotlin', | ||
], | ||
}) | ||
} | ||
return _highlighter | ||
return await createHighlighter({ | ||
themes: ['github-light', 'github-dark'], | ||
langs: SUPPORT_LANGUAGES, | ||
}) | ||
} | ||
|
||
const getHighlighter = once(_getHighlighter) | ||
export const highlighter = await getHighlighter() | ||
export const highlighter = await _getHighlighter() |
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