escape fences in jsdoc, simplify, format

pull/4960/head
Divyansh Singh 2 months ago
parent 597e8e4468
commit 60506d4a9b

@ -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
*/

@ -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)

@ -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 (
`<div class="language-${lang}${active}">` +
@ -48,11 +48,3 @@ function extractLang(info: string) {
.replace(/^vue-html$/, 'template')
.replace(/^ansi$/, '')
}
function getLangLabel(lang: string, languageLabel?: Record<string, string>): string {
if (languageLabel && languageLabel[lang]) {
return languageLabel[lang]
}
return lang.replace(/_/g, ' ')
}

Loading…
Cancel
Save