Gathering detailed insights and metrics for rehype-external-links
Gathering detailed insights and metrics for rehype-external-links
Gathering detailed insights and metrics for rehype-external-links
Gathering detailed insights and metrics for rehype-external-links
remark-external-links
Deprecated: this package is no longer maintained. Please use `remark-rehype` to move from remark (markdown) to rehype (HTML) and then replace `remark-external-links` with [`rehype-external-links`][rehype-external-links].
rehype-link-processor
rehype plugin to process links adding custom css class or attributes used by external or download links
rehype-extended-links
Extended link handling for rehype
rehype-smart-links
A rehype plugin for Astro that adds different styling for internal and external links
rehype plugin to add rel (and target) to external links
npm install rehype-external-links
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
106 Stars
38 Commits
5 Forks
7 Watchers
1 Branches
10 Contributors
Updated on Jun 19, 2025
Latest Version
3.0.0
Package Id
rehype-external-links@3.0.0
Unpacked Size
22.76 kB
Size
6.63 kB
File Count
7
NPM Version
9.8.0
Node Version
20.5.1
Published on
Sep 03, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
rehype plugin to add rel
(and target
) to external links.
This package is a unified (rehype) plugin to add rel
(and target
)
attributes to external links.
It is particularly useful when displaying user content on your reputable site,
because users could link to disreputable sources (spam, scams, etc), as search
engines and other bots will discredit your site for linking to them (or
legitimize their sites).
In short: linking to something signals trust, but you can’t trust users.
This plugin adds certain rel
attributes to prevent that from happening.
unified is a project that transforms content with abstract syntax trees
(ASTs).
rehype adds support for HTML to unified.
hast is the HTML AST that rehype uses.
This is a rehype plugin that adds rel
(and target
) to <a>
s in the AST.
This project is useful when you want to display user content from authors you don’t trust (such as comments), as they might include links you don’t endorse, on your website.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install rehype-external-links
In Deno with esm.sh
:
1import rehypeExternalLinks from 'https://esm.sh/rehype-external-links@3'
In browsers with esm.sh
:
1<script type="module"> 2 import rehypeExternalLinks from 'https://esm.sh/rehype-external-links@3?bundle' 3</script>
Say our module example.js
contains:
1import rehypeExternalLinks from 'rehype-external-links' 2import remarkParse from 'remark-parse' 3import remarkRehype from 'remark-rehype' 4import rehypeStringify from 'rehype-stringify' 5import {unified} from 'unified' 6 7const file = await unified() 8 .use(remarkParse) 9 .use(remarkRehype) 10 .use(rehypeExternalLinks, {rel: ['nofollow']}) 11 .use(rehypeStringify) 12 .process('[rehype](https://github.com/rehypejs/rehype)') 13 14console.log(String(file))
…then running node example.js
yields:
1<p><a href="https://github.com/rehypejs/rehype" rel="nofollow">rehype</a></p>
This package exports no identifiers.
The default export is rehypeExternalLinks
.
unified().use(rehypeExternalLinks[, options])
Automatically add rel
(and target
?) to external links.
options
(Options
, optional)
— configurationTransform (Transformer
).
You should likely not configure target
.
You should at least set rel
to ['nofollow']
.
When using a target
, add noopener
and noreferrer
to avoid exploitation
of the window.opener
API.
When using a target
, you should set content
to adhere to accessibility
guidelines by giving users advanced warning when opening a new window.
CreateContent
Create a target for the element (TypeScript type).
element
(Element
)
— element to checkContent to add (Array<Node>
or Node
, optional).
CreateProperties
Create properties for an element (TypeScript type).
element
(Element
)
— element to checkProperties to add (Properties
, optional).
CreateRel
Create a rel
for the element (TypeScript type).
element
(Element
)
— element to checkrel
to use (Array<string>
, optional).
CreateTarget
Create a target
for the element (TypeScript type).
element
(Element
)
— element to checktarget
to use (Target
, optional).
Options
Configuration (TypeScript type).
content
(Array<Node>
, CreateContent
, or Node
,
optional)
— content to insert at the end of external links; will be inserted in a
<span>
element; useful for improving accessibility by giving users
advanced warning when opening a new windowcontentProperties
(CreateProperties
or
Properties
, optional)
— properties to add to the span
wrapping content
properties
(CreateProperties
or
Properties
, optional)
— properties to add to the link itselfprotocols
(Array<string>
, default: ['http', 'https']
)
— protocols to see as external, such as mailto
or tel
rel
(Array<string>
, CreateRel
, or string
,
default: ['nofollow']
)
— link types to hint about the referenced documents; pass an
empty array ([]
) to not set rel
s on links; when using a target
, add noopener
and noreferrer
to avoid exploitation of the window.opener
APItarget
(CreateTarget
or Target
,
optional)
— how to display referenced documents; the default (nothing) is to not set
target
s on linkstest
(Test
, optional)
— extra test to define which external link elements are modified; any test
that can be given to hast-util-is-element
is supportedTarget
Target (TypeScript type).
1type Target = '_blank' | '_parent' | '_self' | '_top'
This package is fully typed with TypeScript.
It exports the additional types
CreateContent
,
CreateProperties
,
CreateRel
,
CreateTarget
,
Options
, and
Target
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, rehype-external-links@^3
,
compatible with Node.js 16.
This plugin works with rehype-parse
version 3+, rehype-stringify
version 3+,
rehype
version 4+, and unified
version 6+.
Improper use of rehype-external-links
can open you up to a
cross-site scripting (XSS) attack.
Either do not combine this plugin with user content or use
rehype-sanitize
.
See contributing.md
in rehypejs/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More