Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.


1 Answers

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

like image 191
lena Avatar answered Feb 04 '26 15:02

lena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!