Programmable, Typesafe Document Generation