Build a HTML5 to PUG Code Converter in Node.js and Javascript Using html2pug Library Full Project For Beginners

 

 

html2pug Build Status

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

 

 

index.html

 

 

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

 

 

index.pug

 

 

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.

See also  Build P2P (Peer to Peer) Video and Text Chat in Javascript Using Simple Peer and WebRTC Full Tutorial

Programmatically

const html2pug = require('html2pug')

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

Options

Name Type Default Description
tabs Boolean false Use tabs instead of spaces for indentation
commas Boolean true Use commas to separate node attributes
doubleQuotes Boolean false Use double quotes instead of single quotes for attribute values
fragment Boolean false Wraps result in enclosing <html> and <body> tags if false
See also  Build a Stylish Arithmetic Calculator Using HTML5 CSS3 and Javascript With Background Image Full Project For Beginners

 

Leave a Reply