What is remark-external-links?
The remark-external-links package is a plugin for the Remark Markdown processor that automatically modifies links in Markdown files. It is primarily used to add attributes like target and rel to external links, enhancing security and usability without manual HTML tagging.
Adding attributes to external links
This feature allows users to automatically add specific attributes such as target='_blank' and rel='nofollow noopener noreferrer' to external links in Markdown content. This enhances security by preventing tabnapping and improves SEO through 'nofollow'. The code sample demonstrates how to set up the plugin with Remark to process a simple Markdown string.
const remark = require('remark');
const html = require('remark-html');
const externalLinks = require('remark-external-links');
remark()
.use(externalLinks, {target: '_blank', rel: ['nofollow', 'noopener', 'noreferrer']})
.use(html)
.process('Check out [Google](https://google.com)!', function (err, file) {
console.log(String(file));
});