Comparing version 0.1.0 to 0.2.0
@@ -25,2 +25,5 @@ var htmlparser = require('htmlparser2'); | ||
attribs[attr] = url.resolve(base, attribs[attr]); | ||
if (options.decorator) { | ||
attribs[attr] = options.decorator(attribs[attr]); | ||
} | ||
} | ||
@@ -27,0 +30,0 @@ }); |
{ | ||
"name": "absolution", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "absolution accepts HTML and a base URL, and returns HTML with absolute URLs. Great for generating valid RSS feeds.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,4 +27,14 @@ # absolution | ||
If you want to do further processing of each absolute URL, you can also pass a decorator function: | ||
var clean = absolution(dirty, 'http://example.com', { | ||
decorator: function(url) { | ||
return 'http://mycoolthing.com?url=' + encodeURIComponent(url); | ||
} | ||
}); | ||
## Changelog | ||
0.2.0: decorator option added. | ||
0.1.0: initial release. | ||
@@ -31,0 +41,0 @@ |
@@ -35,3 +35,10 @@ var assert = require("assert"); | ||
}); | ||
it('should support the decorator option', function() { | ||
assert.equal(absolution('<a href="../peer.html">Test</a>', 'http://example.com/child/', { | ||
decorator: function(url) { | ||
return 'http://test.com?url=' + encodeURIComponent(url); | ||
} | ||
}), '<a href="http://test.com?url=http%3A%2F%2Fexample.com%2Fpeer.html">Test</a>'); | ||
}); | ||
}); | ||
11133
104
51