Skip to content

Instantly share code, notes, and snippets.

@sompylasar
Created January 22, 2019 23:09
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 sompylasar/d5f56e913c88b7e7f633a15fdc4b44d8 to your computer and use it in GitHub Desktop.
Save sompylasar/d5f56e913c88b7e7f633a15fdc4b44d8 to your computer and use it in GitHub Desktop.
While in the Wiki Edit (`/_edit`) Preview mode, run this snippet in the browser console to get a Markdown of a Table of contents. https://github.com/isaacs/github/issues/215
console.log(
'\n\n\n> **Table of contents**\n> \n' +
Array.from(document.querySelectorAll('h1 > a, h2 > a, h3 > a')).map((a) => (
{'H1':'> * ','H2':'> * ','H3':'> - '}[a.parentNode.tagName] +
`[${a.parentNode.innerText.trim()}](${a.hash})`
)).join('\n') +
'\n\n\n'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment