Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype

HTML processor powered by plugins part of the unified collective

  • 13.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is rehype?

Rehype is a powerful HTML processor built on the unified framework. It allows you to parse, transform, and stringify HTML content. It is highly extensible and can be used for a variety of tasks such as sanitizing HTML, extracting content, and transforming HTML structures.

What are rehype's main functionalities?

Parsing HTML

Rehype can parse HTML strings into a syntax tree, which can then be manipulated or analyzed.

const rehype = require('rehype');
const html = '<h1>Hello, world!</h1>';
rehype().parse(html);

Transforming HTML

Rehype allows you to transform HTML content by manipulating the syntax tree. You can use plugins or custom functions to modify the tree.

const rehype = require('rehype');
const html = '<h1>Hello, world!</h1>';
rehype()
  .use(() => (tree) => {
    // Transform the tree
  })
  .process(html)
  .then((file) => {
    console.log(String(file));
  });

Stringifying HTML

Rehype can convert a syntax tree back into an HTML string, allowing you to output the transformed content.

const rehype = require('rehype');
const tree = { type: 'root', children: [{ type: 'element', tagName: 'h1', properties: {}, children: [{ type: 'text', value: 'Hello, world!' }] }] };
rehype().stringify(tree);

Sanitizing HTML

Rehype can be used to sanitize HTML content, removing potentially dangerous elements and attributes.

const rehype = require('rehype');
const rehypeSanitize = require('rehype-sanitize');
const html = '<script>alert("Hello, world!")</script><p>Safe content</p>';
rehype()
  .use(rehypeSanitize)
  .process(html)
  .then((file) => {
    console.log(String(file));
  });

Other packages similar to rehype

Keywords

FAQs

Package last updated on 27 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc