Created
June 24, 2014 11:26
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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