Skip to content

Instantly share code, notes, and snippets.

@chr5tphr
Last active July 18, 2022 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chr5tphr/594af24a887905ccb0c7777fa3fd0b5f to your computer and use it in GitHub Desktop.
Save chr5tphr/594af24a887905ccb0c7777fa3fd0b5f to your computer and use it in GitHub Desktop.
Create a table of contents for a markdown file
#!/usr/bin/env -S gawk -f
$1~/^##+$/{
l = length($1);
r = q = substr($0, l + 2);
gsub(" ", "-", q);
printf "%" ((l - 2) * 4 + 2) "s[%s](#%s)\n", "* ", r, q
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment