Last active
June 24, 2023 17:16
-
-
Save souporserious/5ffb84a4edc4ed1e39bbb0a76b5eb7d1 to your computer and use it in GitHub Desktop.
Extract headings from a markdown string.
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
const headings = content | |
.split('\n') | |
.filter((line) => line.match(/#{1,3}\s/)) | |
.map((line) => { | |
const [, level, title] = line.match(/(#{1,3})\s(.*)/) | |
return { | |
level: level.length, | |
title, | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment