You should look at Pandoc[1]. It's a Markdown-to-everything converter, and though I'm not super familiar with the code I believe it's well written. One of my favorite tools for writing.
You also need to add that the parser of Pandoc is not regular expression based. It is a very robust parser, parsing the document in an internal abstract tree you can easily modify. You can also adapt the parser to your needs with simple extensions. You can then get very nice outputs in HTML or PDF[1]. As it is a nice command line tool, it is easy to generate everything with a simple Makefile too.
+1 for Pandocs extensions. I can verify that is sufficient for producing a doctoral dissertion (in German; not my own…), via LaTeX.
The way Pandoc handles citations, footnotes, tables(!), etc is just delightful.
[1]: http://johnmacfarlane.net/pandoc/