Skip to content

Instantly share code, notes, and snippets.

@r-brown
Last active March 1, 2020 15:58
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 r-brown/2c5b0cd07548ad9f02f6ce8a76a32848 to your computer and use it in GitHub Desktop.
Save r-brown/2c5b0cd07548ad9f02f6ce8a76a32848 to your computer and use it in GitHub Desktop.
// In the Wiki Edit (/_edit) Preview mode, run this snippet in the browser console to get a Markdown of a Table of Contents:
console.log(
'**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' + '***'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment