Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including html2pug with all npm packages installed. Try it out:

var html2pug = require("html2pug")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

html2pug v4.0.0

Converts HTML to Pug

html2pug Build Status

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

Turns this :unamused:

<!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 :tada:

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, { tabs: true })

Options

NameTypeDefaultDescription
tabsBooleanfalseUse tabs instead of spaces for indentation
commasBooleantrueUse commas to separate node attributes
doubleQuotesBooleanfalseUse double quotes instead of single quotes for attribute values
fragmentBooleanfalseWraps result in enclosing <html> and <body> tags if false
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free