adi*_*518 2 formatting visual-studio-code
Visual Code 使用哪种格式化程序?我在某处阅读了它使用的内容,jsbeautifier因此我尝试向我的.ejs模板添加兼容的忽略注释,但它不起作用。
据我所知,没有扩展就没有办法做到这一点。
但是,如果您使用此扩展名,您可以完全控制格式。它还使用了 js-beautify,但它增加了配置。
正如 js-beautify文档中所指定的,“保留”指令仅适用于 javascript 部分。我已经在ejs文件的脚本标签中对此进行了测试,并且格式化文档不会更改console.log语句的缩进。实际上,这根本没有更改任何设置。我只是安装了扩展程序,将此文件另存为index.ejs并观察到 vscode 将语言模式设置为html.
我的测试页面
// These comments DON'T work because they aren't in a javascript section of the code
/* beautify preserve:start */
<h1><%= title %></h1>
/* beautify preserve:end */
<ul>
</ul>
<script>
function log() {
// Without the beautify comments, format document will move console.log
// to align with this
/* beautify preserve:start */
console.log('hello');
/* beautify preserve:end */
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4181 次 |
| 最近记录: |