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-htmlentities

v0.1.1

Published

Grunt task for the javascript HE html entities handler

Downloads

4

Readme

grunt-htmlentities

Grunt task for the javascript HE html entities handler. This task can be used to encode an entire file or multiple files.

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-htmlentities --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-htmlentities');

The "htmlentities" task

Overview

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

  htmlentities: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

options.rename

Type: String Default value: ''

A string value that is used to rename the file(s) that you are encoding. If you are encoding multiple files to a single directory, you should not use this option as it will rename and override the previously encoded files, leaving only the last encoded file in the directory.

TODO: Add option to rename with a variable to allow for renaming to a single directory.

options.extname

Type: String Default value: ''

A string value that is used to to add an extension name to the encoded file before the 'html' extension.

options.encodeEverything

Type: Boolean Default value: false

This means that grunt-htmlentities will not use any character references for printable ASCII symbols that don’t need escaping. Set it to true to encode every symbol in the input string. When set to true, this option takes precedence over options.allowUnsafeSymbol

// Default `false` setting
input:
  'foo © bar ≠ baz 𝌆 qux'
output:
  'foo © bar ≠ baz 𝌆 qux'

// Setting to `true`, to explicitly encode all symbols
input:
  'foo © bar ≠ baz 𝌆 qux'
output:
  'foo © bar ≠ baz 𝌆 qux'

options.useNamedReferences

Type: Boolean Default value: true

This means that grunt-htmlentities will use hexadecimal escapes (e.g. ©) in the output — named character references (e.g. ©) will be used instead when available. Set it to true to enable the use of only hexadecimal escapes.

// Default `true` setting
input:
  'foo © bar ≠ baz 𝌆 qux'
output:
  'foo © bar ≠ baz 𝌆 qux'

// Setting to `false`, to explicitly disallow named references
input:
  'foo © bar ≠ baz 𝌆 qux'
output:
  'foo © bar ≠ baz 𝌆 qux'

options.allowUnsafeSymbols

Type: Boolean Default value: false

This means that characters that are unsafe for use in HTML content (&, <, >, ", ', and `) will be encoded. When set to true, only non-ASCII characters will be encoded. If the encodeEverything option is set to true, this option will be ignored.

input:
  'foo © and & ampersand'
output:
  'foo &#xA9; and & ampersand'

options.strict

Type: Boolean Default value: false

This means that grunt-htmlentities will encode any HTML text content you feed it, even if it contains any symbols that cause parse errors. To throw an error when such invalid HTML is encountered, set the strict option to true. This option makes it possible to use he as part of HTML parsers and HTML validators.

Usage Examples

Default Options

In this example, the default options are used to do 2 files into a single directory. The generated result would be dest/encoded/testing.html and dest/encoded/123.html. (Notice that the encoded JavaScript file was converted to an HTML document.)

grunt.initConfig({
  htmlentities: {
    options: {},
    files: {
     src: ['src/testing.html', 'src/123.js'],
     dest: 'dest/encoded/'
  }
  }
});

Custom Options

In this example, custom options are used to do something encode files to their existing directories. The generated result would be src/templates/encoded.tpl.html and src/js/encoded.tpl.html. (Notice that the dest property was omitted.)

grunt.initConfig({
  htmlentities: {
    options: {
    rename: encoded,
    extname: tpl
  },
  src: ['src/templates/testing.html', 'src/js/123.js']
  }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2015-1-22   v0.1.1   Update README.md.
  • 2015-1-20   v0.1.0   Initial release.