title: Modifying a HTML file in NodeJS
body: <p>Let me preface with two things.  I am currently using grunt for these tasks and I also know about Yeoman which has what I am asking for.  I do really like Yeoman however it is just a little too opinionated for this particular project I am working on.</p>
  
  <p>So I have the following HTML file:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;meta name="description" content=""&gt;
          &lt;meta name="viewport" content="width=device-width"&gt;
  
          &lt;!-- START-CSS-MIN:css/build/min.css --&gt;
          &lt;link rel="stylesheet" href="css/bootstrap/bootstrap-2.1.1.css"&gt;
          &lt;link rel="stylesheet" href="css/normalize.css"&gt;
          &lt;link rel="stylesheet" href="css/boilerplate.css"&gt;
          &lt;!-- END-CSS-MIN --&gt;
  
          &lt;!-- START-JS-MIN:js/build/modernizr.js --&gt;
          &lt;script src="js/libraries/modernizr.js"&gt;&lt;/script&gt;
          &lt;!-- END-JS-MIN --&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;!--[if lt IE 7]&gt;
              &lt;p class="chromeframe"&gt;You are using an outdated browser. &lt;a href="http://browsehappy.com/"&gt;Upgrade your browser today&lt;/a&gt; or &lt;a href="http://www.google.com/chromeframe/?redirect=true"&gt;install Google Chrome Frame&lt;/a&gt; to better experience this site.&lt;/p&gt;
          &lt;![endif]--&gt;
  
          &lt;p&gt;Hello world! This is a basline HTML5 template (based on HTML5 Boilerplate).&lt;/p&gt;
  
          &lt;!-- START-JS-MIN:js/build/libraries.js --&gt;
          &lt;script src="js/libraries/underscore.js"&gt;&lt;/script&gt;
          &lt;script src="js/libraries/jquery/jquery.js"&gt;&lt;/script&gt;
          &lt;!-- END-JS-MIN --&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now you can see the CSS-MIN and JS-MIN comments.  Right now I already have a custom grunt build task that properly collects all those files in the comments (using htmlparser) and then minifies and concats them as directly based on the comments.  The last step in the build process is to create a new version of that HTML file (for production use) that replaces the comments with the new file.  For example, the code above would be turned into this:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;meta name="description" content=""&gt;
          &lt;meta name="viewport" content="width=device-width"&gt;
  
          &lt;link rel="stylesheet" href="css/build/min.css"&gt;
  
          &lt;script src="js/build/modernizr.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;!--[if lt IE 7]&gt;
              &lt;p class="chromeframe"&gt;You are using an outdated browser. &lt;a href="http://browsehappy.com/"&gt;Upgrade your browser today&lt;/a&gt; or &lt;a href="http://www.google.com/chromeframe/?redirect=true"&gt;install Google Chrome Frame&lt;/a&gt; to better experience this site.&lt;/p&gt;
          &lt;![endif]--&gt;
  
          &lt;p&gt;Hello world! This is a basline HTML5 template (based on HTML5 Boilerplate).&lt;/p&gt;
  
          &lt;script src="js/build/libraries.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The question I have is how would I be able to do this in NodeJS?  The htmlparser NPM module is great for parsing HTML however I now need something where I am modifying the HTML (removing and adding certain elements in specific locations).  Is there any good packages/tutorials on how to do this in NodeJS code?</p>