You do not have to worry about backward markup in your production environment. Also, you should not use Tidy or other HTML cleaners. Acceptable use cases are, for example. when you allow HTML input (but use Markdown instead), although they are rare.
Most often, HTML filter filters are abused to hide underlying code issues. Not. Correct your markup manually.
If you need to backtrack your code only in the development environment, you can use any of the above. However, be careful that these libraries try to correct your markup (that their main purpose, indentation, is a byproduct). I wrote an indentation tool based on the Dindent regex .
Dindent transforms the markup as follows:
<!DOCTYPE html> <html> <head></head> <body> <script> console.log('te> <st'); function () { test; <!-- <a> --> } </script> <div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <div><table border="1" style="background-color: red;"><tr><td>A cell test!</td> <td colspan="2" rowspan="2"><table border="1" style="background-color: green;"><tr> <td>Cell</td><td colspan="2" rowspan="2"></td></tr><tr> <td><input><input><input></td></tr><tr><td>Cell</td><td>Cell</td><td>Ce ll</td></tr></table></td></tr><tr><td>Test <span>Ce ll</span></td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td></tr></table></div></div> </body> </html>
For this:
<!DOCTYPE html> <html> <head></head> <body> <script> console.log('te> <st'); function () { test; <!-- <a> --> } </script> <div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <div> <table border="1" style="background-color: red;"> <tr> <td>A cell test!</td> <td colspan="2" rowspan="2"> <table border="1" style="background-color: green;"> <tr> <td>Cell</td> <td colspan="2" rowspan="2"></td> </tr> <tr> <td> <input> <input> <input> </td> </tr> <tr> <td>Cell</td> <td>Cell</td> <td>Ce ll</td> </tr> </table> </td> </tr> <tr> <td>Test <span>Ce ll</span></td> </tr> <tr> <td>Cell</td> <td>Cell</td> <td>Cell</td> </tr> </table> </div> </div> </body> </html>
Dindent will not attempt to sanitize or otherwise interfere with your code other than adding indentation. This will simplify your development / debugging. Not for production.
Gajus Feb 19 '14 at 22:23 2014-02-19 22:23
source share