Whenever I reformat html source code in Visual Studio with Ctrl-K, Ctrl-D it formats my source code like this:
每当我使用Ctrl-K重新格式化Visual Studio中的html源代码时,按Ctrl-D格式化我的源代码如下:
<p>
text</p>
<p>
more text</p>
How can I make it use the following format instead?
我怎样才能使用以下格式?
<p>
text
</p>
<p>
more text
</p>
I know that there are settings at Options-> Text Editor -> Html -> Formatting, but I could not find suitable there.
我知道选项 - >文本编辑器 - > Html - >格式化中有设置,但我找不到合适的设置。
Thanks,
谢谢,
Adrian
阿德里安
Edit: I've checked the tag-specific settings, and page break for p tags is set to "Before opening, within, and after closing". Also, the little preview shows exactly the format I want to have. But Visual Studio still does it wrong. Could this have anything to do with Resharper being installed on my system?
编辑:我已经检查了特定于标签的设置,并且p标签的分页符设置为“在打开之前,之内和之后”。此外,小预览显示我想要的格式。但Visual Studio仍然做错了。这可能与Resharper安装在我的系统上有什么关系吗?
3 个解决方案
#1
19
The problem has nothing to do with ReSharper. This is a feature by design of the Visual Studio Source Formatter where it will attempt not to change the semantics of an element due to formatting options that you specify.
这个问题与ReSharper无关。这是Visual Studio源格式化程序设计的一个功能,它将尝试不更改由于您指定的格式化选项而导致的元素语义。
So, you specified that you want the p tags to have breaks within the content, but a break after a p tag would change the semantics of the content within the tag, thus the formatter ends up putting the closing p tag right after the content. To have the closing tag on a separate line you will need to explicitly add a space just before the end of the content and the closing tag.
因此,您指定了您希望p标记在内容中具有中断,但是在p标记之后的中断将更改标记内容的语义,因此格式化程序最终将结束p标记放在内容之后。要将结束标记放在单独的行上,您需要在内容结束和结束标记之前显式添加空格。
Thus:
从而:
<p>content</p>
will produce:
将产生:
<p>
content</p>
While (note the explicit inclusion of a space between the content and the closing p tag):
虽然(注意内容和结束p标签之间明确包含空格):
<p>content </p>
will produce:
将产生:
<p>
content
</p>
This is discussed in a blog post by Scott Guthrie in the 3rd paragraph from the bottom. Start counting from the paragraph right above the additional links section.
Scott Guthrie在博客文章中从底部的第3段中讨论了这一点。从附加链接部分正上方的段落开始计算。
#2
9
Click Tools, Options, Text Editor, HTML, Formatting, Tag Specific Options.
Add a new Client-side tag for p
(if it's not there already) and select Separate Closing tag
and Before, within, and after closing
.
单击工具,选项,文本编辑器,HTML,格式,标记特定选项。为p添加一个新的客户端标记(如果它不存在)并选择单独关闭标记以及关闭之前,之内和之后。
#3
0
Check this How Change Auto Formatting HTML In Visual Studio 2008 2010
在Visual Studio 2008 2010中查看此更改自动格式化HTML的方式
#1
19
The problem has nothing to do with ReSharper. This is a feature by design of the Visual Studio Source Formatter where it will attempt not to change the semantics of an element due to formatting options that you specify.
这个问题与ReSharper无关。这是Visual Studio源格式化程序设计的一个功能,它将尝试不更改由于您指定的格式化选项而导致的元素语义。
So, you specified that you want the p tags to have breaks within the content, but a break after a p tag would change the semantics of the content within the tag, thus the formatter ends up putting the closing p tag right after the content. To have the closing tag on a separate line you will need to explicitly add a space just before the end of the content and the closing tag.
因此,您指定了您希望p标记在内容中具有中断,但是在p标记之后的中断将更改标记内容的语义,因此格式化程序最终将结束p标记放在内容之后。要将结束标记放在单独的行上,您需要在内容结束和结束标记之前显式添加空格。
Thus:
从而:
<p>content</p>
will produce:
将产生:
<p>
content</p>
While (note the explicit inclusion of a space between the content and the closing p tag):
虽然(注意内容和结束p标签之间明确包含空格):
<p>content </p>
will produce:
将产生:
<p>
content
</p>
This is discussed in a blog post by Scott Guthrie in the 3rd paragraph from the bottom. Start counting from the paragraph right above the additional links section.
Scott Guthrie在博客文章中从底部的第3段中讨论了这一点。从附加链接部分正上方的段落开始计算。
#2
9
Click Tools, Options, Text Editor, HTML, Formatting, Tag Specific Options.
Add a new Client-side tag for p
(if it's not there already) and select Separate Closing tag
and Before, within, and after closing
.
单击工具,选项,文本编辑器,HTML,格式,标记特定选项。为p添加一个新的客户端标记(如果它不存在)并选择单独关闭标记以及关闭之前,之内和之后。
#3
0
Check this How Change Auto Formatting HTML In Visual Studio 2008 2010
在Visual Studio 2008 2010中查看此更改自动格式化HTML的方式