Forum Moderators: open

Message Too Old, No Replies

Cleaning HTML code

Dreamweaver

         

ukgimp

3:24 pm on May 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, perhaps you can help. I am trying to clean some realy dirty html using dreamweaver or any other code to insert it into a database.

I have loads of messy font tags like

<font color="12345" size="3" Face="MyriaMM_250 wt 500 wd">

OK I can stip them out using the following regex

</{0,1}font[^>]*>

but when I look at the code in code view, there are loads of new lines and tabs. If I look at it in design view, cut and past it it is fine. Is there a way of getting code view to wrap properly as I would like to keep formatting like <i></i> etc.

Cheers

sonjay

11:10 pm on May 10, 2004 (gmt 0)

10+ Year Member



Commands menu -> Apply Source Formatting

ukgimp

8:48 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



:)

Your joking. I was trying regular expressions and all sorts of stuff. lol

Cheers Sonjay

Monkscuba

9:16 am on May 11, 2004 (gmt 0)

10+ Year Member



"Apply Source Formatting"
sonjay! OMG. Thanks for that.
I just tried this on a random page of our web site and it has cut about 1k from the page size (from 24 - 23). By doing this (sorry to ask, I am a rank amateur really), is it right that the page loses nothing except un needed code? If so, well hell, I'd better go do it to all pages!

Cheers.

ukgimp

9:19 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



one more challenge for you sonjay

Can this be done across a whole site? 1000's of pages?

sonjay

10:27 am on May 11, 2004 (gmt 0)

10+ Year Member



Unfortunately, ukgimp, I don't believe there's any way to apply source formatting to a whole site at once. It's strictly a document-level command, as far as I know.

All it does is apply Dreamweaver's default formatting (tabs, indents, etc.) to the code -- it doesn't change the code at all, doesn't re-write anything, doesn't do anything that could cause any nasty surprises.

You can do some modifying of *how* DW will apply code formatting. In Preferences, under "Code Formatting," you can specify tabs and indent levels, and under the Edit menu -> Tag Libraries, you can set some more preferences for that, at a tag-specific level -- if you always want line breaks before and after particular tags, for example, or you don't want certain tags indented, that sort of thing.

Monkscuba, with Apply Source Formatting you don't even lose "unneeded code" -- you only lose unneeded white space: spaces and tabs. There's another command called "Clean up HTML" under the Commands menu -- this will do a lot of actual code clean up. You get a dialog box with that one, asking what kinds of cleanup you want to do. Generally, this one won't hurt anything either, but it does touch actual code, so use it a little more carefully, especially the free-form "Remove tag" field.

Monkscuba

10:34 am on May 11, 2004 (gmt 0)

10+ Year Member



Yeh, the Clean up HTML command I use after every edit, to be sure there's nothing wasted. I'm just amazed that I can lose 1kb from the page just by losing white space! So, basically this Apply Source Formatting just condenses the code, is that it? Recommended for all pages, all the time?

sonjay

11:09 am on May 11, 2004 (gmt 0)

10+ Year Member



I'm sure it wouldn't *hurt* anything to apply it to all pages whenever you edit them. I pretty much only use it when I'm working in code view and get annoyed at the messed-up formatting, but if it really saves as much as 1k (in white space!) on a single page, maybe I should use it more.

I'd prefer that DW managed its code formatting better so as to *keep* the proper formatting so that we didn't have to clean it up all the time, but that's another issue.

Monkscuba

11:16 am on May 11, 2004 (gmt 0)

10+ Year Member



Well, I just tried it on our (big, lots of text) index page and saved more than 2k. I mean, as I say, I'm a real amateur so I guess my code was somewhat confused and all over the place. If you're a decent programmer, maybe it won't save much.

So our new improved smaller page has been uploaded for the bots to get their teeth into.

pageoneresults

11:18 am on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd prefer that DW managed its code formatting better so as to *keep* the proper formatting so that we didn't have to clean it up all the time, but that's another issue.

This is where diligence in setting up your coding preferences is paramount. I work with FP and have similar features as DW does when it comes to formatting code. If you are in a team editing environment, it is imperative that the entire team have their coding preferences identical to one another. If they don't, that is where the issues begin to arise.

edward301

5:09 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



u can remove many errors and reduce file sizes greatly with HTML Code Cleaner
webmasterfree.com/software/WebAuthoringTools/HTMLEditors/html_code_cleaner.html