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

rehype-parse

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-parse

HTML parser for rehype

  • 4.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is rehype-parse?

rehype-parse is a plugin for the unified processor that parses HTML into a syntax tree. It is part of the rehype ecosystem, which is a toolset for transforming HTML with plugins. This package is particularly useful for processing and manipulating HTML content programmatically.

What are rehype-parse's main functionalities?

Basic HTML Parsing

This feature allows you to parse a simple HTML string into a syntax tree. The code sample demonstrates how to parse an HTML string and inspect the resulting tree structure.

const unified = require('unified');
const parse = require('rehype-parse');
const inspect = require('unist-util-inspect');

const html = '<h1>Hello, world!</h1>';
const tree = unified()
  .use(parse)
  .parse(html);

console.log(inspect(tree));

Parsing with Options

This feature allows you to parse HTML with specific options. In this example, the 'fragment' option is set to true, which allows parsing of HTML fragments instead of full documents.

const unified = require('unified');
const parse = require('rehype-parse');
const inspect = require('unist-util-inspect');

const html = '<h1>Hello, world!</h1>';
const tree = unified()
  .use(parse, { fragment: true })
  .parse(html);

console.log(inspect(tree));

Integration with Other Plugins

This feature demonstrates how to integrate rehype-parse with other plugins in the rehype ecosystem. The code sample shows how to parse HTML and then stringify it back to HTML.

const unified = require('unified');
const parse = require('rehype-parse');
const stringify = require('rehype-stringify');

const html = '<h1>Hello, world!</h1>';
const output = unified()
  .use(parse)
  .use(stringify)
  .processSync(html)
  .toString();

console.log(output);

Other packages similar to rehype-parse

Keywords

FAQs

Package last updated on 18 Jun 2017

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