Manually set the language for highlighting code in visual studio

I manage my style declarations in a .cshtml file so that I can dynamically encode values, such as color codes, which I need to repeat often. I use MVC routing capabilities to serve stylesheets with the .css extension, so all this is opaque to the end user.

The .cshtml file contains mainly CSS, of course, with only a few dozen values ​​passed dynamically, and some calls to helpers that I wrote to make working with CSS easier, so I would like to be able to view this file with CSS highlighting code.

Question: Can I manually set the language for the hightlighting syntax for a given file using Visual Studio?

Note. I know this is easy with Notepad ++, but I would prefer to do everything with the same editor.

UPDATE . I realized that this problem can (I think) weld to "Where is the executable for the CSS source code editor (default)?". This is an option when choosing "Open With ..." in the CSS file, but not an option when choosing "Open With ..." in the .cshtml file, so if I could just navigate to its location using "Add" in this master, my problem is solved. But ... where is this editor ?!

UPDATE (2) : My hack works, but since it is ugly, I would still like to know how to open the default CSS editor.

UPDATE (3) . I could really use the solution here, and it seems like a general solution would be useful in many cases. Hence the generosity.

UPDATE (4) : Well, my hack really works - you just need to open the file using the HTML HTML editor instead of the Razor editor.

+4
source share
2 answers

Here is my hack:

You can open the .cshtml file using the Visual Studio HTML editor, and this editor will recognize CSS if it is nested inside <style> tags. But since the <style> (or any) is not allowed inside the .css file and will cause styles to break, the way around this is to insert open and close tags in razor or CSS comments:

 /*<style>*/ [my style declarations] /*</style>*/ 

OR

 @*<style>*@ [my style declarations] @*</style>*@ 

Ugh. But it works.

update . This works - just be careful to select the VS HTML editor and not the Razor editor when using the "open with ..." function

+3
source

Here's how to do it in Visual Studio 6:

Customize syntax coloring

To set syntax coloring for custom HTML change

  • Create a text file with the extension .hlx in the \msdev\bin\ide . The first line of the file is a signature that uniquely identifies the file type. It contains the name of the option that will be displayed on the "Source File Properties" page. After the signature line, the format is similar to the Windows initialization file format. A semicolon at the beginning of a line indicates a comment.

  • Create three sections in the file: the [Elements] section, the [Attributes] section, and the [Entities] section. Each section contains a list of names separated by spaces, carriage returns, or linear channels. Names do not have to be in alphabetical order. You must specify all the elements, attributes, and objects that you want to mark.

    See an example of a generic sample .hlx .

  • Save the .hlx file.

Note. If the custom option you specify in the .hlx file has the same name as the native HTML support, it will override the native HTML support. There is a 14 character limit for the name of the HTML option you choose.

+1
source

Source: https://habr.com/ru/post/1398829/


All Articles