4

I am new to Grunt, trying to find a way to load multiple HTML files and parse them to extract some values.

I tried to use jQuery.parseHTML, HTMLParser but both are not defined. Is there a way to include jQuery or a lib that can parse HTML?

grunt.config.init({
    concat: {
        options: {
            dest: 'tmp',
            templates: ['public/*.html']
        }
    }
});

var recursiveConcat = function(source, result){
    grunt.file.expand(source).forEach(function(file){
        var data = grunt.file.read(file);
        // parse html to dom
        result += data;
    });
    return result;
};
Stacked
  • 6,892
  • 7
  • 57
  • 73
user1560922
  • 267
  • 1
  • 5
  • 19

2 Answers2

2

Cheerio is a DOM parser that I enjoy using. I haven't tried this, but grunt-dom-massager allows you to load Cheerio in your Gruntfile.

Sean Fahey
  • 1,850
  • 3
  • 26
  • 36
0

It looks like writing your own Grunt Task is pretty straightforward. Samples and walkthroughs here and here

then you create a task using htmlparser to manage your process.

However unless you are going to re-use this or pair it with some other grunt task (like grunt-watch) you might find it easier to just create a node script using htmlparser

bknights
  • 14,408
  • 2
  • 18
  • 31