Show invalid HTML "Is it safe?"
Let's say I have HTML like this:
<ol><li>a knock at the door, I'll be back in a second which I show as inline HTML in the div that I create. Is there any way to stop the internal, incorrect HTML code associated with the alignment of the entire document that appears after the HTML?
I understand that parsing parsed is one option (since I have this on the server side), but I'm looking for an easier solution.
Edit I know that I can simply replace the < and > objects with entities, but I want to keep the formatting (within reason).
Although you are looking for a “easier solution” than HTML parsing, you may need to use HTML Cleaner or Tidy HTML , as this should take care of the broken tags for you - which is essentially what they were made for.
Do you need inline text to support HTML? If not, you can simply remove all HTML tags or replace <> screens. Or you can save the text on the server as Markdown or any other language other than HTML and generate good HTML on the fly.
Change If you really need HTML, I suggest you run the XML validator in an HTML snippet. You actually do not need to look at the XML structure: if the fragment is well formed, then it is very unlikely that it will break the rest of the layout.