You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a `data-language` attribute on the rendered `pre` elements to expose the highlighted syntax language.
6
+
7
+
For example, the following Markdown code block will expose `data-language="python"`:
8
+
```
9
+
\```python
10
+
def func():
11
+
print('Hello Astro!')
12
+
\```
13
+
```
14
+
15
+
This allows retrieving the language in a rehype plugin from `node.properties.dataLanguage` by accessing the `<pre>` element using `{ tagName: "pre" }`:
16
+
```js
17
+
// myRehypePre.js
18
+
import { visit } from"unist-util-visit";
19
+
exportdefaultfunctionmyRehypePre() {
20
+
return (tree) => {
21
+
visit(tree, { tagName:"pre" }, (node) => {
22
+
constlang=node.properties.dataLanguage;
23
+
[...]
24
+
});
25
+
};
26
+
}
27
+
```
28
+
29
+
Note: The `<pre>` element is not exposed when using Astro's `<Code />` component which outputs flattened HTML.
30
+
31
+
32
+
The `data-language` attribute may also be used in css rules:
0 commit comments