Skip to content
Converts HTML to Pug 🐶
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.eslintrc.yml
.gitignore
.prettierignore
.prettierrc.toml
CHANGELOG.md
LICENSE
README.md
package-lock.json
package.json
test.js

README.md

html2pug

Converts HTML to Pug templating language (formerly Jade).
Requires Node.js version 7.6 or higher.

Turns this 😒

<!doctype html>
<html lang="en">
  <head>
    <title>Hello World!</title>
  </head>
  <body>
    <div id="content">
      <h1 class="title">Hello World!</h1>
    </div>
  </body>
</html>

Into this 🎉

doctype html
html(lang='en')
  head
    title Hello World!
   body
    #content
      h1.title Hello World!

Install

Get it on npm:

npm install -g html2pug

Usage

CLI

Accept input from a file or stdin and write to stdout:

# choose a file
html2pug < example.html

# use pipe
echo '<h1>foo</h1>' | html2pug -f

Write output to a file:

html2pug < example.html > example.pug

See html2pug --help for more information.

Programmatically

const html2pug = require('html2pug')

const html = '<header><h1 class="title">Hello World!</h1></header>'
const pug = html2pug(html, { useTabs: true })

Options

Name Type Default Description
useTabs Boolean false Use tabs instead of spaces
useCommas Boolean true Use commas to separate node attributes, or a space if false
isFragment Boolean false Wraps result in enclosing <html> and <body> tags if false
You can’t perform that action at this time.