npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-prettify

v0.4.0

Published

HTML prettifier with options to format HTML according to your own preferences.

Downloads

31,402

Readme

grunt-prettify NPM version

HTML prettifier with options to format HTML according to your own preferences.

Install

Install with npm:

npm i grunt-prettify --save-dev

Once the plugin has been installed, add the following line to your Gruntfile:

grunt.loadNpmTasks('grunt-prettify');

Overview

In your project's Gruntfile, add a section named prettify to the data object passed into grunt.initConfig().

grunt.initConfig({
  prettify: {
    options: {
      // Task-specific options go here.
    },
    html: {
      // Target-specific file lists and/or options go here.
    }
  }
});

Options

config

Type: String Default value: null

Path to .jsbeautifyrc. If this option is specified, options defined therein will be used. The .jsbeautifyrc file must be valid JSON and looks something like this:

{
  "indent": 4,
  "condense": true,
  "indent_inner_html": true,
  "unformatted": [
    "a",
    "pre"
  ]
}

Note that options defined in .jsbeautifyrc override the default options, and options defined in the Gruntfile override all other options.

condense

Type: Boolean Default value: true

Removes extra newlines and retains indenting.

preserveBOM

Type: Boolean Default value: false

Preserve byte-order marks that might exist. Also see the Grunt.js source.

padcomments

Type: Boolean|Number Default value: false

Add newlines above each code comment. For backwards compatibility, you may set to true to add a single newline, or specify the number of newlines you want to add.

indent

Type: Number Default value: 2

The indentation size to be used on the output HTML. This is an alias for indent_size. So either indent or indent_size may be used.

indent_char

Type: String Default value: ' ' (space) Options: space|tab (use an actual space or tab, not the word)

Character with which to indent the output HTML.

indent_scripts

Type: String Default value: keep Options: keep|separate|normal

The indentation character to use to indent the output HTML.

indent_inner_html

Type: Boolean Default value: true

Indent <body></body> and <head></head> sections.

brace_style

Type: String Default value: expand

Options:

  • collapse: (default) puts braces on the same line as control statements
  • expand: put all braces on their own lines (Allman / ANSI style)
  • end-expand: put end braces only on their own line.

wrap_line_length

Type: Number Default value: 0 (disabled)

Maximum characters per line. 0 disables, max is 250.

preserve_newlines

Type: Boolean Default value: false

Preserve existing line-breaks.

max_preserve_newlines

Type: Number Default value: unlimited

Maximum number of consecutive line-breaks to be preserved.

unformatted

Type: String|Array Default value: ["pre", "code"]

Array of tags that should not be re-formatted in the output. Defaults to inline.

Attention: Make sure you play around with the settings and view the HTML in the browser. Pay special attention to whitespace around links and other inline elements, such as <strong> and <span>. If you specify a list of elements to remain unformatted, you will definitely need to make sure that whitepace is rendering the way you want it to.

Usage Examples

Default Options

The default setup in this project's Gruntfile uses an external .prettifyrc file for controlling the task's options.

grunt.initConfig({
  prettify: {
    options: {
      config: '.prettifyrc'
    },
    files: {
      'pretty/index.html': ['ugly/index.html']
    }
  }
});

The default options are set to:

{
  "indent": 2,
  "indent_char": " ",
  "indent_scripts": "normal",
  "wrap_line_length": 0,
  "brace_style": "collapse",
  "preserve_newlines": true,
  "max_preserve_newlines": 1,
  "unformatted": [
    "a",
    "code",
    "pre"
  ]
}

Custom Options

You can also specify the options in the Gruntfile if you wish, like this:

prettify: {
  options: {
    indent: 2,
    indent_char: ' ',
    wrap_line_length: 78,
    brace_style: 'expand',
    unformatted: ['a', 'sub', 'sup', 'b', 'i', 'u']
  },
  ...
}

Example configurations for prettifying one file at a time, or entire directories of files:

prettify: {
  options: {
    config: '.prettifyrc'
  },
  // Prettify a directory of files
  all: {
    expand: true,
    cwd: 'test/actual/ugly/',
    ext: '.html',
    src: ['*.html'],
    dest: 'test/actual/pretty/'
  },
  // Or prettify one file at a time using the "files object" format
  files: {
    'pretty/index.html': ['ugly/index.html']
  },
  // Or the "compact" src-dest format
  one: {
    src: 'test/actual/ugly/index.html',
    dest: 'test/actual/pretty/index.html'
  }
}

See the [grunt][] docs for more information about task configuration.

Author

jonschlinkert

License

Copyright (c) 2014 jonschlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on October 10, 2014.