Search code examples
htmltagstrailing

Tool to remove leading/trailing spaces in HTML files?


I have searched but could not find anything similar to what I need. I am looking for a tool that is capable of removing leading/trailing spaces in my HTML files which also have embedded JavaScript. Basically in the end, I plan to use this tool within my Nant scripts to perform this task on the fly with every deployment.

Is there already a tool that can do this, or maybe the best scripting language?

Basically, I will like what MS Word does for text using "justify (Ctrl+J)", to be done for my HTML files.


Solution

  • Here is the solution I found for this.

    Using the html compressor command line tool, I was able to only remove the leading spaces of the html file where as fully minifying them didnt work.

    Soultion:

    java -jar htmlcompressor.jar --preserve-comments --preserve-multi-spaces --preserve-line-breaks --output D:\html\foo-leading_spaces.htm D:\html\foo.htm

    Using this tool to generate my desired results, I am able to apply this to my build scripts to perform this process on the fly.

    Thanks everyone for their input and hope this helps others in the similar situation.