Skip to content

Commit a09741b

Browse files
ArmandPhilippotdelucisyanthomasdev
authored
fix: use the unified() processor in remark/rehype recipes (#14046)
Co-authored-by: delucis <357379+delucis@users.noreply.github.com> Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
1 parent 219180f commit a09741b

3 files changed

Lines changed: 33 additions & 54 deletions

File tree

src/content/docs/en/recipes/external-links.mdx

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,48 @@ Using a rehype plugin, you can identify and modify links in your Markdown files
1616
## Recipe
1717

1818
<Steps>
19-
1. Install the `rehype-external-links` plugin.
19+
1. Install both the [`rehype-external-links`](https://www.npmjs.com/package/rehype-external-links) plugin and [`@astrojs/markdown-remark`](https://www.npmjs.com/package/@astrojs/markdown-remark).
2020

2121
<PackageManagerTabs>
2222
<Fragment slot="npm">
2323
```shell
24-
npm install rehype-external-links
24+
npm install rehype-external-links @astrojs/markdown-remark
2525
```
2626
</Fragment>
2727
<Fragment slot="pnpm">
2828
```shell
29-
pnpm add rehype-external-links
29+
pnpm add rehype-external-links @astrojs/markdown-remark
3030
```
3131
</Fragment>
3232
<Fragment slot="yarn">
3333
```shell
34-
yarn add rehype-external-links
34+
yarn add rehype-external-links @astrojs/markdown-remark
3535
```
3636
</Fragment>
3737
</PackageManagerTabs>
3838

39-
2. Import the plugin into your `astro.config.mjs` file.
39+
2. Configure the plugin in your `astro.config.mjs` file.
4040

41-
Pass `rehypeExternalLinks` to the `rehypePlugins` array, along with an options object that includes a content property. Set this property's `type` to `text` if you want to add plain text to the end of the link. To add HTML to the end of the link instead, set the property `type` to `raw`.
41+
Import `unified()` and define it as the Markdown processor to [support remark plugins](/en/guides/markdown-content/#using-remark-and-rehype-plugins). Then, pass to `rehypePlugins` an array containing your imported `rehypeExternalLinks` plugin and an options object with a `content` property. Set this property's `type` to `text` if you want to add plain text to the end of the link. To add HTML to the end of the link instead, set the property `type` to `raw`.
4242

43-
```ts
44-
// ...
43+
```js title="astro.config.mjs"
44+
import { unified } from '@astrojs/markdown-remark';
45+
import { defineConfig } from 'astro/config';
4546
import rehypeExternalLinks from 'rehype-external-links';
4647

4748
export default defineConfig({
4849
// ...
4950
markdown: {
50-
rehypePlugins: [
51-
[
52-
rehypeExternalLinks,
53-
{
54-
content: { type: 'text', value: ' 🔗' }
55-
}
56-
],
57-
]
51+
processor: unified({
52+
rehypePlugins: [
53+
[
54+
rehypeExternalLinks,
55+
{
56+
content: { type: 'text', value: ' 🔗' }
57+
}
58+
],
59+
]
60+
}),
5861
},
5962
});
6063
```
@@ -63,7 +66,3 @@ Using a rehype plugin, you can identify and modify links in your Markdown files
6366
The value of the `content` property is [not represented in the accessibility tree](https://developer.mozilla.org/en-US/docs/Web/CSS/content#accessibility_concerns). As such, it's best to make clear that the link is external in the surrounding content, rather than relying on the icon alone.
6467
:::
6568
</Steps>
66-
67-
68-
## Resources
69-
- [rehype-external-links](https://www.npmjs.com/package/rehype-external-links)

src/content/docs/en/recipes/modified-time.mdx

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,22 @@ This recipe calculates time based on your repository’s Git history and may not
1616
## Recipe
1717

1818
<Steps>
19-
1. Install Helper Packages
20-
21-
Install [`Day.js`](https://www.npmjs.com/package/dayjs) to modify and format times:
22-
23-
<PackageManagerTabs>
24-
<Fragment slot="npm">
25-
```shell
26-
npm install dayjs
27-
```
28-
</Fragment>
29-
<Fragment slot="pnpm">
30-
```shell
31-
pnpm add dayjs
32-
```
33-
</Fragment>
34-
<Fragment slot="yarn">
35-
```shell
36-
yarn add dayjs
37-
```
38-
</Fragment>
39-
</PackageManagerTabs>
40-
41-
Install [`@astrojs/markdown-remark`](https://www.npmjs.com/package/@astrojs/markdown-remark) to use [the `unified()` processor](/en/guides/markdown-content/#using-remark-and-rehype-plugins):
19+
1. Install [`Day.js`](https://www.npmjs.com/package/dayjs) to modify and format times, and [`@astrojs/markdown-remark`](https://www.npmjs.com/package/@astrojs/markdown-remark) to use [the `unified()` processor](/en/guides/markdown-content/#using-remark-and-rehype-plugins):
4220

4321
<PackageManagerTabs>
4422
<Fragment slot="npm">
4523
```shell
46-
npm install @astrojs/markdown-remark
24+
npm install dayjs @astrojs/markdown-remark
4725
```
4826
</Fragment>
4927
<Fragment slot="pnpm">
5028
```shell
51-
pnpm add @astrojs/markdown-remark
29+
pnpm add dayjs @astrojs/markdown-remark
5230
```
5331
</Fragment>
5432
<Fragment slot="yarn">
5533
```shell
56-
yarn add @astrojs/markdown-remark
34+
yarn add dayjs @astrojs/markdown-remark
5735
```
5836
</Fragment>
5937
</PackageManagerTabs>

src/content/docs/en/recipes/reading-time.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@ Create a [remark plugin](https://github.com/remarkjs/remark) which adds a readin
1212
## Recipe
1313

1414
<Steps>
15-
1. Install Helper Packages
16-
17-
Install these two helper packages:
15+
1. Install the following packages:
1816
- [`reading-time`](https://www.npmjs.com/package/reading-time) to calculate minutes read
1917
- [`mdast-util-to-string`](https://www.npmjs.com/package/mdast-util-to-string) to extract all text from your markdown
18+
- [`@astrojs/markdown-remark`](https://www.npmjs.com/package/@astrojs/markdown-remark) to use [the `unified()` processor](/en/guides/markdown-content/#using-remark-and-rehype-plugins):
2019

2120
<PackageManagerTabs>
2221
<Fragment slot="npm">
2322
```shell
24-
npm install reading-time mdast-util-to-string
23+
npm install reading-time mdast-util-to-string @astrojs/markdown-remark
2524
```
2625
</Fragment>
2726
<Fragment slot="pnpm">
2827
```shell
29-
pnpm add reading-time mdast-util-to-string
28+
pnpm add reading-time mdast-util-to-string @astrojs/markdown-remark
3029
```
3130
</Fragment>
3231
<Fragment slot="yarn">
3332
```shell
34-
yarn add reading-time mdast-util-to-string
33+
yarn add reading-time mdast-util-to-string @astrojs/markdown-remark
3534
```
3635
</Fragment>
3736
</PackageManagerTabs>
@@ -57,13 +56,16 @@ Create a [remark plugin](https://github.com/remarkjs/remark) which adds a readin
5756

5857
3. Add the plugin to your config:
5958

60-
```js title="astro.config.mjs" "import { remarkReadingTime } from './remark-reading-time.mjs';" "remarkPlugins: [remarkReadingTime],"
59+
```js title="astro.config.mjs" {1,3,7-9}
60+
import { unified } from '@astrojs/markdown-remark';
6161
import { defineConfig } from 'astro/config';
6262
import { remarkReadingTime } from './remark-reading-time.mjs';
6363

6464
export default defineConfig({
6565
markdown: {
66-
remarkPlugins: [remarkReadingTime],
66+
processor: unified({
67+
remarkPlugins: [remarkReadingTime],
68+
}),
6769
},
6870
});
6971
```

0 commit comments

Comments
 (0)