Created
September 1, 2014 20:56
-
-
Save penguinpowernz/12c6388b968cbba0e917 to your computer and use it in GitHub Desktop.
Some javascript to give numbers to headings on a gollum page
This file contains 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
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