Markdown: Language-identifying attribute for code blocks?


I’m struggling to find precedents besides RedCarpet’s usage in Jekyll, but several tools I’ve used have produced an attribute that identifies the language of the code block being rendered (i.e., data-lang="<LANGUAGE>", class="language-<LANGUAGE>"). This can offer some neat styling tweaks with CSS! Here’s an example of how that might look:

From this:

fn main() {
    println!("Hello, world!");

…to this:

  <code data-lang="rust"> <!-- >
fn main() {
    println!("Hello, world!");

Is it only for the cases where syntax highlighting is disabled?

In Syntect, you don’t actually have a <code> tag, only <pre>.
The way to implement it would be to do a basic replace on the result of (which is returning

If it is only for codeblocks without syntax highlighting, then it’s even easier, just a string to modify.


I’d prefer to have it be available in all cases – I specifically was hoping for language-specific decorations around rendered code blocks – but I understand that I’m not necessarily representative of others’ use cases. :slight_smile: