如何在Visual Code中内联忽略格式?

问题描述 投票:1回答:1

哪个格式化程序使用VCode?我在某处读到VC使用jsbeautifier所以我尝试在我的.ejs模板中添加兼容的忽略注释,但无济于事。

formatting visual-studio-code inline ignore
1个回答
4
投票

据我所知,如果没有扩展,就没有办法做到这一点。

但是,如果使用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>
© www.soinside.com 2019 - 2024. All rights reserved.