Not to discourage you to write your own script, but maybe you want to look at calibre or pandoc to do what you want. With pandoc you can make whatever you want out of markdown. Epub, html, docx, latex, excellent pdfs via latex (without needing to know anything about latex) etc.
|