-
-
Save Pacheco95/27ec4055bd15ca947a704ca426c565e0 to your computer and use it in GitHub Desktop.
creates a gitlab markdown table of contents for a README.md page
This file contains 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
// quick and dirty snippet to creates a gitlab markdown table of contents for a README.md page | |
// preview gitlab page and paste in browser console | |
var str = ""; | |
$('.file-content') | |
.find('h1, h2, h3, h4, h5, h6, h7') | |
.each((i, node) => { | |
// node.tagName is H1 H2... | |
let indent = Number(node.tagName[1]) - 1; | |
// markdown mested lists are | |
// - xxx | |
// - yyy etc | |
let tabs = ' '.substr(0, 3 * indent); | |
let linkName = node.textContent.trim(); | |
let linkAnchor = node.querySelector('a').id; | |
str += `\n${tabs}- [${linkName}](#${linkAnchor})`; | |
}); | |
console.log(str); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment