Package Exports
- remark-external-links
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (remark-external-links) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
remark-external-links
remark plugin to automatically add target
and rel
attributes
to external links.
Note!
This plugin is ready for the new parser in remark
(remarkjs/remark#536
).
The current and previous versions of the plugin work with the current and
previous versions of remark.
Install
This package is ESM only:
Node 12+ is needed to use it and it must be import
ed instead of require
d.
npm:
npm install remark-external-links
Use
Say we have the following file, example.js
:
import {remark} from 'remark'
import remarkHtml from 'remark-html'
import remarkExternalLinks from 'remark-external-links'
remark()
.use(remarkExternalLinks, {target: false, rel: ['nofollow']})
.use(remarkHtml)
.process('[remark](https://github.com/remarkjs/remark)')
.then((file) => {
console.log(String(file))
})
Now, running node example
yields:
<p><a href="https://github.com/remarkjs/remark" rel="nofollow">remark</a></p>
API
This package exports no identifiers.
The default export is remarkExternalLinks
.
unified().use(remarkExternalLinks[, options])
Automatically add target
and rel
attributes to external links.
options
options.target
How to display referenced documents (string?
: _self
, _blank
, _parent
,
or _top
, default: _blank
).
Pass false
to not set target
s on links.
options.rel
Link types to hint about the referenced documents (Array.<string>
or string
, default: ['nofollow', 'noopener', 'noreferrer']
).
Pass false
to not set rel
s on links.
When using a
target
, addnoopener
andnoreferrer
to avoid exploitation of thewindow.opener
API.
options.protocols
Protocols to check, such as mailto
or tel
(Array.<string>
, default:
['http', 'https']
).
options.content
hast content to insert at the end of external links
(Node or Children).
Will be inserted in a <span>
element.
Useful for improving accessibility by giving users advanced warning when opening a new window.
options.contentProperties
Properties
to add to the span
wrapping content
, when
given.
Security
options.content
is used and injected into the tree when it’s given.
This could open you up to a cross-site scripting (XSS) attack if you pass
user provided content in.
This may become a problem if the Markdown later transformed to rehype (hast) or opened in an unsafe Markdown viewer.
Most likely though, this plugin will instead protect you from exploitation of
the window.opener
API.
Contribute
See contributing.md
in remarkjs/.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.