在 Atom 中以 HTML 格式打开 cshtml 文件

Open cshtml files as HTML in Atom

基于 atom 的 github 关于 customFileTypes 选项的这个问题 (https://github.com/atom/atom/issues/1718),我在 config.cson.

中有以下内容
"*":
  core:
    customFileTypes:
      "source.html": [
        "cshtml"
      ]

我的意图是使用 HTML 语法自动打开 cshtml 文件以进行语法高亮显示,但是,我的 cshtml 文件仍以纯文本打开。

如果我将 "source.html" 更改为 "source.gfm",那么我的 cshtml 文件将打开为 Github Flavored Markdown,因此我怀疑 "source.html" 不是我应该使用的名称正在使用。

我怎样才能让它工作?还有,我在哪里可以获得语法名称列表?

通过使用 text.html.basic 作为作用域名称来完成这项工作,因此我的配置如下所示:

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

要获取符合条件的范围名称列表,请打开 Atom 控制台 (Ctrl+Alt+I in Windows, Ctrl+Shift+I in Linux) 和 运行 Object.keys(atom.grammars.grammarsByScopeName).

您在 return 中得到一个数组,因此 Object.keys(atom.grammars.grammarsByScopeName).sort().join('\n') 将为您提供一个排序良好的列表。

如果您想显示带有 ASP.NET Razor 主题(.cshtml 文件的标准)的文件,请继续执行以下操作:

  1. 下载language-cshtml包 https://atom.io/packages/language-cshtml

  2. 将您的 ~/.atom/config.cson 更改为包括以下内容:


"*":
  core:
    customFileTypes:
      "text.html.cshtml": "cshtml"