Last active
January 22, 2026 07:21
-
-
Save ABB00717/42a74b6ab993f2a2fc9d0d7d3ff83fa8 to your computer and use it in GitHub Desktop.
A Javascript script prints headers in current HTML file with tabs representing their depth.
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
| class Tag { | |
| constructor(level, text) { | |
| this.level = level; | |
| this.text = text; | |
| }; | |
| }; | |
| function extractHeaders() { | |
| const headers = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); | |
| console.log(headers); | |
| const tagList = Array.from(headers).map(header => { | |
| const level = parseInt(header.tagName.substring(1)); | |
| const text = header.innerText.trim(); | |
| return new Tag(level, text); | |
| }); | |
| tagList.forEach(tag => { | |
| const indentation = '\t'.repeat(tag.level); | |
| console.log(`${indentation}${tag.text}`); | |
| }); | |
| return tagList; | |
| }; | |
| extractHeaders(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment