Last active
July 18, 2022 12:17
-
-
Save chr5tphr/594af24a887905ccb0c7777fa3fd0b5f to your computer and use it in GitHub Desktop.
Create a table of contents for a markdown file
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
#!/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