Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open cshtml files as HTML in Atom

Tags:

atom-editor

Based on this issue (https://github.com/atom/atom/issues/1718) from atom's github concerning the customFileTypes option, I have the following in my config.cson.

"*":
  core:
    customFileTypes:
      "source.html": [
        "cshtml"
      ]

My intention is for cshtml files to be automatically opened with the HTML grammar for syntax highlighting, however, my cshtml files still open as Plain Text.

If I change "source.html" to "source.gfm", then my cshtml files open as Github Flavoured Markdown, so I suspect that "source.html" isn't the name I should be using.

How can I get this to work? And, where can I get a list of names for grammars?

like image 416
user2943490 Avatar asked Dec 06 '25 02:12

user2943490


2 Answers

Made this work by using text.html.basic as the scope name, so my config looks like this:

"*":
  core:
    customFileTypes:
      "text.html.basic": [
        "cshtml"
      ]

To get a list of eligible scope names, open the Atom console (Ctrl+Alt+I in Windows, Ctrl+Shift+I in Linux) and run Object.keys(atom.grammars.grammarsByScopeName).

You get an array in return, so Object.keys(atom.grammars.grammarsByScopeName).sort().join('\n') will give you a nicely sorted list.

like image 136
user2943490 Avatar answered Dec 09 '25 01:12

user2943490


In case you want to display the file with the ASP.NET Razor theme (standard for .cshtml files), go ahead and do the following:

  1. Download the language-cshtml package https://atom.io/packages/language-cshtml

  2. Change you ~/.atom/config.cson to include the following:


"*":
  core:
    customFileTypes:
      "text.html.cshtml": "cshtml"
like image 20
Lucas Costa Avatar answered Dec 09 '25 03:12

Lucas Costa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!