ineed
Version:
Web scraping and HTML-reprocessing. The easy way.
24 lines (18 loc) • 557 B
JavaScript
var url = require('url'),
Common = require('../../common');
module.exports = {
name: 'hyperlinks',
extends: 'reprocess',
init: function (ctx, replacer) {
this.ctx = ctx;
this.replacer = replacer;
},
onStartTag: function (startTag) {
if (startTag.tagName === 'a') {
var href = Common.getAttrValue(startTag.attrs, 'href') || '';
href = this.replacer(this.ctx.baseUrl, href);
Common.setAttrValue(startTag.attrs, 'href', href);
}
return startTag;
}
};