Skip to content

Instantly share code, notes, and snippets.

@llun
Created October 21, 2014 03:18
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 llun/b65aa76b23dc7f687d05 to your computer and use it in GitHub Desktop.
Save llun/b65aa76b23dc7f687d05 to your computer and use it in GitHub Desktop.
Create TOC from Github markdown page
var toc = '';
for (var i = 0; i < contents.length; i++) { var link = contents[i].querySelector('a').getAttribute('href'); var text = contents[i].textContent.replace(/^\s+|\s+$/,''); toc += '- [' + text + '](' + link + ')\n' }
console.log (toc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment