• a knock at the door, I'll be back in a second which I show as inline...">

    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).

    +4
    source share
    3 answers

    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.

    +4
    source

    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.

    +2
    source

    Replace < and > ascii / unicode &#60; equivalents and &#62; OR &lt; and &gt; OR \u003c and \u003e

    +1
    source

    Source: https://habr.com/ru/post/1310524/


    All Articles