Skip to content

Instantly share code, notes, and snippets.

@rduarte
Forked from guilhermechapiewski/github_wiki_toc.js
Created April 26, 2010 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rduarte/379562 to your computer and use it in GitHub Desktop.
Save rduarte/379562 to your computer and use it in GitHub Desktop.
$(function () {
var toc = $("<ul>").css("margin-bottom", "20px !important");
$("div.main div.wikistyle h2").each(function() {
var id = $(this).text().replace(/\s+/g, "_").replace(/[^0-9a-zA-Z_.-]/g, "")
$(this).attr("id", id)
toc.append(
$("<li>").append($("<b>").append($("<a>").attr("href", "#" + id).text($(this).text())))
)
});
$("div.wikistyle").prepend(toc).prepend($("<h2>").text("Table of Contents"));
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment