Ported the html-template from Tidbits

I have also added some better documentation, and restructured the code
to make it more readable. All "helper" functions have also been made a
part of the to-html macro in order to keep the namespace less cluttered.