views:

146

answers:

4

I'm just curious if anyone has any tricks on how to keep source code looking good when you "View Source." I'm militant about keeping my code well formatted and spaced while I'm developing and I tend to "View Source" a lot to double check the output (when firebug is overkill). When I start using RenderPartials and RenderActions and anything in the tag it gets pretty messy.

I don't want to send too many extra characters to the browser to keep file size efficient but is there a way to force the xhtml/html to do a newline or tab? I tried a couple of things that didn't work. Thanks!

+4  A: 

Get over it.

Don't worry about how it looks in 'view source'; worry about how it looks in csharp :) If you get worried about the efficiency of the HTML you can gzip it, and other such things.

Noon Silk
+1 the only reason for view source 90% of the time is to get code or paths from other sites and in that case, we...
griegs
I get my gzip on in production but I think it would be nice to have "View Source" formatted while in development and test. I think it's just my compulsion for neatness coming through here as not too many people share my wishes...
DM
Your compulsion for neatness is not valid here; as I said it's more important that the sourcecode looks nice; with the HTML-output your main concern is what is best for the *browser* and your bandwidth. That said, to a degree I feel similar, but I basically go over it. Focus the attention elsewhere; you will be better for it.
Noon Silk
A: 

Just send a \n and it should come out as a newline in the "view-source" section of the browser.

chpwn
+3  A: 

I use firefox's ViewSourceWith extension to view the source in a code editor (in my case SciTe) in which I have a macro programmed so that when I press Ctrl-1 it reformats the HTML using a script I've written.

If validation is the goal then consider using a HTML validator rather than your eyeballs. Total Validator looks good.

slebetman
I like your suggestions but if I'm going to go through that much trouble I would just view it in Firebug. The scenario I'm referring to is a situation where I just need a quick peek at the html and not the whole story. I would just love it if that quick peek was well formatted. Thanks for you response +1!
DM
But Firebug doesn't do what you want due to Firefox auto-correcting any errors on the page before generating the DOM (and Firebug just sees the DOM, not the source).
slebetman
A: 

Example:

public static String Etc(...)
{
    TagBuilder myTag = new TagBuilder("span");
    myTag.SetInnerText("I'm mr. tag-content!");
    return myTag.ToString(TagRenderMode.Normal) + Environment.NewLine;
}
Terje