glenlivet-htmltojson
v0.0.1
Published
A Glenlivet plugin that transforms HTML into JSON declaratively.
Downloads
2
Readme
glenlivet-htmltojson
A Glenlivet plugin that transforms HTML into JSON declaratively.
Installation
npm install glenlivet-htmltojson
Usage
var glenlivet = require('glenlivet');
var Bottle = glenlivet.Bottle;
glenlivet.plugins.register(require('glenlivet-htmltojson'));
var getLinks = new Bottle({
htmlToJson: {
"links": function () {
return this.map("a", {
"label": "->text()",
"url": "->attr('href')"
});
}
}
});
getLinks.htmlToJson({
htmlToJson: {
html: '<div><a href="http://www.prolificinteractive.com">Prolific Interactive</a><a href="http://www.github.com">Github</a></div>'
}
}, function (result) {
console.log(result.htmlToJson.json);
});
The resulting json should be:
{
"links": [
{
"label": "Prolific Interactive",
"url": "http://www.prolificinteractive.com"
},
{
"label": "Github",
"url": "http://www.github.com"
}
]
}