gulp-htmltidy

Node Wrapper for HTML Tidy

gulp-htmltidy

HTML Tidy is an open source program for checking and generating clean XHTML/HTML. It cleans up coding errors in HTML files and fixes bad formatting. It can output files in the HTML, XHTML or XML file format.

Using HTML Tidy, developers can programatically clean up and fix poorly-written HTML pages. Another use is to convert HTML to XHTML or XML. These files can then be easily processed using the tools in the traditional XML chain, such as XSL transforms.

Uses the htmltidy2 library.

/path/to/file.html:

<html>
    <head>
      <style>
        p { color: red; }
      </style> 
    </head>
    <body>
          <!-- ===== body ====== -->
         <p>Test</p>
            
    </body>
        <!--Default Zone
        -->
        <!--Default Zone End-->
</html>

Output:

<!DOCTYPE html>
<html>
<head>
 
<style>
      p { color: red; }
</style> 
<title></title>
</head>
<body>
<p>Test</p>
</body>
</html>
 

Install with npm

npm install --save-dev gulp-htmltidy
var gulp = require('gulp'),
    htmltidy = require('gulp-htmltidy');
 
gulp.task('default', function() {
  return gulp.src('./*.html')
        .pipe(htmltidy())
        .pipe(gulp.dest('build/'));;
});

With options:

var gulp = require('gulp'),
    htmltidy = require('htmltidy');
 
gulp.task('default', function() {
  return gulp.src('./*.html')
        .pipe(htmltidy({doctype: 'html5',
                       hideComments: true,
                       indent: false}))
        .pipe(gulp.dest('build/'));;
});

Clean html like text according optional configuration tidy options.

Type: String

Type: Boolean Default: false

Type: Boolean Default: false