A simple script that will read a markdown file, sort the headers recursively, and output the results to the command line, where it can be redirected into a file.
Example use:
MarkdownSort.pl README.md >README_sorted.md
Use at your own risk. There are no sanity checks to make sure the file is markdown.