summaryrefslogtreecommitdiff
path: root/packages/markdown/remark
diff options
context:
space:
mode:
authorGravatar Houston (Bot) <108291165+astrobot-houston@users.noreply.github.com> 2024-04-11 04:24:47 -0700
committerGravatar GitHub <noreply@github.com> 2024-04-11 13:24:47 +0200
commit66bc1041d4fbef95d624fc9bff0c3f9ced4638c2 (patch)
tree81dd90a2528c781476d61e8255a569a3b53f9254 /packages/markdown/remark
parent908645d9ddfa58fbbe2b5d160d94b7d531ccf7a6 (diff)
downloadastro-66bc1041d4fbef95d624fc9bff0c3f9ced4638c2.tar.gz
astro-66bc1041d4fbef95d624fc9bff0c3f9ced4638c2.tar.zst
astro-66bc1041d4fbef95d624fc9bff0c3f9ced4638c2.zip
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'packages/markdown/remark')
-rw-r--r--packages/markdown/remark/CHANGELOG.md49
-rw-r--r--packages/markdown/remark/package.json4
2 files changed, 51 insertions, 2 deletions
diff --git a/packages/markdown/remark/CHANGELOG.md b/packages/markdown/remark/CHANGELOG.md
index d90ae3f8d..916ff1210 100644
--- a/packages/markdown/remark/CHANGELOG.md
+++ b/packages/markdown/remark/CHANGELOG.md
@@ -1,5 +1,54 @@
# @astrojs/markdown-remark
+## 5.1.0
+
+### Minor Changes
+
+- [#10538](https://github.com/withastro/astro/pull/10538) [`ccafa8d230f65c9302421a0ce0a0adc5824bfd55`](https://github.com/withastro/astro/commit/ccafa8d230f65c9302421a0ce0a0adc5824bfd55) Thanks [@604qgc](https://github.com/604qgc)! - Adds a `data-language` attribute on the rendered `pre` elements to expose the highlighted syntax language.
+
+ For example, the following Markdown code block will expose `data-language="python"`:
+
+ ````
+ \```python
+ def func():
+ print('Hello Astro!')
+ \```
+ ````
+
+ This allows retrieving the language in a rehype plugin from `node.properties.dataLanguage` by accessing the `<pre>` element using `{ tagName: "pre" }`:
+
+ ```js
+ // myRehypePre.js
+ import { visit } from "unist-util-visit";
+ export default function myRehypePre() {
+ return (tree) => {
+ visit(tree, { tagName: "pre" }, (node) => {
+ const lang = node.properties.dataLanguage;
+ [...]
+ });
+ };
+ }
+ ```
+
+ Note: The `<pre>` element is not exposed when using Astro's `<Code />` component which outputs flattened HTML.
+
+ The `data-language` attribute may also be used in css rules:
+
+ ```css
+ pre::before {
+ content: attr(data-language);
+ }
+
+ pre[data-language='javascript'] {
+ font-size: 2rem;
+ }
+ ```
+
+### Patch Changes
+
+- Updated dependencies [[`683d51a5eecafbbfbfed3910a3f1fbf0b3531b99`](https://github.com/withastro/astro/commit/683d51a5eecafbbfbfed3910a3f1fbf0b3531b99)]:
+ - @astrojs/prism@3.1.0
+
## 5.0.0
### Major Changes
diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json
index 19df22236..5e2c8975c 100644
--- a/packages/markdown/remark/package.json
+++ b/packages/markdown/remark/package.json
@@ -1,6 +1,6 @@
{
"name": "@astrojs/markdown-remark",
- "version": "5.0.0",
+ "version": "5.1.0",
"type": "module",
"author": "withastro",
"license": "MIT",
@@ -34,7 +34,7 @@
"test": "astro-scripts test \"test/**/*.test.js\""
},
"dependencies": {
- "@astrojs/prism": "^3.0.0",
+ "@astrojs/prism": "^3.1.0",
"github-slugger": "^2.0.0",
"hast-util-from-html": "^2.0.0",
"hast-util-to-text": "^4.0.0",