Refactor html5lib serializer to avoid mutating the input via table.sort