About rehype-smart-links

rehype-smart-links is a rehype plugin designed to enhance links in Markdown documents. It adds smart navigation and styling features to help users distinguish between different types of links, improving the document reading experience.

Features

The plugin automatically detects and categorizes links into three types:

  • Internal Links - Links pointing to pages within your website
  • External Links - Links pointing to other websites
  • Broken Links - Links pointing to non-existent pages

2. Class Names and Attribute Addition

The plugin adds specific class names and attributes to different types of links:

HTML
<!-- Internal link -->
<a href="/about" class="internal-link">About Page</a>

<!-- External link -->
<a href="https://example.com" class="external-link" target="_blank" rel="noopener noreferrer">Example Website</a>

<!-- Broken link -->
<a href="/non-existent" class="broken-link">Non-existent Page</a>

3. Customization Options

The plugin provides a rich set of customization options that allow you to adjust link handling behavior according to your needs:

OptionTypeDefaultDescription
internalLinkClassstring'internal-link'Class name for internal links
externalLinkClassstring'external-link'Class name for external links
brokenLinkClassstring'broken-link'Class name for broken links
openExternalbooleantrueWhether to open external links in a new tab
internalLinksstring[][]List of specific domains to mark as internal links
includeFileExtensionsstring[]['md', 'html']File extensions to include in route checking

Use Cases

rehype-smart-links is suitable for various projects using Markdown:

  • Documentation Sites - Enhance document navigation experience
  • Blog Platforms - Improve link usability in blog posts
  • Knowledge Bases - Better link accessibility in knowledge base content

Getting Started

Check out our Quick Start guide to learn how to use rehype-smart-links in your project.

Examples

Contributing

We welcome community contributions! If you have any questions or suggestions, please submit an issue or pull request to the GitHub repository.

Related Links Astro Tailwind CSS DaisyUI
Resources GitHub NPM