Skip to content

Commit 93a0f21

Browse files
authored
feat: add rehype plugins for automatic heading links and update styles (#2242)
1 parent f113821 commit 93a0f21

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

astro/astro.config.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import expressiveCode from 'astro-expressive-code';
77
import react from '@astrojs/react';
88
import svgr from 'vite-plugin-svgr';
99
import Icons from 'unplugin-icons/vite';
10+
import rehypeSlug from 'rehype-slug';
11+
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
1012
import redirects from './src/config/redirect.js';
1113

1214
/* https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables */
@@ -18,6 +20,17 @@ const site = NETLIFY_PREVIEW_SITE || 'https://expressjs.com';
1820
export default defineConfig({
1921
redirects,
2022
site,
23+
markdown: {
24+
rehypePlugins: [
25+
rehypeSlug,
26+
[
27+
rehypeAutolinkHeadings,
28+
{
29+
behavior: 'wrap',
30+
},
31+
],
32+
],
33+
},
2134
vite: {
2235
plugins: [
2336
// Transforms SVG files imported with the `?react` suffix into React components

astro/package-lock.json

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

astro/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
"mdast-util-from-markdown": "^2.0.3",
3131
"mdast-util-to-string": "^4.0.0",
3232
"react": "^19.2.4",
33-
"react-dom": "^19.2.4"
33+
"react-dom": "^19.2.4",
34+
"rehype-autolink-headings": "^7.1.0",
35+
"rehype-slug": "^6.0.0"
3436
},
3537
"devEngines": {
3638
"runtime": {

astro/src/styles/base/_global.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ small,
133133
margin: var(--space-body) 0;
134134
}
135135

136+
/* Heading links (rehype-autolink-headings) */
137+
h1 > a,
138+
h2 > a,
139+
h3 > a,
140+
h4 > a,
141+
h5 > a,
142+
h6 > a {
143+
color: inherit;
144+
text-decoration: none;
145+
146+
&:hover {
147+
color: inherit;
148+
text-decoration: underline;
149+
}
150+
}
151+
136152
/* Links */
137153
a {
138154
color: var(--color-link);

0 commit comments

Comments
 (0)