Skip to content

Commit e05ad7d

Browse files
committed
fix: Adds icon to external links, via the rehypePlugin system.
1 parent 9f19976 commit e05ad7d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

astro.config.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
import { defineConfig } from 'astro/config';
33
import starlight from '@astrojs/starlight';
44
import rehypeExternalLinks from 'rehype-external-links';
5+
import { externalLinkIcon } from './external-link-icon.js';
56

67
// https://astro.build/config
78
export default defineConfig({
89
site: 'https://JaneliaSciComp.github.io',
910
base: '/fileglancer-user-docs',
1011
markdown: {
1112
rehypePlugins: [
12-
[rehypeExternalLinks, { target: '_blank', rel: ['noopener', 'noreferrer'] }]
13+
[rehypeExternalLinks, {
14+
target: '_blank',
15+
rel: ['noopener', 'noreferrer'],
16+
content: externalLinkIcon
17+
}]
1318
]
1419
},
1520
integrations: [

external-link-icon.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* External link icon for rehype-external-links plugin.
3+
*
4+
* This SVG is defined using the hast (Hypertext Abstract Syntax Tree) format,
5+
* which is the AST format used by rehype plugins. The rehype-external-links
6+
* plugin expects content to be provided as a hast node, not as raw HTML/SVG markup.
7+
*
8+
* The icon uses Starlight's built-in "external" icon design.
9+
*/
10+
export const externalLinkIcon = {
11+
type: 'element',
12+
tagName: 'svg',
13+
properties: {
14+
width: '1em',
15+
height: '1em',
16+
viewBox: '0 0 24 24',
17+
fill: 'currentColor',
18+
style: 'display: inline-block; vertical-align: text-bottom; margin-left: 0.25em;'
19+
},
20+
children: [
21+
{
22+
type: 'element',
23+
tagName: 'path',
24+
properties: {
25+
d: 'M19.33 10.18a1 1 0 0 1-.77 0 1 1 0 0 1-.62-.93l.01-1.83-8.2 8.2a1 1 0 0 1-1.41-1.42l8.2-8.2H14.7a1 1 0 0 1 0-2h4.25a1 1 0 0 1 1 1v4.25a1 1 0 0 1-.62.93Z'
26+
}
27+
},
28+
{
29+
type: 'element',
30+
tagName: 'path',
31+
properties: {
32+
d: 'M11 4a1 1 0 1 1 0 2H7a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1v-4a1 1 0 1 1 2 0v4a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3h4Z'
33+
}
34+
}
35+
]
36+
};

0 commit comments

Comments
 (0)