Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thzinc/5354777 to your computer and use it in GitHub Desktop.
Save thzinc/5354777 to your computer and use it in GitHub Desktop.
jQuery-based JavaScript to add numbers to each <li/> element in a document. (Particularly useful for HTML generated by FreeMind)
(function($) {
$("li").each(function(i, e) {
var current = $(e);
var parent = current.parents("li");
var id = [];
if (parent.length) {
id = parent.data("id").map(function(e) { return e; });
id.push(current.prevAll("li").length + 1);
}
current.data("id", id);
if (id.length) {
current.prepend(["[", id.join("."), "] "].join(""));
}
});
$("a[href]").each(function(i, e) {
var current = $(e);
var target = $(current.attr("href"));
if (target.length) {
current.text(["(Depends on [", target.data("id").join("."), "] ", target.children(".nodecontent").text(), ")"].join(""));
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment