summaryrefslogtreecommitdiffstats
path: root/lib/output/modifiers/modifyHTML.js
blob: cd3d6e5b4b77cea1565cd34835f2a1f23878e0d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var cheerio = require('cheerio');
var Promise = require('../../utils/promise');

/**
    Apply a list of operations to a page and
    output the new page.

    @param {Page}
    @param {List|Array<Transformation>}
    @return {Promise<Page>}
*/
function modifyHTML(page, operations) {
    var html = page.getContent();
    var $ = cheerio.load(html);

    return Promise.forEach(operations, function(op) {
        return op($);
    })
    .then(function() {
        var resultHTML = $.html();
        return page.set('content', resultHTML);
    });
}

module.exports = modifyHTML;