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

posthtml-parser

Package Overview
Dependencies
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-parser

Parse HTML/XML to PostHTMLTree

  • 0.4.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
185K
decreased by-81.02%
Maintainers
3
Weekly downloads
 
Created

What is posthtml-parser?

The posthtml-parser npm package is a tool used to parse HTML into an Abstract Syntax Tree (AST). This allows developers to manipulate HTML content programmatically, making it easier to perform tasks such as transforming HTML structures, extracting specific elements, and integrating with other tools in the PostHTML ecosystem.

What are posthtml-parser's main functionalities?

Parsing HTML to AST

This feature allows you to parse a string of HTML into an Abstract Syntax Tree (AST). The AST can then be manipulated programmatically.

const parse = require('posthtml-parser');
const html = '<div class="example">Hello World</div>';
const ast = parse(html);
console.log(ast);

Handling HTML fragments

This feature allows you to parse HTML fragments and control parsing options such as whether to convert tag names to lowercase.

const parse = require('posthtml-parser');
const fragment = '<span>Fragment</span>';
const ast = parse(fragment, { lowerCaseTags: false });
console.log(ast);

Integration with PostHTML plugins

This feature demonstrates how to integrate the parser with PostHTML plugins to transform HTML content. In this example, a plugin is used to change all <div> tags to <section> tags.

const posthtml = require('posthtml');
const parse = require('posthtml-parser');
const html = '<div class="example">Hello World</div>';
posthtml()
  .use(tree => {
    tree.match({ tag: 'div' }, node => {
      node.tag = 'section';
      return node;
    });
  })
  .process(html)
  .then(result => console.log(result.html));

Other packages similar to posthtml-parser

Keywords

FAQs

Package last updated on 08 Nov 2019

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