Skip to content

Instantly share code, notes, and snippets.

@hogashi
Created October 14, 2022 09:25
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 hogashi/c239868c00cb412626b0378e914a53d7 to your computer and use it in GitHub Desktop.
Save hogashi/c239868c00cb412626b0378e914a53d7 to your computer and use it in GitHub Desktop.
javascript:(() => {
const toc = [...document.querySelector('#readme').querySelectorAll('h1, h2, h3, h4, h5, h6')].map(h =>
`${
' '.repeat(
/* "H1" などから "1" を取ってきて 1 引いて行頭の空白の個数に使う */
parseInt(h.tagName.match(/[0-9]+/)[0], 10) - 1
)
}- [${h.innerText}](${h.querySelector('a').href})`
).join('\n');
console.log(toc);
navigator.clipboard.writeText(toc);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment