Tips on Cleaning Up Source Code

Seeing clean, structured code is always nice.  Here are some tips to automate cleaning up messy code.

1. Use HTML Tidy to clean up code
There are some online code cleaners based on Tidy that can do this for you like at http://infohound.net/tidy/

2. Dreamweaver “Apply Source Formatting”
Dreamweaver can format your source code based on a format profile. Find it under Commands -> Apply Source Formatting. This will also trim unnecessary whitespace and the beginning and end of lines.

3. Trim unnecessary whitespace at beginning of line
REGEX: ^s+
REPLACE: empty string

 4. Trim unnecessary whitespace at end of line
REGEX: ^s$
REPLACE: empty string

5. Convert spaces to tabs
In Dreamweaver, select / highlight all the code, right click, select “Convert spaces to tabs”

6. Delete empty lines
REGEX: [rn]{2,}
REPLACE: n