哪个格式化程序使用VCode?我在某处读到VC使用jsbeautifier
所以我尝试在我的.ejs
模板中添加兼容的忽略注释,但无济于事。
据我所知,如果没有扩展,就没有办法做到这一点。
但是,如果使用this extension,则可以完全控制格式。它也使用js-beautify,但它增加了配置。
正如js-beautify docs中指定的那样,“preserve”指令仅适用于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>