Skip to content

Commit

Permalink
perf(plugin-shiki): improve logging when language is not available (#215
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pengzhanbo committed Jul 10, 2024
1 parent c7c9a72 commit b84ce08
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/plugins/markdown/shiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ The following features requires additional style to work, which should be handle

- Type: `string`

- Default: `'plain'`
- Default: `''`

- Details: Fallback language when the specified language is not available.

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/plugins/markdown/shiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export default defineUserConfig({

- 类型:`string`

- 默认值:`'plain'`
- 默认值:`''`

- 详情:指定的语言不可用时所使用的备选语言。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const WARNED_LANGS = new Set<string>()
export const getLanguage = (
lang: string,
loadedLanguages: string[],
defaultLang: string,
defaultLang: string | undefined,
logLevel: string,
getMarkdownFilePath: MarkdownFilePathGetter,
): string => {
Expand All @@ -18,7 +18,7 @@ export const getLanguage = (
// warn for unknown languages only once
if (logLevel !== 'silent' && !WARNED_LANGS.has(result)) {
logger.warn(
`Missing ${colors.cyan(lang)} highlighter, use ${colors.cyan(defaultLang)} to highlight instead.`,
`Missing ${colors.cyan(lang)} highlighter, ${defaultLang ? `use ${colors.cyan(defaultLang)} to highlight instead.` : 'skip highlighting'}`,
)
WARNED_LANGS.add(result)
}
Expand All @@ -30,7 +30,7 @@ export const getLanguage = (
)
}

result = defaultLang
result = defaultLang || 'plain'
}

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const applyHighlighter = async (
{
langs = bundledLanguageNames,
langAlias = {},
defaultLang = 'plain',
defaultLang,
transformers: userTransformers = [],
...options
}: ShikiHighlightOptions = {},
Expand Down

0 comments on commit b84ce08

Please sign in to comment.