Skip to content

Instantly share code, notes, and snippets.

@souporserious
Last active June 24, 2023 17:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save souporserious/5ffb84a4edc4ed1e39bbb0a76b5eb7d1 to your computer and use it in GitHub Desktop.
Save souporserious/5ffb84a4edc4ed1e39bbb0a76b5eb7d1 to your computer and use it in GitHub Desktop.
Extract headings from a markdown string.
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