Version 1.1: added ability to provide a template to insert the generate HTML into