不要在VSCode的autoformatter之前添加额外的换行符和标签

时间:2016-05-10 15:42:18

标签: html visual-studio-code autoformatting

VSCode的格式化程序会自动在<head><body>标记之前以及在结束</html>标记之前插入换行符。在默认设置中,存在以下行:

// List of tags, comma separated, that should have an extra newline before them. 'null' defaults to "head, body, /html".
"html.format.extraLiners": null,

我尝试将用户设置中的html.format.extraLiners设置为"",也设置为"none",但它没有改变任何内容。

这就是我得到的:

<html>

<head></head>

<body></body>

</html>

这就是我想要的:

<html>
<head></head>
<body></body>    
</html>

2 个答案:

答案 0 :(得分:5)

由于某种原因,在这种情况下,空字符串的处理方式与null相同。可能是因为空字符串和null在JS中都是假的。代码可能已使用truthy / falsy检查而不是cities实现此设置的默认设置。

不过,

=== null应该可行。由单个空格字符组成的字符串也适用于我:

"none"

答案 1 :(得分:2)

我安装了"JS-CSS-HTML Formatter"扩展程序,这导致了问题。卸载后,现在一切都按预期工作。