How to config intellij-idea not format some part of the code?

Freewind picture Freewind · Dec 24, 2012 · Viewed 15.3k times · Source

In a html file, there is some code used custom template-language:

<script type="text/javascript">
    function ($scope, JsRoutes) {
        $scope.rows = [
            ${"#{list rows, as: 'row', separator: ','}"}
            {
            #{list fieldConfigs, as: 'f', separator: ','}
            ${f.name} : ${'$'}{row.${f.name}.toJson()}#{/list}
            }
            ${'#{/list}'}
        ]
    }
</script>

Is it possible to configure intellij-idea not to format it(but format the other part of the document)? Since idea will make it hard to read after formatting:

<script type="text/javascript">
    function ($scope, JsRoutes) {
        $scope.rows = [
            ${"#{list rows, as: 'row', separator: ','}"}
            {
    #{list fieldConfigs, as: 'f', separator: ','}
    ${f.name} :
        ${'$'}{
            row.${f.name}.toJson()
        }#{/list}
    }
    ${'#{/list}'}
    ]
    }
</script>

Answer

fawkes picture fawkes · May 6, 2014

In my version EAP 13.1, you must enable the following option in settings,

Preferences -> Code Style -> General -> Formatter Control -> Enable formatter markers in comments

before you can use these comments,

// @formatter:off

// @formatter:on 

or these (depending on language):

<!--@formatter:off-->

<!--@formatter:on-->

Screenshot:

Screenshot highlighting the checkbox for Enable formatter markers in comments under Preferences