如何在 Atom 文本编辑器中按文件类型创建默认语法? [英] How do I make a default syntax by filetype in Atom text editor?

查看:36
本文介绍了如何在 Atom 文本编辑器中按文件类型创建默认语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 .ejs 文件具有 html 语法,但是,它总是以纯文本形式打开文件.

I want my .ejs files to have html syntax, however, it always opens the files as Plain Text.

在 sublime 中,您可以选择以当前扩展名打开所有内容...",然后选择您的语法.

In sublime you can choose "Open all with current extension as..." then choose your syntax.

我看到您可以更改左下角的语法

I see that you can change the syntax in the left bottom corner

如何打开具有特定语法的特定类型的文件?

How do you open files with a certain type with a specific syntax?

推荐答案

简易模式:包含

如果你的语言真的只是 HTML,你可以设置一个简单的包来处理这个问题.

Easy mode: include

If your language really is just HTML, you can set up a simple package to handle this.

创建一个名为 langugage-ejs 的包,然后在 grammars/ejs.cson 中,您可以将 HTML 包含为您关心的模式:

Create a package called langugage-ejs and in grammars/ejs.cson you can include HTML as having the patterns you care about:

'fileTypes': [
  'ejs'
]

'name': 'Embedded JavaScript'

'patterns': [
  {
    'include': 'source.html'
  }
]

'scopeName': 'source.ejs'

language-ipynb 当然是通过扩展 JSON 来做到这一点的.

language-ipynb certainly does this by extending JSON.

但实际上,您在 HTML 之上有模板标签,您希望编辑器能够识别这些标签.我能找到的最好的例子是 erb(嵌入式 Ruby 模板).它源自 HTML,但也添加了其他标签,如以下代码段所示:

In reality though, you have template tags on top of HTML that you would want to make the editor recognize. The best example I can find is for erb (Embedded Ruby templates). It sources from HTML but also adds on other tags as shown in this snippet:

...
'patterns': [
  {
    'begin': '<%+#'
    'captures':
      '0':
        'name': 'punctuation.definition.comment.erb'
    'end': '%>'
    'name': 'comment.block.erb'
  }
  {
    'begin': '<%+(?!>)[-=]?'
    'captures':
      '0':
        'name': 'punctuation.section.embedded.ruby'
    'end': '-?%>'
    'name': 'source.ruby.rails.embedded.html'
    'patterns': [
      {
        'captures':
          '1':
            'name': 'punctuation.definition.comment.ruby'
        'match': '(#).*?(?=-?%>)'
        'name': 'comment.line.number-sign.ruby'
      }
      {
        'include': 'source.ruby.rails'
      }
    ]
  }
  {
    'include': 'text.html.basic'
  }
]
...

这篇关于如何在 Atom 文本编辑器中按文件类型创建默认语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆