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

posthtml

Package Overview
Dependencies
Maintainers
3
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml

HTML/XML post processor

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
305K
decreased by-56.79%
Maintainers
3
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 23 Sep 2015

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