-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
BREAKING CHANGE: now `langs` option is required, you need to set the languages list explicitly Co-authored-by: meteorlxy <[email protected]>
- Loading branch information
Showing
4 changed files
with
68 additions
and
27 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
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,26 +1,74 @@ | ||
import type { Plugin } from '@vuepress/core' | ||
import { getHighlighter } from 'shiki' | ||
import type { HighlighterOptions } from 'shiki' | ||
import { getHighlighter } from 'shikiji' | ||
import type { | ||
BundledLanguage, | ||
BundledTheme, | ||
LanguageInput, | ||
SpecialLanguage, | ||
StringLiteralUnion, | ||
ThemeRegistration, | ||
ThemeRegistrationRaw, | ||
} from 'shikiji' | ||
|
||
export type ShikiLang = | ||
| LanguageInput | ||
| StringLiteralUnion<BundledLanguage> | ||
| SpecialLanguage | ||
|
||
export type ShikiTheme = | ||
| ThemeRegistration | ||
| ThemeRegistrationRaw | ||
| StringLiteralUnion<BundledTheme> | ||
|
||
/** | ||
* Options of @vuepress/plugin-shiki | ||
*/ | ||
export type ShikiPluginOptions = Pick<HighlighterOptions, 'theme' | 'langs'> | ||
export interface ShikiPluginOptions { | ||
/** | ||
* Languages to be loaded. | ||
* | ||
* Shikiji does not preload any languages to avoid extra overhead. So you need | ||
* to specify the languages you want to use. | ||
* | ||
* @see https://shikiji.netlify.app/languages | ||
*/ | ||
langs?: ShikiLang[] | ||
|
||
/** | ||
* The single theme to use | ||
* | ||
* @see https://shikiji.netlify.app/themes | ||
*/ | ||
theme?: ShikiTheme | ||
|
||
/** | ||
* The dark and light themes to use | ||
* | ||
* @see https://shikiji.netlify.app/themes | ||
*/ | ||
themes?: { | ||
dark: ShikiTheme | ||
light: ShikiTheme | ||
} | ||
} | ||
|
||
export const shikiPlugin = ({ | ||
theme = 'nord', | ||
langs, | ||
theme = 'nord', | ||
themes, | ||
}: ShikiPluginOptions = {}): Plugin => ({ | ||
name: '@vuepress/plugin-shiki', | ||
|
||
extendsMarkdown: async (md) => { | ||
const highlighter = await getHighlighter({ | ||
theme, | ||
langs, | ||
themes: themes ? [themes.dark, themes.light] : [theme], | ||
}) | ||
|
||
md.options.highlight = (code, lang) => | ||
highlighter.codeToHtml(code, { | ||
lang, | ||
...(themes ? { themes } : { theme }), | ||
}) | ||
}, | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.