Skip to content

Instantly share code, notes, and snippets.

@guilhermechapiewski
Created May 6, 2010 00:31
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 guilhermechapiewski/391639 to your computer and use it in GitHub Desktop.
Save guilhermechapiewski/391639 to your computer and use it in GitHub Desktop.
Create "Table of contents" in Github wiki for H1 and H2 items.
$(function () {
var toc = $("<ul>").css("margin-bottom", "20px !important");
$("div.main div.wikistyle h1,h2").each(function() {
var id = $(this).text().replace(/\s+/g, "_").replace(/[^0-9a-zA-Z_.-]/g, "")
$(this).attr("id", id)
if (this.tagName == "H1") {
toc.append(
$("<li>").append($("<b>").append($("<a>").attr("href", "#" + id).text($(this).text())))
)
} else {
toc.append(
$("<ul>").append($("<li>").append($("<b>").append($("<a>").attr("href", "#" + id).text($(this).text()))))
)
}
});
$("div.wikistyle").prepend(toc).prepend($("<h2>").text("Table of Contents"));
})
@benjaminoakes
Copy link

As of 2 May 2012 or prior, this is no longer valid. JavaScript can't be included any longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment