Last active
February 16, 2019 09:52
-
-
Save munckymagik/433d24d02b8d00b8f078ac5a172dd895 to your computer and use it in GitHub Desktop.
Jupyter notebook & lab TOC generator bookmarklet
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
javascript:(() => { | |
const anchors = Array.from(document.querySelectorAll('a.anchor-link,a.jp-InternalAnchorLink')); | |
const linkData = anchors.map( | |
a => [ | |
Number(a.parentElement.tagName[1]), | |
a.parentElement.firstChild.textContent, | |
new URL(a.href).hash | |
] | |
); | |
const links = linkData | |
.filter(([level, ..._]) => level > 1) | |
.map(([level, title, url]) => { | |
const indent = ' '.repeat(level - 2); | |
return `${indent} * [${title}](${url})`; | |
}); | |
const toc = `**Table of contents**\n${links.join("\n")}`; | |
console.log(toc); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment