ineed
Version:
Web scraping and HTML-reprocessing. The easy way.
28 lines (21 loc) • 660 B
JavaScript
var Common = require('../../common'),
SerializationPlugin = require('../serialization');
module.exports = {
name: 'texts',
extends: 'collect',
init: function (ctx, replacer) {
this.ctx = ctx;
this.replacer = replacer;
},
onStartTag: function () {
//NOTE: restore flag for new text tokens
SerializationPlugin.escapeHtml = true;
},
onText: function (text) {
if (Common.isPlainText(this.ctx.inBody, this.ctx.leadingStartTag, text)) {
text = this.replacer(text, Common.escapeHtml);
SerializationPlugin.escapeHtml = false;
}
return text;
}
};