trungdq88 / Awesome-Black-Friday-Cyber-Monday

Awesome deals on Black Friday: Apps, SaaS, Books, Courses, etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Snippet to regenerate table of content

trungdq88 opened this issue · comments

Run in the browser console while visiting your README.

$$('.markdown-body h2, .markdown-body h3, .markdown-body h4').map(heading => {
    const text = heading.innerText
    const hash = heading.querySelector('a').getAttribute('href');
    const level = Number(heading.tagName.replace('H', '')) - 2;
    const length = heading.nextElementSibling.querySelectorAll('tbody tr').length
    const lengthText = length > 0 ? `(${length})` : ''
    return `${new Array(level).fill('	').join('')}- [${text} ${lengthText}](${hash})`;
}).join('\n')