If everything is already ancored, why do you feel the need to place everything inline before you export to ePub? Is there a specific reason for it? It should export fine as-is but you could always go and strip out the extra div tags from the HTML post export if you needed to, it would be far easier than writing this script from scratch.
But it does not export fine to ePub. The Question number comes out on one
line and the text on another. And then the little graphic comes out on yet
another ... and they aren't next to each other. I think i'll have to go in
to the object export actions and make a jpg for each question. I thought
moving them into the text was easier plus i think it looks better.
I'm sorry, to do what you want you will need to edit the ePub after export.
(please, for the sake of accessability and usibility, don't make the whole thing an image -- think about how someone will read it on an iPhone)