Socket
Socket
Sign inDemoInstall

hast-util-from-parse5

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hast-util-from-parse5

hast utility to transform from Parse5’s AST


Version published
Weekly downloads
3.7M
increased by2.07%
Maintainers
2
Weekly downloads
 
Created

What is hast-util-from-parse5?

The `hast-util-from-parse5` package is a utility that converts a Parse5 AST (Abstract Syntax Tree) to a HAST (Hypertext Abstract Syntax Tree). This is particularly useful for working with HTML in a structured way, allowing for transformations, analysis, and manipulation of HTML content.

What are hast-util-from-parse5's main functionalities?

Convert Parse5 AST to HAST

This feature allows you to convert a Parse5 AST to a HAST. The code sample demonstrates parsing an HTML string into a Parse5 AST and then converting it to a HAST.

const parse5 = require('parse5');
const fromParse5 = require('hast-util-from-parse5');

const html = '<!doctype html><html><head><title>Example</title></head><body><p>Hello, world!</p></body></html>';
const parse5Ast = parse5.parse(html);
const hast = fromParse5(parse5Ast);

console.log(JSON.stringify(hast, null, 2));

Convert Parse5 Fragment to HAST

This feature allows you to convert a Parse5 fragment to a HAST. The code sample demonstrates parsing an HTML fragment into a Parse5 fragment and then converting it to a HAST.

const parse5 = require('parse5');
const fromParse5 = require('hast-util-from-parse5');

const htmlFragment = '<p>Hello, world!</p>';
const parse5Fragment = parse5.parseFragment(htmlFragment);
const hastFragment = fromParse5(parse5Fragment);

console.log(JSON.stringify(hastFragment, null, 2));

Other packages similar to hast-util-from-parse5

Keywords

FAQs

Package last updated on 16 Feb 2023

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