Fix doctype serialization

As per tmpvar/jsdom#848 I'll PR this here.

While switching the custom serializer in jsdom I came across some bugs in doctype serialization, this should fix them.

I just noticed I haven't added a test, will add when I get some time and figure out the test system before the merge.