Rythm formatter custom language plugin

Hi,
I'm currently writing a plugin for IntelliJ which should recognize rythm engine code. It's a template engine where the syntax starts with @.
In my case rythm is mixed with HTML in a .html file.

What is working so far is the syntax highlighting and some HTML formatting.
This is a part of the code which should be formatted:

@extends(XXX)

@section(xxx){
<script src="/xxx/xxx/xxx" type="xxx/xxx></script>
<script src="/xxx/xxx/xxx" type="xxx/xxx></script>
<script src="/xxx/xxx/xxx" type="xxx/xxx></script>
}
@section(xxx) {
<li>
<a href="/xxx">@i18n("XXX.xxx.xxx")</a>
</li>
}
...

---------------------------------------------
And this is how it should look like:
@extends(XXX)

@section(xxx){
     <script src="/xxx/xxx/xxx" type="xxx/xxx></script>
     <script src="/xxx/xxx/xxx" type="xxx/xxx></script>
     <script src="/xxx/xxx/xxx" type="xxx/xxx></script>
}
@section(xxx) {
     <li>
         <a href="/xxx">@i18n("XXX.xxx.xxx")</a>
     </li>
}

So this is what I want:
After the rythm part the HTML part should be indented by 4 spaces. After an opening tag of HTML rythm code should also be indented by 4 spaces. After a closing tag rythm should not be indented.

 

Any help appreciated.

0
4 comments

Hi. As example you can look into the formatting implementation in handlebars plugin: See https://github.com/JetBrains/intellij-plugins/tree/master/handlebars

0

Thanks for your reply. This helped me a lot.

How can I indent the XmlBlock in the DataLanguageBlockWrapper?

When I'm opening the PSI Viewer it looks like this:



Like I said, the <script Tag should be intended by 4 also the <li> Tag should be intended by 4 and so on.

 

Is it possible to say IntelliJ to start the indent with 4?

This is how it should look like:




0

That's a tough question. In practice we use a different template formatting engine for many templates since the one in the public API has severe limitations and is not capable of maintaining proper HTML indentation structure. The problem is that the new engine is not a part of public API yet but there are plans to move it there and simply deprecate the old one. But this unlikely will happen within 2016.3 timeframe. I have created a task you may follow: https://youtrack.jetbrains.com/issue/IDEA-161600

1

Thanks for your answer Rustam.

I will follow your task.

0

Please sign in to leave a comment.