fix up write_document() to not have evil side effects
Merge branch 'master' of github.com:anura-engine/anura