I have a file with a lot of this kind of thing in it:
我有一个文件里面有很多这样的东西
<asp:TableCell ID="TableCell9" runat="server">Company
Organization:</asp:TableCell><asp:TableCell ID="TableCell10" runat="server">
How can I get the formatter to change it to shows like this:
如何让格式化程序将其更改为如下所示:
<asp:TableCell ID="TableCell9" runat="server">Company Organization:</asp:TableCell>
<asp:TableCell ID="TableCell10" runat="server">
What I have tried:
我已经尝试:
I opened Tools->Options then browsed to Text Editor. I got a list of Languages. I selected HTML because that is the language that controls formatting for aspx files.
我打开工具->选项然后浏览到文本编辑器。我有一份语言清单。我选择了HTML,因为它是控制aspx文件格式的语言。
I changed "tag wrapping" to not have "Wrap tags when exceeding specified length" checked.
我将“标签包装”更改为没有“超过指定长度时的包装标签”检查。
I then pressed ctrl+k, ctrl+d (Format the document). This did not fix the problem.
然后按ctrl+k, ctrl+d(格式化文档)。这并不能解决问题。
What I don't want to have to do:
我不想做的是:
Edit the file manually to fix all the tags.
手动编辑文件以修复所有标记。
Any ideas?
什么好主意吗?
3 个解决方案
#1
21
I was having the same problem, and I found the answer on Scott Gu's blog.
我遇到了同样的问题,我在Scott Gu的博客上找到了答案。
The solution is to setup the formatting rules in Visual Studio (right click on any tag, click on Formatting and Validation, click on Tag Specific Options)
解决方案是在Visual Studio中设置格式规则(右键单击任何标记,单击格式和验证,单击标记特定的选项)
When press ctrl-k, ctrl-d the document will format as per your settings. If a closing tag does not move to a new line, it's because there is no space between the end tag and what is preceding it. This happens because Visual Studio is being careful to not change how the page is rendered.
按ctrl-k时,按下ctrl-d文档将按照您的设置进行格式化。如果结束标记不移动到新行,那是因为结束标记和之前的标记之间没有空格。这是因为Visual Studio小心翼翼地不更改页面的呈现方式。
For the full blog post checkout Scott Gu's blog post.
要查看完整的博客文章,请查看Scott Gu的博客文章。
http://weblogs.asp.net/scottgu/archive/2006/07/07/tip_2f00_trick_3a00_ -自定义-格式化html -视觉- web -开发-和- 2005. aspx -视觉工作室
#2
2
I found a way that works.
我找到了一种有效的方法。
In the list with HTML there is a File Extension Option.
在HTML列表中有一个文件扩展选项。
I added ASPX to that list and said to edit it with an XML editor (I suppose I could have just right clicked it and opened it with the xml editor, but I did not think of that till after).
我向该列表添加了ASPX,并要求使用XML编辑器对其进行编辑(我想我可以右键单击它,然后使用XML编辑器打开它,但我在此之后才想到这一点)。
Anyway, once it is open as an XML File I formatted it (ctrl+k, ctrl+d) and it formated the way I wanted it. I then removed the extension mapping and reopend the file again.
不管怎样,一旦它作为XML文件打开,我就格式化了它(ctrl+k, ctrl+d),它按照我想要的方式格式化了。然后,我删除了扩展映射并重新选择文件。
One last formatting adjusted the tab spacing and I was perfect!
最后一次格式化调整了制表符的间距,我做到了完美!
Note: When I did this the top line had this change made: from Page Language="C#"
to Page="" Language="C#"
I changed it back manually and all seemed to be well.
注意:当我这样做的时候,最上面一行做了这样的更改:从Page Language=" c# "到Page="" Language=" c# ",我手动更改了它,一切似乎都很好。
Later Note: Sadly, Visual Studio messes up the formatting every time I run the solution. Note that pressing ctrl+k, ctrl+d is fine and keeps my nice formatting, but when I run, Visual Studio collapses it down to a very unreadable format. :( Don't know how to fix it....
稍后注意:遗憾的是,Visual Studio每次运行解决方案时都会打乱格式。请注意,按ctrl+k, ctrl+d就可以了,并且保持了良好的格式,但是当我运行的时候,Visual Studio将它折叠成一个非常不可读的格式。(不知道如何修复它....
#3
1
The answer should be: Tools-Options->Text Editor->HTML-Format->Tag Specific Options Then in ASP.NET Controls look for your tag. If it's not there you might need to Add it (New Tag) and set the Line breaks as you want them.
答案应该是:工具-选项->文本编辑器-> html格式->标签特定选项然后在ASP。NET控件寻找您的标记。如果没有,您可能需要添加它(New Tag),并根据需要设置换行符。
However I've found that this does not always work.Visual Studio respects the per tag colorization but Line breaks are not always respected.
然而,我发现这并不总是有效的。Visual Studio尊重每个标签的颜色化,但是换行符并不总是被尊重的。
So if this doesn't work for you, you might need to do a Search-Replace hack (Look for and replace with a NewLine in the middle), thenk try Format document and that should work.
因此,如果这对您不起作用,您可能需要执行搜索-替换hack(寻找并替换为中间的换行),然后尝试格式化文档,这应该是可行的。
#1
21
I was having the same problem, and I found the answer on Scott Gu's blog.
我遇到了同样的问题,我在Scott Gu的博客上找到了答案。
The solution is to setup the formatting rules in Visual Studio (right click on any tag, click on Formatting and Validation, click on Tag Specific Options)
解决方案是在Visual Studio中设置格式规则(右键单击任何标记,单击格式和验证,单击标记特定的选项)
When press ctrl-k, ctrl-d the document will format as per your settings. If a closing tag does not move to a new line, it's because there is no space between the end tag and what is preceding it. This happens because Visual Studio is being careful to not change how the page is rendered.
按ctrl-k时,按下ctrl-d文档将按照您的设置进行格式化。如果结束标记不移动到新行,那是因为结束标记和之前的标记之间没有空格。这是因为Visual Studio小心翼翼地不更改页面的呈现方式。
For the full blog post checkout Scott Gu's blog post.
要查看完整的博客文章,请查看Scott Gu的博客文章。
http://weblogs.asp.net/scottgu/archive/2006/07/07/tip_2f00_trick_3a00_ -自定义-格式化html -视觉- web -开发-和- 2005. aspx -视觉工作室
#2
2
I found a way that works.
我找到了一种有效的方法。
In the list with HTML there is a File Extension Option.
在HTML列表中有一个文件扩展选项。
I added ASPX to that list and said to edit it with an XML editor (I suppose I could have just right clicked it and opened it with the xml editor, but I did not think of that till after).
我向该列表添加了ASPX,并要求使用XML编辑器对其进行编辑(我想我可以右键单击它,然后使用XML编辑器打开它,但我在此之后才想到这一点)。
Anyway, once it is open as an XML File I formatted it (ctrl+k, ctrl+d) and it formated the way I wanted it. I then removed the extension mapping and reopend the file again.
不管怎样,一旦它作为XML文件打开,我就格式化了它(ctrl+k, ctrl+d),它按照我想要的方式格式化了。然后,我删除了扩展映射并重新选择文件。
One last formatting adjusted the tab spacing and I was perfect!
最后一次格式化调整了制表符的间距,我做到了完美!
Note: When I did this the top line had this change made: from Page Language="C#"
to Page="" Language="C#"
I changed it back manually and all seemed to be well.
注意:当我这样做的时候,最上面一行做了这样的更改:从Page Language=" c# "到Page="" Language=" c# ",我手动更改了它,一切似乎都很好。
Later Note: Sadly, Visual Studio messes up the formatting every time I run the solution. Note that pressing ctrl+k, ctrl+d is fine and keeps my nice formatting, but when I run, Visual Studio collapses it down to a very unreadable format. :( Don't know how to fix it....
稍后注意:遗憾的是,Visual Studio每次运行解决方案时都会打乱格式。请注意,按ctrl+k, ctrl+d就可以了,并且保持了良好的格式,但是当我运行的时候,Visual Studio将它折叠成一个非常不可读的格式。(不知道如何修复它....
#3
1
The answer should be: Tools-Options->Text Editor->HTML-Format->Tag Specific Options Then in ASP.NET Controls look for your tag. If it's not there you might need to Add it (New Tag) and set the Line breaks as you want them.
答案应该是:工具-选项->文本编辑器-> html格式->标签特定选项然后在ASP。NET控件寻找您的标记。如果没有,您可能需要添加它(New Tag),并根据需要设置换行符。
However I've found that this does not always work.Visual Studio respects the per tag colorization but Line breaks are not always respected.
然而,我发现这并不总是有效的。Visual Studio尊重每个标签的颜色化,但是换行符并不总是被尊重的。
So if this doesn't work for you, you might need to do a Search-Replace hack (Look for and replace with a NewLine in the middle), thenk try Format document and that should work.
因此,如果这对您不起作用,您可能需要执行搜索-替换hack(寻找并替换为中间的换行),然后尝试格式化文档,这应该是可行的。