Last active
August 29, 2015 14:27
-
-
Save JakeLin/4c2ecd2881ac93078c16 to your computer and use it in GitHub Desktop.
Generate Table of Contents for GitHub Wiki using Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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