Convert HTML to Pug

Sep 15, 2021

To convert your HTML files to Pug, you can use the html2pug npm package. The html2pug package currently only works in Node.js, so you need an API endpoint if you want to use it from a browser app. Below is an example of using html2pug in Node.js.

const html2pug = require('html2pug');

// h1 Hello, World
html2pug('<h1>Hello, World</h1>', { tabs: false, fragment: true });

The fragment option tells html2pug whether to wrap your HTML in an <html> 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.

Below is a live converter that uses html2pug.

More Node Tutorials