A few days ago I checked the HTML validity of my own blog. I have to admit that I didn’t do that after I wrote the jugglingPostLang plugin (wrote about that in my blog post Simple Language-Defined Posts in WordPress) for WordPress. I realized that my plugin produced invalid html in many cases, so that was an issue:
The issue is, that <span> elements forbid block level content, while <div> elements are not allowed as a child of any element that only accepts phrasing content (which is roughly running text and what’s inside).
To solve that I read through the html specifications to find a solution but unfortunately there isn’t a simple solution on the horizon.
In the following I’m going to summarize the html specification details on the topic and give a rough sketch on the algorithm to determine what’s a valid wrapping node. Wrapping Arbitrary HTML to Assign a common Universal Attribute weiterlesen