Skip to content

Instantly share code, notes, and snippets.

@samnang
Created May 29, 2015 02:49
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 samnang/cb9515ffcf5b0ab03f8f to your computer and use it in GitHub Desktop.
Save samnang/cb9515ffcf5b0ab03f8f to your computer and use it in GitHub Desktop.
TOC of Github's README
function tocLink(heading, title, href) {
var ele = '<li class="tooltipped tooltipped-w" aria-label="'+title+'">'+
'<a href="'+href+'" aria-label="'+title+'"'+
'class="js-selected-navigation-item sunken-menu-item">'+
'<span class="full-word">'+title+'</span></a></li>'
return ele;
}
var header = "<li class='tooltipped tooltipped-w'><strong>&nbsp;Table of Contents</strong></li>"
var rows = [];
$('a[class=anchor').each(function(i, anchor) {
$anchor = $(anchor);
$heading = $anchor.parent();
rows.push(
tocLink(
$heading.prop("tagName").toLowerCase(),
$heading.text(),
$anchor.attr('href')
)
);
})
var template = "<div class='repository-sidebar'><nav class='sunken-menu repo-nav' role='navigation'><div class='sunken-menu-separator'></div><ul class='sunken-menu-group'>"+
header+rows.join('')+"</ul></nav></div>"
$($('.repository-with-sidebar.with-full-navigation .repository-sidebar')[0]).append(template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment