Add icons to external links
هذا المحتوى غير متوفر بلغتك بعد.
Using a rehype plugin, you can identify and modify links in your Markdown files that point to external sites. This example adds icons to the end of each external link, so that visitors will know they are leaving your site.
Prerequisites
Section titled Prerequisites- An Astro project using Markdown for content pages.
Recipe
Section titled Recipe-
Install the
rehype-external-links
plugin. -
Import the plugin into your
astro.config.mjs
file.Pass
rehypeExternalLinks
to therehypePlugins
array, along with an options object that includes a content property. Set this property’stype
totext
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 propertytype
toraw
.The value of the
content
property is not represented in the accessibility tree. As such, it’s best to make clear that the link is external in the surrounding content, rather than relying on the icon alone.