How do I highlight my inline script with type="text/javascript-lazy" as if it were javascript?

Hey,

In my projects I have to "hide" my inline javascript from Angular.js by renaming it.
How can I still have Syntax-Highlighting etc. as if the type would be just text/javascript?

Regards,
Claas M.

15 comments
Comment actions Permalink

Hi there,

Please provide some sample that can be copy-pasted.

0
Comment actions Permalink

You mean an example scenario?


Capture.PNG





Here, the <script> part is not highlighted as JavaScript, because the type is javascript-lazy and I cant change the type to javascript (for unrelated reasons).

But I still want it to be highlighted as if the type were text/javascript.

Like so:
Capture.PNG

How can I achieve that? I hope you understand what I mean.

P.S Inserting HTML code didn't work on this forum

0
Comment actions Permalink

Sure. Create custom Language Injection rule for that:
screen01.png

NOTE that such fragments with custom injected language will have some backgound color (light green using Default color scheme).

P.S Inserting HTML code didn't work on this forum

Work fine for me. See below -- standard functionality (text copied from IDE using colors of my current color scheme)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE">
    <title></title>
    <link rel="icon" href="/favicon.ico" type="image/ico">
    <link rel="stylesheet" href="/testing/css.css"/>
</head>
<body>
<script type="text/javascript-lazy">
    console.log("Hello World");
</script>
<script type="text/javascript">
    console.log("Hello World");
</script>
<header></header>
<footer></footer>
</body>
</html>
0
Comment actions Permalink

My Language Injection Settings doesn't have an XPath Condition Input field:
Capture.PNG
Why is that? I'm using Webstorm 10.0.4

0
Comment actions Permalink

The one that I've used is of "XM Tag Injection" while you did "Generic JS"

screen01.png

"Generic JS" is for rules that will be used inside JavaScript fragments only while you need injection into <script> tag .. which is HTML/XML

0
Comment actions Permalink

Ah okay. Works now, thanks :)

0
Comment actions Permalink

How can this be done if XPath plugin is no more compatible with recent versions of IntelliJ?

0
Comment actions Permalink

XPath plugin is bundled with IDEA and is definitely compatible with it...

0
Comment actions Permalink

But "XPath condition" field is inactive in my case. Should I enable it somehow?

0
Comment actions Permalink

Config screenshot:

The XPath fields looks OK but I can't enter there anything (it's inactive, in fact).

0
Comment actions Permalink

Thanks. PyCharm doesn't bundle XPath plugin (https://youtrack.jetbrains.com/issue/PY-2214), and a third-party  XPathView + XSLT-Support plugin (https://plugins.jetbrains.com/plugin/237-xpathview--xslt-support) is targeted for Idea only and outdated (you will see messages like "Plugin 'XPathView + XSLT-Support' can't be loaded because: Plugin does not include any module dependency tags in its plugin.xml therefore is assumed legacy and can be loaded only in IntelliJ IDEA" if you inspect your log)

0
Comment actions Permalink

So there is no way to get this working? :(

0
Comment actions Permalink

So its 2020, and this is all documented for PhpStorm 2020.2 but it does not work ... XPath Plugin is enabled, settings seam as described, What am I missing?

answer: namespace matters a lot: phpstorm only suggest http://www.w3.org/1999/xhtml but it needs to be exactly http://www.w3.org/1999/html

and now it works:

0

Please sign in to leave a comment.