HTMLSerializer - Grouped images

I've put this down as React butIi guess this could be for any technology.

I have a rich text field where I add text and multiple images.

If I have 2 or more images next to each other, I want to lay them out in a grid. In order to do this its ideal that they share a parent, i.e...
div
img
img
img

I've been looking at doing this in my own HTMLSerializer, but have hit a few walls. I wondered if anyone else has achieved a similar result?