1.1.1 • Published 9 years ago
dom-processor v1.1.1
dom-processor
Simple processor for replacing elements in html using cheerio.
Install
npm install dom-processor --saveExamples
dom-processor
Create a new instance using a config-loader and call the process-method with the content to be processed.
If the loading of your replacement-configurations depends on the currently processed file make sure to call process with the path as second argument.
var configLoader = require('./config-loader');
var DomProcessor = require('dom-processor');
var processor = new DomProcessor(configLoader);
var result = processor.process('<div></div>', 'path/to/file');
console.log(result);config-loader
An object with a load-method which is called with the path of the currently processed file and additional load configurations for cheerio.
The load-method returns an Array of replacement-configurations. Each replacement has two properties:
selector: Selector of the elements to be replaced.replace: Function to create and return the new element. It is called with matching element as first argument.
The loadConfigurations-object cointains configurations for cheerio
function load(filePath) {
return [{
selector: 'div',
replace: function($element) {
return '<span></span>';
}
}];
}
let loadConfigurations = { decodeEntities: false };
module.exports = {
load: load,
loadConfigurations: loadConfigurations
};License
MIT © Benjamin Eckardt