maketoc 398 B

123456789101112131415
  1. #!/bin/zsh
  2. for filename (*Zsh-开发指南(第*md) {
  3. local title=${${${filename#*(}%)*}//-/ }
  4. echo "## [$title]("$filename")"
  5. for i (${(f)"$(grep "^###" $filename)"}) {
  6. local level=${i%% *}
  7. local subtitle=${i#$level }
  8. level=${level/"####"/- }
  9. echo "$level [$subtitle]("$filename"#${${${(L)subtitle// /-}//、}//:})"
  10. }
  11. echo "\n---\n"
  12. }