Mark external, absolute links with appropriate rel & target attributes
- Prevents XSS attacks & provides good UX
- Does not affect HTML within markdown
$ npm install --save markdown-it markdown-it-external-anchor
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>
-
domain (default:
null
) - A domain which is considered an internal link.- When domain is provided, localhost is implicit.
-
class (default:
null
) - a class name
This is just a personal project. I do not consider it "released". That said, I'm open to suggestions and contributions.
All source-code is provided under the terms of the MIT license.
Copyright 2025 Binyamin Aron Green.