blob: b86681456e40b22be514059fb2fe14d531a9532e (
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} page
* @param {List|Array<Transformation>} operations
* @return {Promise<Page>} page
*/
function modifyHTML(page, operations) {
const html = page.getContent();
const $ = cheerio.load(html);
return Promise.forEach(operations, (op) => {
return op($);
})
.then(() => {
const resultHTML = $.html();
return page.set('content', resultHTML);
});
}
module.exports = modifyHTML;
|