Gathering detailed insights and metrics for rehype
Gathering detailed insights and metrics for rehype
Gathering detailed insights and metrics for rehype
Gathering detailed insights and metrics for rehype
HTML processor powered by plugins part of the @unifiedjs collective
npm install rehype
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,831 Stars
345 Commits
91 Forks
12 Watching
1 Branches
46 Contributors
Updated on 27 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
2.6%
96,512
Compared to previous day
Last week
3.8%
524,855
Compared to previous week
Last month
10.5%
2,145,169
Compared to previous month
Last year
116.9%
19,680,551
Compared to previous year
4
rehype is a tool that transforms HTML with plugins. These plugins can inspect and change the HTML. You can use rehype on the server, the client, CLIs, deno, etc.
rehype is an ecosystem of plugins that work with HTML as structured data, specifically ASTs (abstract syntax trees). ASTs make it easy for programs to deal with HTML. We call those programs plugins. Plugins inspect and change trees. You can use the many existing plugins or you can make your own.
unifiedjs.com
With this project and a plugin, you can turn this HTML:
1<!doctype html> 2<html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <title>Saturn</title> 6 </head> 7 <body> 8 <h1>Saturn</h1> 9 <p>Saturn is a gas giant composed predominantly of hydrogen and helium.</p> 10 </body> 11</html>
…into the following HTML:
1<!doctypehtml><html lang=en><meta charset=utf8><title>Saturn</title><h1>Saturn</h1><p>Saturn is a gas giant composed predominantly of hydrogen and helium.
1import rehypeParse from 'rehype-parse' 2import rehypePresetMinify from 'rehype-preset-minify' 3import rehypeStringify from 'rehype-stringify' 4import {unified} from 'unified' 5 6const file = await unified() 7 .use(rehypeParse) 8 .use(rehypePresetMinify) 9 .use(rehypeStringify).process(`<!doctype html> 10<html lang="en"> 11 <head> 12 <meta charset="utf-8"> 13 <title>Saturn</title> 14 </head> 15 <body> 16 <h1>Saturn</h1> 17 <p>Saturn is a gas giant composed predominantly of hydrogen and helium.</p> 18 </body> 19</html>`) 20 21console.log(String(file))
With another plugin, you can turn this HTML:
1<h1>Hi, Saturn!</h1>
…into the following HTML:
1<h2>Hi, Saturn!</h2>
1/** 2 * @import {Root} from 'hast' 3 */ 4 5import rehypeParse from 'rehype-parse' 6import rehypeStringify from 'rehype-stringify' 7import {unified} from 'unified' 8import {visit} from 'unist-util-visit' 9 10const file = await unified() 11 .use(rehypeParse, {fragment: true}) 12 .use(myRehypePluginToIncreaseHeadings) 13 .use(rehypeStringify) 14 .process('<h1>Hi, Saturn!</h1>') 15 16console.log(String(file)) 17 18function myRehypePluginToIncreaseHeadings() { 19 /** 20 * @param {Root} tree 21 */ 22 return function (tree) { 23 visit(tree, 'element', function (node) { 24 if (['h1', 'h2', 'h3', 'h4', 'h5'].includes(node.tagName)) { 25 node.tagName = 'h' + (Number(node.tagName.charAt(1)) + 1) 26 } 27 }) 28 } 29}
You can use rehype for many different things. unified is the core project that transforms content with ASTs. rehype adds support for HTML to unified. hast is the HTML AST that rehype uses.
This GitHub repository is a monorepo that contains the following packages:
rehype-parse
— plugin to take HTML as input and turn it into a syntax tree (hast)rehype-stringify
— plugin to take a syntax tree (hast) and turn it into HTML as outputrehype
— unified
, rehype-parse
, and rehype-stringify
, useful when input and
output are HTMLrehype-cli
— CLI around rehype
to inspect and format HTML in scriptsDepending on the input you have and output you want, you can use different parts
of rehype.
If the input is HTML, you can use rehype-parse
with unified
.
If the output is HTML, you can use rehype-stringify
with unified
If both the input and output are HTML, you can use rehype
on its own.
When you want to inspect and format HTML files in a project, you can use
rehype-cli
.
rehype plugins deal with HTML. You can choose from the many plugins that already exist. Here are three good ways to find plugins:
awesome-rehype
— selection of the most awesome projectsrehype-plugin
topic
— any tagged repo on GitHubSome plugins are maintained by us here in the @rehypejs
organization while
others are maintained by folks elsewhere.
Anyone can make rehype plugins, so as always when choosing whether to include
dependencies in your project, make sure to carefully assess the quality of
rehype plugins too.
The rehype organization and the unified collective as a whole is fully typed
with TypeScript.
Types for hast are available in @types/hast
.
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 compatible with Node.js 16.
As improper use of HTML can open you up to a cross-site scripting (XSS)
attacks, use of rehype can also be unsafe.
Use rehype-sanitize
to make the tree safe.
Use of rehype plugins could also open you up to other attacks. Carefully assess each plugin and the risks involved in using them.
For info on how to submit a report, see our security policy.
See contributing.md
in rehypejs/.github
for ways
to get started.
See support.md
for ways to get help.
Join us in Discussions to chat with the community and contributors.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
Support this effort and give back by sponsoring on OpenCollective!
Vercel |
Motif |
HashiCorp |
GitBook |
Gatsby | |||||
Netlify |
Coinbase |
ThemeIsle |
Expo |
Boost Note |
Markdown Space |
Holloway | |||
You? |
No vulnerabilities found.
Reason
13 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
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 9/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
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 2024-11-18
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