Redo of #886: Page charset fix

I finished what @ptone started on #886, added a couple of tests, and resolved some merge conflicts.

If this get merged, pull request #483 is unblocked and free to go.

PS.: I had opened #944 but I made a lot of duplicates. I made a git mess there. Sorry. That's why I am opening this new one.