Last active
January 6, 2022 20:35
-
-
Save tol-is/dcf6656a4d241ca44dab9367d33b8b11 to your computer and use it in GitHub Desktop.
Get table of contents from markdown
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
| const getMarkdownHeadings = (source: string) => | |
| source | |
| .split("\n") | |
| .map((line) => { | |
| const matches = line.match(/^#+[\s]+/); | |
| return matches | |
| ? { | |
| level: matches[0].trim().length, | |
| heading: line.replace(matches[0], "").trim(), | |
| } | |
| : false; | |
| }) | |
| .filter(Boolean); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment