Auto html format/indent in Visual Studio .NET?

S

Steve Franks

Is there any way to tell VS to automatically reformat my HTML view to add
lines and tabs/spacing to create nicely formatted HTML in the viewer? I am
using Visual Studio 2005 .NET Beta 2

For example, let's say I paste this HTML into VS.NET "source" view:

<table><tr><td>val1</td><td>val2</td></tr></table>

I'd like to issue a command to VS to have it reformat this source and change
it to this in the editor:

<table>
<tr>
<td>val1</td>
<td>val2</td>
</tr>
</table>

Is there any such command or built-in functionality to do this?

If not, does anyone know of a 3rd party tool (or perhaps an alternative HTML
designer tool) that will do this?

Thanks!

Steve
 
J

Juan T. Llibre

Try this :

"Tools", "Options", select the checkbox "Show All Settings",
scroll to "Text Editor", and then "All languages", "Tabs",
and set your default "Indenting" and "Tab" preferences.

It will work the way you set it from that point on.

It should reformat the HMTL source to the specs you select
when you close and open the file after pasting the code,
although I don't guarantee it.

I don't know if it will reformat poorly-formatted
code to the extent you say you want it reformatted.

It's worth a try, anyway.
 
S

Steve Franks

Juan T. Llibre said:
Try this :

"Tools", "Options", select the checkbox "Show All Settings",
scroll to "Text Editor", and then "All languages", "Tabs",
and set your default "Indenting" and "Tab" preferences.

It will work the way you set it from that point on.

It should reformat the HMTL source to the specs you select
when you close and open the file after pasting the code,
although I don't guarantee it.

Thanks.I fFound that but its not making any difference. Here's what I am
doing:

I do not have a Show All Settings checkbox. However I did fine Text
Editor-All Languages-Tabs. In the top section none of the radio boxes for
"none,block,smart" were checked. I tried selecting "block", then I created
a new page and cut/pasted html but it did not reformat it. I tried saving it
and it didn't make a difference. Then I switched to Design view and back to
Source mode, still no difference. Then I repeated the same thing but with
"smart" radio selected. Nonthing made a difference.

Any ideas?

Thanks,

Steve
 
J

Juan T. Llibre

re:
Any ideas?

Nailed it...

"Tools", "Options", scroll to "Text Editor", and then "HTML",
"Miscellaneous", select "Format HTML on Paste".

That does exactly what you want.

It's amazing what you can find out by playing around with the IDE.
 
S

Steve C. Orr [MVP, MCSD]

Simply press:
Control + K
Control + D

....and the code will be auto-formatted. This works in HTML and in code
(VB/C#) windows.
 
J

Juan T. Llibre

Yup.

That does exactly the same thing, but setting the
"Format HTML on Paste" option doesn't even
require doing that, when pasting.

That's a nifty keyboard shortcut when you're a sloppy coder, though.
Two commands, and everything is formatted for you.

;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top