Ported over code from pandoc's Text.Pandoc.Biblio.