mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
26 lines
581 B
JavaScript
26 lines
581 B
JavaScript
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;
|