diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 9cdaff85..a091639a 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -87,14 +87,25 @@ export interface MarkdownOptions extends Options { */ languages?: (LanguageInput | BuiltinLanguage)[] /** - * Custom language aliases. - * Maps custom language names to existing languages for syntax highlighting. - * Language identifiers with underscores will automatically display with spaces. - * Alias lookup is case-insensitive. + * Custom language aliases for syntax highlighting. + * Maps custom language names to existing languages. + * Alias lookup is case-insensitive and underscores in language names are displayed as spaces. * - * @example { 'my_lang': 'python' } - * - * ```My_Lang uses Python highlighting, displays "My Lang" + * @example + * + * Maps `my_lang` to use Python syntax highlighting. + * ```js + * { 'my_lang': 'python' } + * ``` + * + * Usage in markdown: + * ````md + * ```My_Lang + * # This will be highlighted as Python code + * # and will show "My Lang" as the language label + * print("Hello, World!") + * ``` + * ```` * * @see https://shiki.style/guide/load-lang#custom-language-aliases */ diff --git a/src/node/markdown/plugins/highlight.ts b/src/node/markdown/plugins/highlight.ts index 4e62d3d1..780e37e8 100644 --- a/src/node/markdown/plugins/highlight.ts +++ b/src/node/markdown/plugins/highlight.ts @@ -68,10 +68,14 @@ export async function highlight( ...(options.languages || []), ...Object.values(options.languageAlias || {}) ], - langAlias: options.languageAlias ? - Object.fromEntries( - Object.entries(options.languageAlias).map(([key, value]) => [key.toLowerCase(), value]) - ) : undefined + langAlias: options.languageAlias + ? Object.fromEntries( + Object.entries(options.languageAlias).map(([key, value]) => [ + key.toLowerCase(), + value + ]) + ) + : undefined }) await options?.shikiSetup?.(highlighter) diff --git a/src/node/markdown/plugins/preWrapper.ts b/src/node/markdown/plugins/preWrapper.ts index d68043a1..38266509 100644 --- a/src/node/markdown/plugins/preWrapper.ts +++ b/src/node/markdown/plugins/preWrapper.ts @@ -18,7 +18,7 @@ export function preWrapperPlugin(md: MarkdownItAsync, options: Options) { token.info = token.info.replace(/ active$/, '').replace(/ active /, ' ') const lang = extractLang(token.info) - const langLabel = getLangLabel(lang, options.languageLabel) + const langLabel = options.languageLabel?.[lang] || lang.replace(/_/g, ' ') return ( `