Some work on the reading of documents, largely copied from the Redactor 2.0 project.