pandoc.hs:  Rewrote some of the logic for clarity.