minor tweak to document_generator to make it more robust to nonunicode (hopefully)