Skip to content

Convert HTML to Pug in Node.js

We can use the html2pug npm package to convert HTML to Pug in JavaScript / Node.js.

const html2pug = require('html2pug');
html2pug('<h1>Test page</h1>', { tabs: false, fragment: true });

The fragment option tells html2pug whether to wrap your HTML in an tag, if it isn’t already.
fragment is false by default, which means html2pug will always prepend html\n head\n body\n to the output by default.

See also  How to configure npm with npmrc?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.