How to format html files in Eclipse?
Asked Answered
A

5

59

The XML formatting works perfect but not the html formatting. In fact if I use "cmd-shift-F" for a html file, it just left aligns almost everything. I've attached the before and after pictures.

No eclipse html formatting applied

After eclipse html formatting applied

Does anyone know how to fix this? I played around with HTML formatting preferences but had no luck. Note that the same document, if it is saved as xml will format perfectly.

I am using eclipse 3.6 with WTP plugin.

Alisa answered 6/2, 2011 at 3:33 Comment(4)
The HTML format looks ok for me. I don't see how is your format preference. Maybe you should add it.Nalda
yup, you're right. That's the default behavior for the HTML editor in Eclipse. To me that's a bug that should resolved.Syllabogram
No, problem still exists with Indigo and Juno. Not sure about Kepler.Denby
Still an issue in 2018, I guess the best solution is to use a different toolCoccid
T
70

go to Window --> preferences --> Web --> HTML files --> Editor.

In the Inline Elements section, select all the elements that you don't want eclipse to inline(continue with same line).

Click Apply and then Ok. Now re format using ctrl + shift + f.

Thermolysis answered 7/1, 2015 at 9:42 Comment(5)
CTRL+Shift+f works for me in LiClipse, However, it removes some xhtml compatibility such as <br /> it make it <br>Hartill
This path still exists in Eclipse Neon, thanks looking for this for a LONG timeGuv
span is not in the list but still is forced on one line :(Ce
In 2018-12, auto format will not indent head and its child elements. Also doesn't indent body. By default, these elements are not declared as inline.Pneumatophore
Same issue (for my POV it is not a normal thing to inline an input or a label in p for instance...) in Eclipse IDE for PHP Developers Version: 2020-03 (4.15.0). I don't understand why the default formater settings are such a mess... Thanks for the path of the preferences.Moise
C
2

go to Window --> preferences --> Web --> HTML files --> Editor.

Make sure "Indentation Size" is not set to zero.

That's what did it for me.

Countervail answered 16/1, 2018 at 19:24 Comment(0)
M
1

http://eclipsetidy.sourceforge.net/

You can specify your formatting preferences too: http://eclipsetidy.sourceforge.net/?act=preferences

Memberg answered 11/3, 2011 at 3:3 Comment(0)
I
0

Eclipse Juno release seems to do a good job. It doesn't handle tags (that is the div tag that closes itself). Not sure why anyone would use it but we have a project that has them sprinkled about, probably from some WYSISYG editor someone was using.

Insole answered 1/8, 2012 at 20:49 Comment(2)
You mean it doesn't handle empty tags? An HTML formatter that didn't handle tags would be ... not an HTML formatter.Comic
Using Juno, I don't see anything wrong with formatting of empty div tags. However, it does left-align everything that's not inside a body tag (i.e. the head and body tags are left aligned, despite being inside the html element, plus every item inside the head element). This isn't the way I like it, and I can find no option to change that.Heteroecious
F
-3

CTRL+SHIFT+F works fine.

Just click on the source codes you want to format and then press CTRL+SHIFT+F.

Flesher answered 1/12, 2016 at 18:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.