rehype-github-link v1.0.0
rehype-github-link
rehype plugin to enhance links.
Contents
- What is this?
- When should I use this?
- Install
- Use
- API
- Bugs
- Authoring
- HTML
- CSS
- Syntax
- Types
- Compatibility
- Security
- Related
- Contribute
- Notice
- License
What is this?
This plugin enhances links by marking them as external.
By default it appends rel="nofollow"
to links that are neither local nor
go to github.com
.
This plugin is part of a monorepo rehype-github
.
See its readme for more info.
When should I use this?
You can use this plugin when you want to match how github.com works or when you want to build similar pipelines that have user content.
Install
This package is ESM only. In Node.js (version 16+), install with npm:
npm install rehype-github-link
In Deno with esm.sh
:
import rehypeGithubLink from 'https://esm.sh/rehype-github-link@1'
In browsers with esm.sh
:
<script type="module">
import rehypeGithubLink from 'https://esm.sh/rehype-github-link@1?bundle'
</script>
Use
Say our module example.js
looks as follows:
import rehypeGithubLink from 'rehype-github-link'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'
const file = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypeGithubLink)
.use(rehypeStringify)
.process('<a href="https://example.com">link</a>')
console.log(String(file))
…now running node example.js
yields:
<a href="https://example.com" rel="nofollow">link</a>
API
This package exports no identifiers.
The default export is
rehypeGithubLink
.
rehypeGithubLink(options?)
Plugin to enhance links.
Parameters
options
(Options
, optional) — configuration
Options
Configuration (TypeScript type).
Fields
internal
(Array<string>
orstring
, default:'github.com'
) — hostname or hostnames to not mark as externalrel
(Array<string>
orstring
, default:'nofollow'
) — relationship(s) of your site to external content, used inrel
; you should probably set['nofollow', 'ugc']
Bugs
There are no bugs with how GitHub does this,
but they could use ['nofollow', 'ugc']
instead.
Authoring
There are no additional recommendations on how to author links in markdown.
HTML
The markup that github.com adds is:
rel="nofollow"
CSS
No CSS is needed.
Syntax
No syntax is applicable.
Types
This package is fully typed with TypeScript.
It exports the additional type Options
.
Compatibility
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 16+. Our projects sometimes work with older versions, but this is not guaranteed.
This plugin works with rehype-parse
version 3+,
rehype-stringify
version 3+,
rehype
version 5+,
and unified
version 6+.
Security
This package is safe.
Related
remark-gfm
— support GFM in remarkrehype-external-links
— similar plugin
Contribute
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.
Notice
This project is not affiliated with GitHub.
License
8 months ago