Skip to content

Instantly share code, notes, and snippets.

@munckymagik
Last active February 16, 2019 09:52
Show Gist options
  • Save munckymagik/433d24d02b8d00b8f078ac5a172dd895 to your computer and use it in GitHub Desktop.
Save munckymagik/433d24d02b8d00b8f078ac5a172dd895 to your computer and use it in GitHub Desktop.
Jupyter notebook & lab TOC generator bookmarklet
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