如何在Visual Code中内联忽略格式? [英] How to inline ignore format in Visual Code?

查看:116
本文介绍了如何在Visual Code中内联忽略格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Which formatter VCode uses? I read somewhere VC uses jsbeautifier so I tried adding a compatible ignore comment to my .ejs template, but to no avail.

推荐答案

据我所知,没有扩展就无法做到这一点.

As far as I know, there is no way to do this without an extension.

但是,如果您使用此扩展名,则可以完全控制格式 .它还使用js-beautify,但添加了配置.

However, you have full control of the formatting if you use this extension. It also uses js-beautify, but it adds configuration.

如js-beautify docs 中所指定,"preserve"指令仅适用在javascript部分中.我已经在ejs文件的脚本标签中对此进行了测试,并且格式化文档不会更改console.log语句的缩进.实际上,此操作完全无需更改任何设置.我只安装了扩展名,将此文件另存为index.ejs,并观察到vscode的语言模式设置为html.

As specified in the js-beautify docs, the "preserve" directive only works in javascript sections. I have tested this in the script tag of an ejs file and formatting the document does NOT change the indentation of the console.log statement. This worked without changing any settings at all, actually. I simply installed the extension, saved this file as index.ejs and observed that vscode had the language mode set to 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>

这篇关于如何在Visual Code中内联忽略格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆