Reputation: 373
How can I make PhpStorm treat the script tags with the type="text/plain"
property as JavaScript? For example the following fragment:
<script type="text/plain">
alert("test");
</script>
I have tried adding a language injection with the following config, which makes code highlighting work, but code style doesn't work. Every time I reformat the code, it just appends a new line at the bottom of the script tag. It should indent the alert by 4 spaces, just like it does with a script tag that doesn't have the type="text/plain"
property.
The reason I'm using type="text/plain"
is because I'm using a GDPR JavaScript plugin, that only loads the JavaScript after the user has given consent to marketing for example.
Upvotes: 2
Views: 539
Reputation: 165118
The text/plain
type seems to be hardcoded (special handling by the IDE): even though you can make Language Injection to work (the code will be displayed using JavaScript syntax colors) it still shows up as "Plain Text fragment" when Alt + Enter Quick Fix menu is invoked inside. Plus that "extra line at the end" and "no indenting" issues...
Therefore try another type, e.g. text/script
(Language Injection rule works just fine here).
If you have concerns that some browsers may actually execute it (because of the script
part after the text/
) then try another custom type, e.g. text/script-template
, text/text
etc.
Upvotes: 3