blob: 00177fc8805854a2f617bc60d52c78afecf9953e (
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
|
const cheerio = require('cheerio');
const 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) {
const html = page.getContent();
const $ = cheerio.load(html);
return Promise.forEach(operations, function(op) {
return op($);
})
.then(function() {
const resultHTML = $.html();
return page.set('content', resultHTML);
});
}
module.exports = modifyHTML;
|