Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / December 2005

Tip: Looking for answers? Try searching our database.

VS2005 Reformats HTML Source

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
clintonG - 27 Dec 2005 22:15 GMT
The IDE will not stop reformatting the HTML.

//Desired Example
<dt class="..." onclick="...">Example</dt>
   <dd id="..." class="...">
   Monday
   </dd>
</dt>

//FUBAR VS 2005
<dt class="..." onclick="...">Example</dt><dd id="..." class="...">Monday
   </dd>
</dt>

Is there a way to stop this?

<%= Clinton Gallagher
        METROmilwaukee (sm) "A Regional Information Service"
        NET csgallagher AT metromilwaukee.com
        URL http://metromilwaukee.com/
        URL http://clintongallagher.metromilwaukee.com/
Mikhail Arkhipov (Microsoft) - 29 Dec 2005 05:02 GMT
On 12/27/05 14:15, in article ezSkLLzCGHA.3140@TK2MSFTNGP14.phx.gbl,

> <dt class="..." onclick="...">Example</dt>
>     <dd id="..." class="...">
>     Monday
>     </dd>
> </dt>

I assume you meant

<dl>
<dt class="..." onclick="...">Example</dt>
    <dd id="..." class="...">
    Monday
    </dd>
</dl>

It is difficult to say from the markup above, but it might be that editing
in Design view introduced a whitespace after Monday.

<dd>
   Monday
</dd>

really renders as

Monday<space>

When you place caret after 'Monday' and switch to Design view, you'll see
that caret is one space after the 'y'. Until you type, this is 'virtual'
whitespace or, rather, whitespace that is rendered instead of all spaces and
new line symbols that come after 'Monday'. If at this point you type, say,
A, making the string 'Monday A', the space becomes real and now is
represented by a single space character.

Designer and formatter always try to preserve page rendering over
formatting. Since now there are spaces left after A (all the collapsed
spaces went into the space between y and A, </dt> moves to immediately after
A preserving page rendering. What is at this point on the page is

Monday<space>A

Adding back newlines and tabs/indents would make text different:

Monday<space>A<space>

vs

Monday<space>A

which is different in rendering from Monday<space>A. Same might happen with
<TD> and other elements where whitespace is significant.

Generally, W3C recommends avoiding putting trailing whitespace in elements
where rendering might be different

http://www.w3.org/TR/html4/struct/text.html#h-9.1

<quote>

In order to avoid problems with SGML line break rules and inconsistencies
among extant implementations, authors should not rely on user agents to
render white space immediately after a start tag or immediately before an
end tag. Thus, authors, and in particular authoring tools, should write:

 <P>We offer free <A>technical support</A> for subscribers.</P>

and not:

 <P>We offer free<A> technical support </A>for subscribers.</P>

</quote>

Thanks
Mikhail Arkhipov (Microsoft)
-- This post is provided 'AS IS' with no warranties and confers no rights
Mikhail Arkhipov (Microsoft) - 29 Dec 2005 05:03 GMT
On 12/27/05 14:15, in article ezSkLLzCGHA.3140@TK2MSFTNGP14.phx.gbl,

> The IDE will not stop reformatting the HTML.
>
[quoted text clipped - 17 lines]
>          URL http://metromilwaukee.com/
>          URL http://clintongallagher.metromilwaukee.com/

I assume you meant

<dl>
<dt class="..." onclick="...">Example</dt>
    <dd id="..." class="...">
    Monday
    </dd>
</dl>

It is difficult to say from the markup above, but it might be that editing
in Design view introduced a whitespace after Monday.

<dd>
   Monday
</dd>

really renders as

Monday<space>

When you place caret after 'Monday' and switch to Design view, you'll see
that caret is one space after the 'y'. Until you type, this is 'virtual'
whitespace or, rather, whitespace that is rendered instead of all spaces and
new line symbols that come after 'Monday'. If at this point you type, say,
A, making the string 'Monday A', the space becomes real and now is
represented by a single space character.

Designer and formatter always try to preserve page rendering over
formatting. Since now there are spaces left after A (all the collapsed
spaces went into the space between y and A, </dt> moves to immediately after
A preserving page rendering. What is at this point on the page is

Monday<space>A

Adding back newlines and tabs/indents would make text different:

Monday<space>A<space>

vs

Monday<space>A

which is different in rendering from Monday<space>A. Same might happen with
<TD> and other elements where whitespace is significant.

Generally, W3C recommends avoiding putting trailing whitespace in elements
where rendering might be different

http://www.w3.org/TR/html4/struct/text.html#h-9.1

<quote>

In order to avoid problems with SGML line break rules and inconsistencies
among extant implementations, authors should not rely on user agents to
render white space immediately after a start tag or immediately before an
end tag. Thus, authors, and in particular authoring tools, should write:

 <P>We offer free <A>technical support</A> for subscribers.</P>

and not:

 <P>We offer free<A> technical support </A>for subscribers.</P>

</quote>

Thanks
Mikhail Arkhipov (Microsoft)
-- This post is provided 'AS IS' with no warranties and confers no rights
clintonG - 29 Dec 2005 15:58 GMT
<snip />

Thank you for your reply Mikhail but I do not use Design View. On a rare
occassion I will go into Design View to use a smart tag to apply a template
when learning a new control but that's about it. I've been coding HTML
manually since day one and I always use source view.

If there is any white space involved it would be in the source where I often
use tabs or spaces to align elements for readability. We were told that
Visual Studio does not mangle HTML anymore. This is false. It removes
carraige returns, line feeds, tabs, and spaces, and it wraps elements such
as dt and ul on a regular basis.

For example I will manually enter tabs or use the Indent Tool on a ul
element in source view this way...

<ul>
   <li>.....</li>
   <li>.....</li>
</ul>

It will then be mangled like this

<ul><li>.....</li><li>.....</li>
</ul>

Visual Studio also reformats the #region in the source code and will not
allow me to remove the indentation to keep the #region aligned to the left
without any indentation which makes reading much easier for me. I can remove
the indentation manuallu but some will always be replaced and others will
not.

<%= Clinton Gallagher
Mikhail Arkhipov (Microsoft) - 29 Dec 2005 17:33 GMT
On 12/29/05 7:58, in article uD9lmBJDGHA.1028@TK2MSFTNGP11.phx.gbl,

> <snip />
>
[quoted text clipped - 29 lines]
>
> <%= Clinton Gallagher

Can you please give me repro steps? I was able to repro the case with <DT>
when editing in Design view, so that's what I explained. If you are always
in Source, the only case VS can reformat the code is when you invoke
formatting manually via Edit | Advanced | Format Document or Format
Selection (^K^D). In this case VS uses formatting rules specified in Tools |
Options | Text Editor | HTML | Formatting | Per Tag Formatting... which are
customizable

When exactly formatting changes? It should never spontaneously change in
Source view. All issues you have mentioned applied to editing in Design view
only, even in VS 2003 and earlier.

Thanks
Mikhail Arkhipov (Microsoft)
-- This post is provided 'AS IS' with no warranties and confers no rights
clintonG - 30 Dec 2005 02:03 GMT
Yea, I know its "not supposed to" but it has been. Funny, I just went into
Options > Text Editor > HTML and observed Tag wrapping was enabled at 80
characters which I just unchecked. That explains one problem I've also
observed but does not seem to explain why carraige returns are being removed
from the formatting of some HTML elements which are being concatenated to
one another.

The concatentation seems to only occur with child elements such as dd which
is a child of dt and li which is a child of ul where the child will be
concatenated to the closing bracket of the parent's closing tag. Am I making
sense? I wish I could make it easier to reproduce for you but to show you
examples such as...

// child element concatenated to parent
<ul><li>...</li>
</ul>

// desired formatted results may include indenting on parent and child
   <ul>
       <li>...</li>
   </ul>

As for spontaneous reformatting I have not nailed that down and do not know
exactly how to replicate yet. One occurence I do know occurs during copy and
paste from one file to another. When doing that I've observed id values are
refactored to some generic value. This bugs the sh!t out of me and I think I
finally found the setting to turn that off. Other occurences may happen when
moving from tab to tab or opening and closing the file in a new tabbed
window. I'm not sure yet.

I've never spent any time in the Text Editor > HTML > Format > Tag Specific
Options settings which would all be set at their default. Out of curiosity I
will study those options. Thanks for reminding me they exist.

I'd also like to fully understand what Options > Text Editor > HTML > Format
> Server tag : Assembly definition actually means rather than just set to
lower case as I've just done. I've been using XHTML 1.0 Transitional to stay
out of quirks mode and the mixed case of controls and their attributes in
the HTML source results in the IDE underlining the mixed case elements with
the red squiggles and information tootip regarding non-compliance with
XHTML. (by the way, I've sent this suggestion to product feedback noting the
intellisense tooltip warnings and related intellisense information should
support copy to clipboard.)

Man a guy could do a whole blog just on learning how to use the Options heh?
Too many of the settings are just sitting there and not documented (to my
knowledge) leaving us to figure out settings by chance. I appreciate your
comments as they have helped me focus on settings I thought I had set but
clearly over-looked but the changes to settings I have made tonight do not
infeer I have discovered a solution to resolve the reformatting of child
elements in the HTML source.

<%= Clinton Gallagher

> On 12/29/05 7:58, in article uD9lmBJDGHA.1028@TK2MSFTNGP11.phx.gbl,
>
[quoted text clipped - 55 lines]
> Mikhail Arkhipov (Microsoft)
> -- This post is provided 'AS IS' with no warranties and confers no rights
Mikhail Arkhipov (Microsoft) - 30 Dec 2005 03:41 GMT
On 12/29/05 18:03, in article ODZKqTODGHA.1268@TK2MSFTNGP12.phx.gbl,

> Yea, I know its "not supposed to" but it has been. Funny, I just went into
> Options > Text Editor > HTML and observed Tag wrapping was enabled at 80
[quoted text clipped - 109 lines]
>> Mikhail Arkhipov (Microsoft)
>> -- This post is provided 'AS IS' with no warranties and confers no rights

There is an option in Text Editor | HTML | Miscellaneous | "Format HTML On
Paste" and "Auto ID on Paste" - make sure both are off. There might be a bug
that paste code does not respect the setting - I want to know if that is so
so we can debug and fix it.

Mixed case in fine for server controls since their markup never goes to the
client. Validation code knows it is a server control so it should not
complain. ASP.NET control attribute names are often long and are barely
readable in all-lowercase.

Thanks
Mikhail Arkhipov (Microsoft)
-- This post is provided 'AS IS' with no warranties and confers no rights
clintonG - 30 Dec 2005 23:43 GMT
<snip />

> There is an option in Text Editor | HTML | Miscellaneous | "Format HTML On
> Paste" and "Auto ID on Paste" - make sure both are off. There might be a
[quoted text clipped - 12 lines]
> Mikhail Arkhipov (Microsoft)
> -- This post is provided 'AS IS' with no warranties and confers no rights

You know, last night when I responded to you I noticed Auto ID on Paste
was checked. I even mentioned it and unchecked it. Tonight I return and
read your comments which I am replying to now. I returned to Auto ID
on Paste and its checked all over again! I swear I unchecked it last night
and I saved the settings because I also unchecked Format HTML on
Paste last night and tonight is remains unchecked. Very strange behavior.

Last night I also changed the Format of Server tags from Assembly definition
to lower case but they too are reset from lower case back to Assembly
definition.

I saved, closed and restarted VS2005 and settings appear to be saved.
I'll give it time to make sure I am not misbelieving I made the changes
last night and saved them when in fact I may not have.

<%= Clinton Gallagher
Mikhail Arkhipov (Microsoft) - 30 Dec 2005 03:43 GMT
On 12/29/05 18:03, in article ODZKqTODGHA.1268@TK2MSFTNGP12.phx.gbl,

> Yea, I know its "not supposed to" but it has been. Funny, I just went into
> Options > Text Editor > HTML and observed Tag wrapping was enabled at 80
[quoted text clipped - 109 lines]
>> Mikhail Arkhipov (Microsoft)
>> -- This post is provided 'AS IS' with no warranties and confers no rights

I believe you can copy warning/error text from Error List window which you
can open via View | Error List.

Thanks
Mikhail Arkhipov (Microsoft)
-- This post is provided 'AS IS' with no warranties and confers no rights

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.