Skip to content

Instantly share code, notes, and snippets.

@RichardB01
Created June 24, 2014 11:26
Show Gist options
  • Save RichardB01/6c34e85d3cf4b1998c2b to your computer and use it in GitHub Desktop.
Save RichardB01/6c34e85d3cf4b1998c2b to your computer and use it in GitHub Desktop.
Node script to convert bookmarks html file into a simple html link list. Requires apricot.
var Apricot = require('apricot').Apricot;
var fs = require('fs');
var htmlBuffer = "<ul>";
// Element layout -- TODO --- -- TODO ----
// element = {name="", herf="", add_date="", icon_data=""}
// Useage:
// node main.js FILENAME.html
Apricot.open(process.argv[2], function(err, doc) {
// check for errors
if (err) {
console.log(err);
return false;
}
// iterate through link tags
doc.find("A");
// extract their attributes (i don't know how to get the custom ADD_DATE attribute.)
doc.each(function(el)
{
htmlBuffer += "\n<li><a href='" + el.href + "'>" + el.innerHTML + "</a></li>";
});
// standard html list notation
htmlBuffer += "\n</ul>";
// Writing to file
console.log("Rendering html file...");
fs.writeFile("output.html", htmlBuffer, function(error)
{
if (error) {
console.log(err);
} else {
console.log("Html finished rendering!")
}
})
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment