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

rehype-stringify

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-stringify

rehype plugin to serialize HTML

  • 10.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
875K
increased by4.76%
Maintainers
3
Weekly downloads
 
Created

What is rehype-stringify?

rehype-stringify is a plugin for the rehype ecosystem that compiles a syntax tree into HTML. It is typically used in conjunction with other rehype plugins to process and transform HTML content.

What are rehype-stringify's main functionalities?

Basic HTML Stringification

This feature allows you to convert an HTML string into a syntax tree and then back into an HTML string. It demonstrates the basic usage of rehype-stringify in a unified pipeline.

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

const html = '<h1>Hello, world!</h1>';

unified()
  .use(rehypeParse)
  .use(rehypeStringify)
  .process(html)
  .then((file) => {
    console.log(String(file));
  });

Transforming HTML

This feature demonstrates how you can transform HTML content by modifying the syntax tree before stringifying it back to HTML. In this example, the text inside the <h1> tag is changed from 'Hello, world!' to 'Hello, universe!'.

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

const html = '<h1>Hello, world!</h1>';

unified()
  .use(rehypeParse)
  .use(() => (tree) => {
    tree.children[0].children[0].value = 'Hello, universe!';
  })
  .use(rehypeStringify)
  .process(html)
  .then((file) => {
    console.log(String(file));
  });

Other packages similar to rehype-stringify

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