Skip to content

Instantly share code, notes, and snippets.

@JakeLin
Last active August 29, 2015 14:27
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 JakeLin/4c2ecd2881ac93078c16 to your computer and use it in GitHub Desktop.
Save JakeLin/4c2ecd2881ac93078c16 to your computer and use it in GitHub Desktop.
Generate Table of Contents for GitHub Wiki using Markdown
// Generate Table of Contents for GitHub Wiki using Markdown
// How to Use
// 1. Open the Wiki page in a modern browser, for example, Chrome
// 2. Open the Console of the developer tools using F12 or ⌥ + Cmd + I
// 3. Copy the code below
// 4. Run it in the Console, it will generate Markdown for "Table of Contents"
// 5. Copy and Paste in your Wiki page.
(function () {
var toc = '**Table of Contents**\n';
$('div#wiki-body div.markdown-body h2').each(function() {
var title = $(this).text().trim();
var link = title.replace(/\s+/g, '-').replace(/[^0-9a-zA-Z_.-]/g, '').toLowerCase()
toc += '* [' + title + '](#' + link + ')\n';
});
console.log(toc);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment