javascript - Treat inline script tags with type="text/plain" as JavaScript
问题描述
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.
解决方案
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.
推荐阅读
- javascript - 为什么AI在追逐/奔跑时会振动
- javascript - 视频 JS 播放器的关键 CSS 中断
- python - 在 Shell 中从同一个 .py 调用两个不同的 Python 函数
- python - 聚合相应输入数组包含所有零行输入的数组标签
- python - 如何在ZipFile模块python中获取解压缩的调试日志
- ruby-on-rails - 当无法传递道具时,从父组件和子组件获取数据
- groovy - 如何在 Katalon 上获取测试用例失败的步骤数?
- powershell - AntivirusProduct 删除特定的
- sql - Oracle中的多个嵌套表
- c# - 从 C# 将 ngrok 控制台应用程序作为进程运行不起作用