Some fixes for the docs.

Also switch to a model where the writes are collected together in a list and then assembled into a string at the end using the getvalue method.  This allows some introspection and easier manipulation of the document during construction.