HookyQR / VSCodeBeautify

Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code
MIT License
606 stars 180 forks source link

Ignore Directive a la js-beautify? #366

Open gadzuuks opened 4 years ago

gadzuuks commented 4 years ago

I wondered if the directives in js-beautify would be parsed by VSCodeBeautify, https://github.com/beautify-web/js-beautify specifically:

Directives Directives let you control the behavior of the Beautifier from within your source files. Directives are placed in comments inside the file. Directives are in the format / beautify {name}:{value} / in CSS and JavaScript. In HTML they are formatted as .

Ignore directive The ignore directive makes the beautifier completely ignore part of a file, treating it as literal text that is not parsed. The input below will remain unchanged after beautification:

// Use ignore when the content is not parsable in the current language, JavaScript in this case.
var a =  1;
/* beautify ignore:start */
{This is some strange{template language{using open-braces?
/* beautify ignore:end */

However, this doesn't appear to work. Am I expecting too much, or doing it incorrectly?

Provide the settings you use:

All default

Action performed

In a .html file:

<script language="javascript">
<!-- beautify ignore:start -->
// let php insert the user's name in a JS const
const userid = '<?=str_replace('XANTERRA\\ ','',$_SERVER['AUTH_USER ']);?>';
// let php insert the referer key provided in the URL query line, or the http referer if not in the query
 var referer = '<?=array_key_exists('referer ',$_GET) ? $_GET['referer '] : (array_key_exists('HTTP_REFERER ',$_SERVER) ? parse_url($_SERVER['HTTP_REFERER '],PHP_URL_HOST) : '');?>';
<!-- beautify ignore:end -->

Then run beautify

Expected results

No formatting change

Actual results

<!-- beautify ignore:start -->
// let php insert the user's name in a JS const
const userid = '<?=str_replace('XANTERRA\\ '
,'',$_SERVER['AUTH_USER
']);?>';
// let php insert the referer key provided in the URL query line, or the http referer if not in the query
var referer = '<?=array_key_exists('referer
',$_GET) ? $_GET['referer
'] : (array_key_exists('HTTP_REFERER
',$_SERVER) ? parse_url($_SERVER['HTTP_REFERER
'],PHP_URL_HOST) : '
');?>';
<!-- beautify ignore:end -->`