I have a string that contain data formatted through a WYSIWYG editor. But the generated HTML code is not very well formatted. I would like something as the “the_content()” wordpress function, that delivers a string like this:
Lorem ipsum dolor sit amet, <strong>not properly closed
Another paragraph without p, lorem ipsum dolor m nonummy.
To somethig like this:
<p>Lorem ipsum dolor sit amet, <strong>not properly closed</strong></p>
<p>Another paragraph without p, lorem ipsum dolor m nonummy.</p>
I look up to the wordpress core but without much success (found a force_balance_tags() function, but don’t seems to be what I want).
So… do you guys know some php class/library/code snippet that does that?
WordPress has a function called
wpautopwhich converts double line-breaks to paragraph elements.I would not suggest using a library for correcting the users wrongly formatted HTML though. You would be forced to guess the correct intepretation. (like old browsers did back in the days, and that was not exactly a success).
As an example, Where should the closing
</strong>tag in your code be placed? No one knows!I would rather look for (or create) a method to check for unvalid HTML and then notify the user, and let them correct it.