I have the problem that if I autoformat a XHTML file (JSF 1.2) in Eclipse with the keys CTRL + SHIFT + f, the output looks really bad and is not really readable anymore.
My formated code:
<span class="label viertel alignright">
<h:outputLabel for="itLine5" value="E-Mail:" />
</span>
Becomes this:
<span class="label viertel alignright"> <h:outputLabel
for="itLine5" value="E-Mail:" /> </span>
In this small example, it's still readable - but in longer code it's just chaos!
How do I make sure that my XHTML code is formatted in a readable manner?
I use this version of Eclipse Helios:
I use these JBoss Tools:
I think I have a solution that works well enough (Eclipse Juno). A lot of tags/elements are specified as inline causing the wierd formatting. <span>
for example is in that list. You could try to remove the list of inline elements (don't worry, you can always select "Restore Defaults"). While you're at it, change the width to something more useful than the default (72 in my case). The preferences are found in Window > Preferences > Web > HTML Files > Editor:
I removed all the inline elements in the list and formatted a big xhtml file with good result. I set my line width to 120 which is what I use for Java. Of course, this change will affect regular HTML files as well.
From your example, this code:
<span class="label viertel alignright"> <h:outputLabel
for="itLine5" value="E-Mail:" />
</span>
was formatted to:
<span class="label viertel alignright">
<h:outputLabel for="itLine5" value="E-Mail:" />
</span>
Is this good enough for you?
I don't use CTRL + SHIFT + F to format the code but only CTRL + I to indent. This function works well only if all the code of the page is selected, so I use CTRL+A to select all and CTRL+I to indent.
The indent function preserves the line breaks and only indents the code. I'm using Juno, hope this also works in Helios!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With