-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(markdown): support custom display-name for fenced code blocks #4960
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
Conversation
LGTM, but not sure if we should do this instead of allowing specifying these globally. Because that part is meant to show the language, I don't think people should misuse it to write titles there. If one wants title, they can use https://vp.yuy1n.io/features.html#%F0%9F%AA%A7-title-bar |
Really appreciate your response! Let me explain why I submitted this PR. Here’s a scenario: users of ArkTS need to write ts after the triple backticks, because ArkTS follows the same syntax highlighting rules as TypeScript. However, their actual language is ArkTS — a subset of TS designed for a specific operating system. Another possible example is SQL dialects. They often reuse the same sql highlighting, but authors might still want to indicate which specific dialect is being used. In such cases, I think this feature is useful. I completely understand your point — people shouldn’t misuse the “language”. I’m looking forward to hearing more thoughts from you and the community. Needs more discussion! |
They can use languageAlias: import { defineConfig } from 'vitepress'
export default defineConfig({
markdown: {
languageAlias: {
arkts: 'ts'
}
}
}) ![]()
The issue is when there is space in the name. One possible solution can be to use Well, the original issue was to respect/override the language's import { defineConfig } from 'vitepress'
export default defineConfig({
markdown: {
languageLabel: {
ts: 'Ark TS'
},
}
})
/*
Usage:
```ts
something
```
(all ts blocks) will be rendered with label "Ark TS"
*/ And, import { defineConfig } from 'vitepress'
export default defineConfig({
markdown: {
languageAlias: {
ark_ts: 'ts'
},
}
})
/*
Usage:
```Ark_TS
something
```
(only Ark_TS blocks) will be rendered with label "Ark TS"
you can still have
```ts
something
```
which will be rendered with label "ts"
*/ |
It’s a more intuitive and concise way to indicate the language! I’m going to work on this approach. Do you think we need consider the case where users actually want an underscore to appear in the language label? or we just ignore it? |
I think it's fine to ignore that case. It only affects the displayed lang anyway. It won't break anything. We can adjust the behavior if someone has a use case to show underscore in language name. |
I’ve put together a basic implementation, hope it’s useful :-) |
Thanks for your review and merge. I love vitepress and really appreciate your contribution :-) |
Description
This PR adds support for a display-name attribute on fenced code blocks.
With this option, users can override the default language label shown in the top-right corner of code blocks.
Example:
The code block will display 'Bar' as the label instead of the default 'foo'.
Linked Issues
Fixes #4951