Add Ability to Use Codeblock Language as Container Title #10808
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Description
Currently, Docusaurus renders the language specified in a codeblock as part of its syntax highlighting, but it doesn't allow using the language as the container title. This proposal suggests adding an option to display the codeblock's language as the title of the container for improved clarity and user experience.
This can be a global boolean setting in the Docusaurus config file where the codeblock component will always fallback to the language if a title isn't specified.
Has this been requested on Canny?
https://docusaurus.io/feature-requests/p/add-ability-to-use-codeblock-language-as-container-title
Motivation
When documenting code examples, it's often helpful to explicitly label the codeblocks with their language for better readability and context. While custom titles can be added using the title attribute in fenced codeblocks, it would be beneficial to have a built-in feature that automatically uses the language as the container title.
This is also beneficial when working around this use case https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md014.md where you want to remove the $
sign to make copy pasting more convenient and allow the user to understand that the code block is a shell command.
it works well for any language as the user can quickly figure out what language he's reading.
API design
type CodeBlock = {
useLanguageAsTitle: boolean;
};
docusaurus.config.ts
{
themeConfig: {
codeBlock: {useLanguageAsTitle: true},
}
}
Have you tried building it?
yes
https://github.com/hichemfantar/docusaurus-fork/tree/codeblock-language-as-title
Self-service
- I'd be willing to contribute this feature to Docusaurus myself.