casolorz
casolorz

Reputation: 9594

eclipse formatting of javascript inside xhtml removes //<![CDATA[ tags

I am using eclipse (juno and previous version) to write JSF code. The pages are all xhtml. Every so often I need to add javascript. When I do so I have to use the CDATA tags otherwise the xhtml is invalid when I have certain characters like > < &.

Anyways, that solution worked fine until I told eclipse to format the code at which point it removed the CDATA tags and it all broke.

Is there a way to tell eclipse not to remove those tags? I realize I can just escape the characters and that will work too but I would prefer to use the CDATA tags to keep the code more readable.

Thanks.

Upvotes: 1

Views: 640

Answers (1)

mzzzzb
mzzzzb

Reputation: 1452

have been facing the same issue myself, i dont exactly have a fix but a work around. you just select the piece of code you want to format before invoking the formatter.

<head>
    <script type="text/javascript">
    //<![CDATA[
      alert('test');
    //]]></script>
</head>
<body>
    <form action="register.jsp" method="post">
        <div class="row">
            <span class="cell1">Username</span><span><input id="username"
                name="username" type="text" /></span><span id="result"></span>
        </div>
        <div class="row">
            <span class="cell1">Full name</span><span><input id="fullname"
                name="fullname" type="text" /></span>
        </div>
    </form>
</body>

here i would select from <body> to </body> and hit Ctrl Shft F.

you may also want to try out a different editor, http://amateras.sourceforge.jp/cgi-bin/fswiki_en/wiki.cgi?page=EclipseHTMLEditor. i havent myself, but it says it has a configurable formatter. please do let me know if you find a simpler solution. thanks

Upvotes: 1

Related Questions