I have HTML that was formatted via a contenteditable div. I am wanting to make it more concise, modern HTML. I can easily replace any b, strong, em, font, etc tags and replace them with spans, but the result produced "stacked" elements.
For instance, I might have:
<span style="font-weight:bold">
<span style="text-decoration:underline">some text</span>
</span>
And I want to see:
<span style="font-weight:bold; text-decoration:underline">some text</span>
The hard part is it would need to handle:
<span style="font-weight:bold">
<span style="text-decoration:underline">some text</span> not underlined
</span>
I've done quite a bit of searching and thinking about this, but haven't found anything reasonable.
Well, here's a start. Obviously your selector would be more specific than just
span
.The only tricky part here is
copyStylesFromParentToChild
. I don't know any easy straightforward way to copy all styles from one element to another. You can try JavaScript & copy style