Skip to content

binyamin/markdown-it-external-anchor

MarkdownIt External Anchor

npm bundle size CI Test

Mark external, absolute links with appropriate rel & target attributes

  • Prevents XSS attacks & provides good UX
  • Does not affect HTML within markdown

Usage

Install

$ npm install --save markdown-it markdown-it-external-anchor

Example

import md from 'markdown-it';
import pluginExternalAnchor from 'markdown-it-external-anchor';

md.use(pluginExternalAnchor, {
    domain: 'example.net',
    class: 'external'
});

md.render('[text](https://example.com)'); // => <a href="https://example/com" rel="noopener noreferrer" target="_blank">text</a>

Options

  • domain (default: null) - A domain which is considered an internal link.
    • When domain is provided, localhost is implicit.
  • class (default: null) - a class name

Maintenance

This is just a personal project. I do not consider it "released". That said, I'm open to suggestions and contributions.

Legal

All source-code is provided under the terms of the MIT license.

Copyright 2025 Binyamin Aron Green.

About

Mark external, absolute links with necessary attributes

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 3

  •  
  •  
  •