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

htmlprocessor

v0.3.3

Published

Process html file using special comments

Downloads

25,623

Readme

htmlprocessor

NPM version Build status NPM downloads Cove coverage

npm install -g htmlprocessor

Grunt/Gulp task

This module is the processor behind grunt-processhtml, gulp-processhtml tasks.

For plenty of examples visit the documentation.

CLI

Outputs help

$ htmlprocessor -h
Usage: htmlprocessor file-to-process.html [options]

  -h, --help             display this help message
  -v, --version          display the version number
  -l, --list             file to output list of replaced files
  -o, --output           file to output processed HTML to
  -d, --data             pass a JSON file to processor
  -e, --env              specify an environment
  -r, --recursive        recursive processing
  -c, --comment-marker   change the comment marker
  -i, --include-base     set the directory to include files from
  -s, --strip            strip blocks matched by other environments
  --custom-block-type    specify custom block type

Outputs version number

$ htmlprocessor -v

Outputs to file-to-process.processed.html.

$ htmlprocessor file-to-process.html

Outputs to processed/file.html.

$ htmlprocessor file-to-process.html -o processed/file.html

Pass some data

$ htmlprocessor file-to-process.html -o processed/file.html -d data.json

Specify an environment

$ htmlprocessor file-to-process.html -o processed/file.html -e dev

Allow recursive processing

$ htmlprocessor file-to-process.html -o processed/file.html -r

Change the comment marker to <!-- process --><!-- /process -->

$ htmlprocessor file-to-process.html -o processed/file.html --comment-marker process

List option

Create a list of files that were replaced and use that list to streamline the build process.

Note: This new option does not affect in any way the previous existing functionality (i.e. it's backward compatible).

$ htmlprocessor file-to-process.html -o processed/file.html --list wrk/replacement.list

Assumning you have this code in an HTML (or JSP)

  .
  .
  .
  <!-- build:css content/myApplication.min.css -->
  <link rel="stylesheet" href="js/bower_components/bootstrap/dist/css/bootstrap.css" />
  <link rel="stylesheet" href="content/bootstrap-responsive.min.css" needed />
  <link rel="stylesheet" href="content/styles.css" />
  <link rel="stylesheet" href="content/myApplicationStyles.css" />
  <!--/build-->
  .
  .
  .
  <!-- build:js js/myApplication.min.js -->
  <script src="js/bower_components/jquery/dist/jquery.js"></script>
  <script src="js/bower_components/angular/angular.js"></script>
  <script src="js/bower_components/angular-route/angular-route.js"></script>

  <!-- App libs -->
  <script src="app/app.js"></script>
  <script src="app/filters/filters.js"></script>
  <script src="app/controllers/applications.js"></script>
  <!--/build-->
  .
  .
  .

The file "wrk/replacement.list" will contain something like this:

file-to-process.html:js/bower_components/bootstrap/dist/css/bootstrap.css
file-to-process.html:content/bootstrap-responsive.min.css
file-to-process.html:content/styles.css
file-to-process.html:content/myApplicationStyles.css
file-to-process.html:js/bower_components/jquery/dist/jquery.js
file-to-process.html:js/bower_components/angular/angular.js
file-to-process.html:js/bower_components/angular-route/angular-route.js
file-to-process.html:app/app.js
file-to-process.html:app/filters/filters.js
file-to-process.html:app/controllers/applications.js

And you can use these commands to concatenate and eventually minify without having to update the build to tell it where it should pickup each files. Also, in this way it orders the global file content in the same manner as your individual includes originally were.

sh -c "cat `cat wrk/replacement.list | grep '\.js$' | cut -d: -f2` > dist/js/myApplication.js"
sh -c "cat `cat wrk/replacement.list | grep '\.css$' | cut -d: -f2` > dist/css/myApplication.css"

If you processed more than a single "html" file, you can change the grep like this:

... | grep 'file-to-process.html:.*\.js$' | ... > dist/js/myApplication.js
... | grep 'other-file-to-process.html:.*\.js$' | ... > dist/js/myApplicationOther.js

The originating file name is included in the list file for that very purpose.

License

See LICENSE.txt