Looking for an app that can format disasterous code

Discussion in 'Web Design and Development' started by Verdanice, Feb 13, 2009.

  1. Verdanice macrumors regular

    Joined:
    Aug 13, 2007
    #1
    I'm in the process of updating a few pages of a site that was developed by the laziest developer I've ever met a couple years ago. The entire thing is incredibly table-centric and has the goddamn things nested ten deep. To make matters worse, nothing is indented properly, and what is indented is indented with spaces rather than tabbing.

    The pages are HTML but have a bunch of ASP in them (and a .ASP extension) as well as some JS. I am in desperate need of a utility that will properly format (i.e. indent) this code. 'Tidy' in TextMate doesn't do a thing and Coda can't get it done either, Espresso doesn't know ASP (...really?) and I very intentionally uninstalled Dreamweaver after putting Master Collection CS4 on my computer (this bloody thing is a result of Dreamweaver).

    Any suggestions would be appreciated!

    Thanks in advance. =)
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Tidy is likely the best bet. I've never used TextMate's version though, but you may want to download others apps that can do it to see if you get better results. Unfortunately, if the code is really horrible, nothing is going to fix that because it won't be able to interpret it correctly to know how to indent it.

    If you need to clean up JavaScript you can use the JavaScript Beautifier.

    You can also take a look at Tabifier as it was designed for this type of situation. I've ever used it though.

    Here's a page with links for various web code formatting.
     
  3. memco macrumors 6502

    Joined:
    May 1, 2008
    #3
    My recommendation is that you get real cozy with an intro to regular expressions, and get a copy of BBEdit. I had a rather large site in much the same state as yours. In my efforts to clean it up I found most code followed a similar pattern, and there were bits and pieces here or there that I wanted, and everything else needed replacing. BBEdit and Tm have an advanced find that can find and replace across multiple files, and can be done using regex. I used Textmate initially but just found out about a week ago that BBEdits method is better because it offers a progress bar and is still usable while TM offers no feedback until the whole process is complete, and becomes nigh unusable. You could probably also use grep on the command line, but it's not something I've got a good handle on, so for me BBE was easier.

    Also, instead of trying to clean up by reformatting, all I do is search for the bits of source that I actually need, and insert that into the appropriate place of a new properly formatted template. Say for example, all you need is the contents of a p tag nested deep in those tables, you can do a regexp like
    Code:
    <(p)\b[^>]*>(.*?)</\1>
    to grab just the p tag (the regexp translates to "grab all the text between <p> and </p>"). then you can use
    Code:
    $2
    somewhere in your replacement to insert just the text of the paragraph (the "(.*?)" means all the stuff between <p> and </p>).

    Perhaps I'll write up a tutorial on how to do this. I know some people have documented some solutions, but I don't think I ever came across a method for reformatting a whole site in one go.
     
  4. Verdanice thread starter macrumors regular

    Joined:
    Aug 13, 2007
    #4
    Sorry about the late response, got kinda crazy.

    Tabifier actually did help with the HTML portion, it indented the chunks of other languages to the proper level so I could do the indenting on that myself.

    memco, I've been meaning to properly learn regexp for ages - I'm going to download BBEdit and try that out when I get a chance, in general regexp is a good thing to know.

    Thanks for the responses, guys.
     

Share This Page