Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-shiki): add langAlias option #178

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/plugins/markdown/shiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export default {
- Also see:
- [Shiki > Languages](https://shiki.style/languages)

### langAlias

- Type: `{ [lang: string]: string }`

- Details: Customize language aliases for Shiki.

- Also see:
- [Shiki > Custom Language Aliases](https://shiki.style/guide/load-lang#custom-language-aliases)

### defaultLang

- Type: `string`
Expand Down
9 changes: 9 additions & 0 deletions docs/zh/plugins/markdown/shiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export default {
- 参考:
- [shiki > Languages](https://shiki.style/languages)

### langAlias

- 类型:`{ [lang: string]: string }`

- 详情:自定义 Shiki 语言别名。

- 参考:
- [Shiki > 自定义语言别名](https://shiki.tmrs.site/guide/load-lang#custom-language-aliases)

### defaultLang

- 类型:`string`
Expand Down
2 changes: 2 additions & 0 deletions plugins/markdown/plugin-shiki/src/node/resolveHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const MUSTACHE_REG = /\{\{[^]*?\}\}/g

export const resolveHighlight = async ({
langs = bundledLanguageNames,
langAlias = {},
theme = 'nord',
themes,
defaultLang = '',
Expand All @@ -22,6 +23,7 @@ export const resolveHighlight = async ({
> => {
const highlighter = await getHighlighter({
langs,
langAlias,
themes: themes ? [themes.dark, themes.light] : [theme],
})

Expand Down
7 changes: 7 additions & 0 deletions plugins/markdown/plugin-shiki/src/node/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export interface ShikiHighlightOptions {
*/
langs?: ShikiLang[]

/**
* Language alias
*
* @see https://shiki.style/guide/load-lang#custom-language-aliases
*/
langAlias?: Record<string, StringLiteralUnion<BundledLanguage>>

/**
* Fallback language when the specified language is not available.
*/
Expand Down
Loading