plugin/document: Simplify and refactor Document plugin

Convert the Document plugin to a new-style plugin. This makes the plugin
a lot simpler, and while here I've taken the liberty of "purifying" the
various metadata-extraction functions so they don't all mutate one
enormous object.

In addition, it appears that previously all annotations (before a cycle
through the store plugin) shared a reference to one global metadata
object. This is now fixed -- the metadata object is copied before being
added to an annotation.