SCSS Language Injection in Pycharm

2019-07-15 17:42发布

问题:

I'm trying to write a language injection for PyCharm that will recognize anything within a <style type="text/x-scss"></style> tag as SCSS. Through some inspection of IntelliJ and the PSI documentation, and direct editing of the IntelliLang.xml file, this is the closest I've gotten:

+ xmlTag().withChild(xmlAttribute().withLocalName(string().equalTo("type")).withValue(string().equalTo("text/x-scss"))).withNamespace(string().equalTo("http://www.w3.org/1999/xhtml"))

However, this (a) seems not to do anything, and (b) as soon as I close the Language Injections Pane, PyCharm rewrites the Java as xmlTag().withLocalName(string().matches("<none>")). What's the right way to do this and to get it to save?

回答1:

Turns out there is a built-in way to do this with SASS specifically.

Language Injection in WebStorm (scss into html)

Simply have your tag look like this:

<style rel="stylesheet/scss" type="text/css">

In our case, we use Django compressor, so this works fine as well:

<style rel="stylesheet/scss" type="text/x-scss">