HTML/JS code formatting with Play 2 plugin

Hi,

when the Play2 plugin is enabled, the HTML/JS code formatter doesn't work correctly when working on *.scala.html files (Play view template file extension).

Example:

<div >foo</div> <script>     if (window.console) {         console.log("Hello World");     } </script>


becomes

<div >foo</div> <script> if ( window.console ) { console.log ( "Hello World" ) ; } </script>


after reformatting. The indentation of the JS code is lost and the extra spaces in the html attribute make it invalid.

When I disable the Play2 plugin or change the file extension to plain ".html", everything works as expected.

Is this a known problem? Anything I can do about it other than disabling the plugin?

This is with IDEA 13.1.3 and the latest released Play2/Scala plugins. I also tried the nightly plugins, but that didn't help.

Thanks for your help,

Timo

Updated to fix formatting of the example

2 comments

I have been struggeling with the formatter from the beginning and gave up because it is completely useless. Not only does the code look unpleasant after formatting, in most cases it is rendered completely dysfunctional - this is true for JavaScript and also HTML code.

Example HTML before formatting:

<div >
     <div >@Messages("renderer.productGallery.offerings.label")</div>
</div>


After formatting:

<div >      <div >@Messages("renderer.productGallery.offerings.label")</div> </div>


Please note the introduced spaces (i.e. "5 px ;") in the style attribute which completely break the page layout.

The JavaScript reformatting bugs are too numerous to mention. Event Shift-Return to create a new block does not work - it introduces a superfluous curly brace.

I only use the Play 2 plugin for "kind of" code completion and some rudimentary color coding. It would be great if the Play 2 plugin for HTML/JavaScript would draw more attention and eventually got fixed.

Thanks and regards,
Peter

0

Please, will somebody from JetBrains reply? This is a serious limitation of an excellent tool. Following are details:

Hi All. I'm a new Scala and new Play 2.0 user on IDEA 14.1.4 Ultimate & Scala Plugin 1.5.2., and I have an issue where IDEA is not correctly formatting a play template file in my opinion. To recreate: Make a new Scala + Play 2.x project, let it initialize the sbt stuff, and replace 'app > views > index.scala.html' with this unformatted code:

@(message: String)
@main("Welcome to Play") {
@play20.welcome(message)
<script>
$(function() {
console.log("$");
});
</script>
}

Run 'Code > Reformat Code...' On my setup this only indents lines 3-4, but I expect it to indent more like this:

@(message: String)
@main("Welcome to Play") {
    @play20.welcome(message)
<script>
    $(function() {
        console.log("$");
    });
</script>
}

Any help would be awesome!



Attachment(s):
Screen Shot 2015-07-11 at 9.30.48 AM.png
0

Please sign in to leave a comment.