Skip to content

Instantly share code, notes, and snippets.

@penguinpowernz
Created September 1, 2014 20:56
Show Gist options
  • Save penguinpowernz/12c6388b968cbba0e917 to your computer and use it in GitHub Desktop.
Save penguinpowernz/12c6388b968cbba0e917 to your computer and use it in GitHub Desktop.
Some javascript to give numbers to headings on a gollum page
function incr_index(index, depth) {
parts = index.split(".");
part = parts[depth - 1];
part = (typeof part == undefined) ? 0 : (part*1)+1;
parts[depth - 1] = part;
for ( var i=depth ; i < parts.length; i++ ) {
parts[i] = 0;
}
return parts.join(".");
}
function depad_index(index) {
return index.replace(/(\.0)+$/,'');
}
index = "0.0.0.0.0";
$(".toc li").each(function() {
depth = $(this).parents("ul").size();
index = incr_index(index, depth);
disp_index = depad_index(index);
$(this).prepend(disp_index + " ");
href = $(this).find("a").attr("href");
$("a[href='"+href+"']").last().parent(":header").prepend(disp_index + " ");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment