Whitespace significance. To standard or not to standard or 'don't change my HTML again!'
Have a look at this bug. In fact, it is not that we again munge your HTML. It is that we are trying to preserve whitespace and ensure correct page rendering. Why? Let's look at the standard first.
B.3.1 Line breaks
SGML (see [ISO8879], section 7.6.1) specifies that a line break immediately following a start tag must be ignored, as must a line break immediately before an end tag. This applies to all HTML elements without exception.
The following two HTML examples must be rendered identically:
<P>Thomas is watching TV.</P>
<P> Thomas is watching TV. </P>
So must the following two examples:
<A>My favorite Website</A>
<A>
My favorite Website
</A>
As you see, CRLF after open atag and before closing tag are not significant. Well, that's not quite what happens in a real world... I created the following HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<a href="https://www.microsoft.com">
Foo
</a>
<br>
<a href="https://www.microsoft.com">
Foo</a>
<br>
<a href="https://www.microsoft.com">Foo</a>
Here is how IE6 renders the fragment:
Here is how FireFox does it:
Interesting, but FireFox renders first line differently (note the longer underline). Opera does the same. Which brings the question: should we follow the letter of the standard and treat
<a>foo</a>
and
<a>
foo
</a>
as the same or should we follow real world rendering and treat them differently? The problem is that upon switch from Design to Source view some HTML formatting may change which may be perceived as that dreaded 'oh, no, my HTML is changing AGAIN! '.
Comments
- Anonymous
September 21, 2004
The comment has been removed - Anonymous
September 21, 2004
I say stick with the standard even more so because I actually expect it to behave the way IE renders it. - Anonymous
September 21, 2004
The comment has been removed - Anonymous
September 21, 2004
Text formatting and rendering are different topics. Please keep text formatting as typed! - Anonymous
September 21, 2004
The comment has been removed - Anonymous
September 21, 2004
<Comment mode="Standard zealot">This HTML fragment is not valid.</Comment>
Anyway, adding the required tags makes no difference (nor the XHTML doctype Julian Harse mentioned) so it is a bug in the other browsers - doesn't happen often, eh? So, keep with the standard when possible but leave the code as typed :) - Anonymous
September 22, 2004
Stick to the standard and assume that Firefox will correct any rendering bugs it has. And hope that IE will do the same. You should not assume that the standards will change to conform with a browser bug, you should assume the bugs will be corrected to conform with the standard(s). - Anonymous
September 22, 2004
Leave the code as the developer wrote it. Please don't mess with our code in a way where you think you are helping us out. If you want to include xhtml validators and such in the IDE that would be great, but if a developer writes a conforming page or not is up to the developer ( although I highly stress sticking to standards when writing markup ).
Nothing is more frustrating, and almost insulting than when the code you just wrote gets changed around because the IDE thinks it's helping out. - Anonymous
September 22, 2004
Let me clarify this a bit. Don't wprry, existing code formatting WILL NOT change. However, new (or heavily changed) markup may be formatted not the way you expect since we may be too careful with white space significance. - Anonymous
September 22, 2004
it's a MOZILLA BUG, Duh! :) - Anonymous
October 07, 2004
Why don't you let the user decide if they want their code to be reformatted? VS.net gives you the option, and then ignores your selection. I find it hard to believe that you can't understand why people call that a bug.
BTW -- You could always add a CodeSweeper function, like in HomeSite, and let people manually decide if they want formatting & error checking help.
$.02 - Anonymous
October 20, 2004
I apologize if this is slightly off topic but I was trying to write an addin to solve the html rewrite issue when switching between design view and html view. it's no problem to hook the edit > advanced > format document option using the guid:
{1496a755-94de-11d0-8c3f-00c04fc2aae2}
and the command id: 319. However this is not the proper hook to get the behavior to stop when the design tab is clicked from the html tab. I was wondering if you could provide me with the guid and command id for that event as I could not find a list of guids and cmdIDs for VS2003. Thanks. - Anonymous
October 20, 2004
Your HTML is reformatted not because of some formatting code that you cannot turn off. Have a look here:
http://weblogs.asp.net/mikhailarkhipov/archive/2004/05/16/132886.aspx
It also provides a link to an articale that describes how to format HTML on view switch if you want to fix it. But you cannot make VS stop modifying it.