user12849275
user12849275

Reputation:

How to tell JetBrains IDE that template string is JS code

I have an ES6 template string, which represents JS code. If I put <script> tags around it, JetBrains IntelliJ will do syntax highlighting and checking, but not if there are no script tags.

Is there a way to tell JetBrains IDE how to interpret the template string?

enter image description here

It's definitely the presence/absence of the html tag.

Upvotes: 3

Views: 679

Answers (1)

lena
lena

Reputation: 93728

IDEA auto-injects HTML in JavaScript string literals/template string if there are HTML tags in it; to inject other languages, you need adding language injection manually - for example, the language can be temporary injected via Inject language or reference intention available on Alt+Enter:

enter image description here

You can also annotate your injection with comments to make it permanent:

//language=JS
const baz = `console.log("test")`

See https://www.jetbrains.com/help/idea/using-language-injections.html for more information

Upvotes: 4

Related Questions