Make the expat parser accept HTML entities.

The fix relies on using a specific doctype.

But now we need to output doctypes ourselves when is_fragment=False,
since input templates can never contain doctypes.