How to inline ignore format in Visual Code?

為{幸葍}努か 提交于 2020-06-28 06:42:08

问题


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.


回答1:


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

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

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.

My test page

// 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>


来源:https://stackoverflow.com/questions/46214935/how-to-inline-ignore-format-in-visual-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!