Skip to content
This repository has been archived by the owner on Oct 13, 2019. It is now read-only.

ntnyq/gulp-format-html

Repository files navigation

gulp-format-html

Migrated to gulp-plugins

🍺 A simple Gulp plugin for html files formatting.

Install

$ npm install gulp-format-html --save-dev
# OR
$ yarn add gulp-format-html -D

Setup

const gulp = require('gulp')
const formatHtml = require('gulp-format-html')

function views () {
  return (
    gulp
      .src('views/**/*.html')
      .pipe(formatHtml())
      .pipe(gulp.dest('dist'))
  )
}

exports.dev = gulp.series(views)

Example

Input:

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>gulp-format-html</title></head><body><header><h1><span>I am h1 in header</span></h1></header><main><p><span>span</span><b>b</b><strong>strong</strong><em>em</em></p></main><footer><p><a href="https://github.com/ntnyq/gulp-format-html">gulp-format-html</a></p></footer></body></html>

Output:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>gulp-format-html</title>
</head>

<body>
  <header>
    <h1>
      <span>I am h1 in header</span>
    </h1>
  </header>
  <main>
    <p>
      <span>span</span>
      <b>b</b>
      <strong>strong</strong>
      <em>em</em>
    </p>
  </main>
  <footer>
    <p>
      <a href="https://github.com/ntnyq/gulp-format-html">gulp-format-html</a>
    </p>
  </footer>
</body>

</html>

Options

gulp-format-html is based on js-beautify, Check it's HTML options for detail.

verbose

  • type boolean
  • default false

Display name of file from stream that is being formatting

Related

  • gulp-diffable-html Zero config HTML formatter to make HTML more readable and to indent HTML tag text in a single newline.

License

MIT © @ntnyq