Using customFileTypes to change the language for HTML


#1

How might I change my Atom configuration so that HTML files open as HTML with JSX textContent (a language from language-javascript-jsx)?

Here are the contents of my config.cson up until customFileTypes ends.

"*":
  core:
    closeEmptyWindows: false
    customFileTypes:
      "text.html": [
        "jsx"
      ]

I’ve tried all sorts of combinations here, like source.html, text.html.basic for the key I’ve tried and source.jsx or text.jsx for the value.


#2

I did the following:

  1. Launch Atom in my local atom repository using atom .
  2. Added the configuration below to my config.cson
  3. Enter the command in the terminal: touch foo.jsx
  4. Double-clicked foo.jsx in the Tree View

The empty file opened and was recognized as HTML.

Contents added to my config.cson:

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

#3

I notice you used jsx. What happened when you tried a .html extension? I am looking to open HTML files with the JSX language enabled.


#4

What is the JSX language scope? Have you taken a look at the FAQ about how to do this?


#5

Yes, I have read the FAQ. I don’t know what the scope of language-javascript-jsx package is, if that’s what you’re asking.

Simply put, I’m trying to set something like “always open using this language” for a file extension. I read through the FAQ, which I found through Google before I posted here. I tried various combinations. I also tried using the CTRL keystroke to quickly switch languages via keyboard, which also does not seem to work on Mac. I look forward to seeing language switching working in Atom. If you can demonstrate it, even if I can’t replicate it, that’s okay. I’m just not seeing the ability to accomplish this.


#6

The FAQ has a link to the Atom Flight Manual section on how to determine this. You’re also reversing the direction of the mapping if you want Atom to recognize files with the html extension as some language, you have to write the customFileTypes section like this:

"*":
  core:
    customFileTypes:
      "source.some-language-scope": [
        "html"
      ]

The Flight Manual also has a section on how to change the language for the current file. I just tested it and it works fine using Atom v1.16.0-dev-ef0619048 and v1.14.4 on Mac OS X 10.12.3.


#7

Thank for explaining this step-by-step. It helped me resolve this issue.