Double Filetype Extension: Correct Syntax Highlighting in Sublime Text 3

十年热恋 提交于 2019-12-10 19:12:29

问题


I am working with some .scss.liquid files and they always open as HTML Liquid, no matter how many times I set the syntax.

Update:

I tried open all with current extension as option, but unfortunately this affects files that are .js.liquid and .html.liquid as well.


回答1:


Sublime Text allows you to apply settings on a per-language basis (actually, per syntax). One of the available settings allows you to map file extensions to the given syntax.

Assuming you're using a syntax named SCSS, Create an SCSS settings file in your User settings: /path/to/packages/User/SCSS.sublime-settings, then add the file extension setting:

{
    "extensions":
    [
        "scss.liquid"
    ]
}

As you can see, it's a json file, and extensions is a list, so you can add as many file extensions as you need. Do not add the leading dot.

Caveat about the file name

The file name for the settings file must match the actual syntax name, including case. In this case it has to be SCSS.sublime-settings. Other examples include:

NAnt Build File.sublime-settings
Ruby on Rails.sublime-settings
Rd (R Documentation).sublime-settings
Java Server Page (JSP).sublime-settings



回答2:


I found a relatively straightforward solution to this problem.

  1. Install ApplySyntax
  2. Create the following rules in ApplySyntax.sublime-settings -- User:

    "syntaxes": [
        {
            "syntax": "SCSS",
            "extensions": ["scss.liquid"]
        },
        {
            "syntax": "JavaScript/JavaScript",
            "extensions": ["js.liquid"]
        },
    ]
    

Update: I now see there is no need for an extra package. Please see accepted answer and my video (in the comments) for tips on how to make it work.



来源:https://stackoverflow.com/questions/49495487/double-filetype-extension-correct-syntax-highlighting-in-sublime-text-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!