Icons for external links
Arrows for external links
Installation
-
Install dependencies
Terminal window pnpm add rehype-external-links -
Configure Astro
astro.config.mjs import rehypeExternalLinks from "rehype-external-links";export default defineConfig({integrations: [starlight({customCss: ["./src/styles/custom.css"],}),],markdown: {rehypePlugins: [[rehypeExternalLinks,{content: { type: "text", value: " โ" }, // โคดcontentProperties: { "aria-hidden": true, class: "no-select" },},],],},}); -
Add CSS
src/styles/custom.css .no-select {user-select: none;}
Based on: Astro recipes
Example
https://example.com
Favicons for external links
Installation
-
Install dependencies
Terminal window pnpm add rehype-external-links -
Configure Astro
astro.config.mjs import rehypeExternalLinks from "rehype-external-links";export default defineConfig({integrations: [starlight({customCss: ["./src/styles/custom.css"],}),],markdown: {rehypePlugins: [[rehypeExternalLinks,{content: { type: "text", value: "" },contentProperties: (x) => {const hostname = new URL(x.properties.href).hostname;return {class: "external-icon",style: `--icon: url(https://external-content.duckduckgo.com/ip3/${hostname}.ico)`,};},},],],},}); -
Add CSS
src/styles/custom.css .external-icon {background-image: var(--icon);background-color: #fff;background-size: cover;color: transparent;padding-left: 1.2rem;border-radius: 0.2rem;margin-left: 0.2rem;}
Example
https://stereobooster.com
https://stereobooster.com