Preserve the class attribute for block images

Build the new set of classes as an array (avoiding the leading space),
and only set it if it differs from what was there before. This avoids
reordering the class attribute.

Change-Id: I863ec8de2e7637f76690c4e0b7db5e153fb7e408
Merge "Preserve the class attribute for block images"