# Markdown: Language-identifying attribute for code blocks?

**URL:** <https://zola.discourse.group/t/markdown-language-identifying-attribute-for-code-blocks/100>\
**Category:** Feature requests\
**Created:** [May 1, 2019, 5:08pm UTC](https://zola.discourse.group/t/markdown-language-identifying-attribute-for-code-blocks/100 "2019-05-01T17:08:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ErichDonGubler](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/erichdongubler/32/50_2.png) [@ErichDonGubler](https://zola.discourse.group/u/ErichDonGubler)\
**Post date:** [May 1, 2019, 5:08pm UTC](https://zola.discourse.group/t/markdown-language-identifying-attribute-for-code-blocks/100/1 "2019-05-01T17:08:27Z")

</div>

I’m struggling to find precedents besides [RedCarpet’s usage in Jekyll](https://jekyllrb.com/docs/configuration/markdown/#redcarpet), 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:

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

````

…to this:

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

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [May 1, 2019, 9:17pm UTC](https://zola.discourse.group/t/markdown-language-identifying-attribute-for-code-blocks/100/2 "2019-05-01T21:17:12Z")

</div>

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 [https://github.com/getzola/zola/blob/master/components/rendering/src/markdown.rs#L189](https://github.com/getzola/zola/blob/master/components/rendering/src/markdown.rs#L189) (which is returning [https://github.com/trishume/syntect/blob/master/src/html.rs#L308-L314](https://github.com/trishume/syntect/blob/master/src/html.rs#L308-L314))

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

---

<div class="post-metadata">

**Author:** ![ErichDonGubler](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/erichdongubler/32/50_2.png) [@ErichDonGubler](https://zola.discourse.group/u/ErichDonGubler)\
**Post date:** [May 2, 2019, 8:02pm UTC](https://zola.discourse.group/t/markdown-language-identifying-attribute-for-code-blocks/100/3 "2019-05-02T20:02:59Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![asaaki](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/asaaki/32/340_2.png) [@asaaki](https://zola.discourse.group/u/asaaki)\
**Post date:** [October 6, 2020, 5:16pm UTC](https://zola.discourse.group/t/markdown-language-identifying-attribute-for-code-blocks/100/4 "2020-10-06T17:16:58Z")

</div>

I just created a branch with that feature:

> **[asaaki/zola](https://github.com/asaaki/zola/tree/code-class-language-info)**
>
> A fast static site generator in a single binary with everything built-in. https://www.getzola.org - asaaki/zola

Unless there are huge objections I would open a PR for it.

---

<div class="post-metadata">

**Author:** ![asaaki](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/asaaki/32/340_2.png) [@asaaki](https://zola.discourse.group/u/asaaki)\
**Post date:** [October 8, 2020, 7:11pm UTC](https://zola.discourse.group/t/markdown-language-identifying-attribute-for-code-blocks/100/5 "2020-10-08T19:11:13Z")

</div>

PR created: [https://github.com/getzola/zola/pull/1204](https://github.com/getzola/zola/pull/1204)
