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

posthtml

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml

HTML/XML processor

  • 0.16.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
751K
decreased by-3.34%
Maintainers
2
Weekly downloads
 
Created

What is posthtml?

PostHTML is a tool for transforming HTML/XML with JavaScript plugins. It allows you to process HTML files using a variety of plugins to perform tasks such as minification, templating, and more.

What are posthtml's main functionalities?

HTML Transformation

This feature allows you to transform HTML elements. In this example, all <div> tags are transformed into <span> tags.

const posthtml = require('posthtml');
const html = '<div class="foo">Hello World</div>';

posthtml()
  .use(tree => {
    tree.match({ tag: 'div' }, node => {
      node.tag = 'span';
      return node;
    });
  })
  .process(html)
  .then(result => console.log(result.html));

HTML Minification

This feature allows you to minify HTML content. The example demonstrates how to collapse whitespace in the HTML string.

const posthtml = require('posthtml');
const html = '<div class="foo">  Hello World  </div>';
const posthtmlMinifier = require('posthtml-minifier');

posthtml([posthtmlMinifier({ collapseWhitespace: true })])
  .process(html)
  .then(result => console.log(result.html));

Templating

This feature allows you to use templating within your HTML. The example shows how to replace a placeholder with a dynamic value.

const posthtml = require('posthtml');
const expressions = require('posthtml-expressions');
const html = '<div>{{ message }}</div>';

posthtml([expressions({ locals: { message: 'Hello World' } })])
  .process(html)
  .then(result => console.log(result.html));

Other packages similar to posthtml

Keywords

FAQs

Package last updated on 25 Feb 2022

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