views:

763

answers:

7

There are plenty of services online that will color-code and "prettify" your code for you - I'm not interested in that for this question. I've taken over for a previous developer who loves seperating each line of markup with 3 or 4 empty lines, along with using spaces rather than tabs for indenting. This is very opposite to how I (and I think most others) operate.

Is there a service online that can remove empty lines, and handle indentation for me? I could write my own script to do this, and perhaps I will, but if the service already exists then I would much rather use them for the time being.

Convert this:

<div class="className">

   <img src="images/one.jpg" />

      <p>Foo

               <img src="images/two.jpg" />         


            </p>

</div>

To this:

<div class="className">
    <img src="images/one.jpg" />
    <p>Foo <img src="images/two.jpg" /></p>
</div>
A: 

Visual Studio does this. It creates totally crap bloated HTML and then formats it nicely for you :)

Matt Howells
Looking for an online service.
Jonathan Sampson
+1  A: 

Are you using Visual Studio (or have access to it?) Then you could just do a "select all" code, then right mouse click -> format selection

Colin
Looking for an online service.
Jonathan Sampson
+5  A: 

HTML Tidy should work for you. The original Tidy is a standalone program.
There is also a library and an online version.

If you set "indent" to "YES", Tidy indents your code and also removes empty lines.

weichsel
This looks promising.
Jonathan Sampson
Maybe your text editor already has HTMLTidy support. I use TextMate on OS X and Scite on all other platforms. Both come with built-in HTMLTidy.
weichsel
+1  A: 

HTML Tidy provides an online service.

Darin Dimitrov
+1  A: 

There is a python module call BeautifulSoup http://www.crummy.com/software/BeautifulSoup/ which is doing this very well. It is not online but it worths a try

luc
+1  A: 

Hm I think the Tidy HTML libraries can help you with your problem. Especially the HTML Tidy Online but also the other Tidy Projects e.g. html tidy on sourceforge . If you are using Eclipse most HTML Editors support even Custom Syntax Formatting (e.g. Aptana) which would be my favourite solution. Also check out the HTML Validator Firefox Plugin it has a Tidy source cleaner, too but the most important feature is the possibility to additionaly validate your HTML.

Daff
A: 

You could use PSPad to do the trick for you. It's reformat doesn't do exactly what you want but it's close. As an aside, I find PSPad really handy for quickly formatting/reading html, xml, perl....

Your example formatted by PSPad:

<div class="className">   
  <img src="images/one.jpg" />      
  <p>Foo                
    <img src="images/two.jpg" />                      
  </p>
</div>

PSPad: PSPad Download

Russell Troywest