How to format html files in Eclipse?

和自甴很熟 提交于 2019-12-03 02:57:06

问题


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.

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.


回答1:


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.




回答2:


http://eclipsetidy.sourceforge.net/

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




回答3:


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

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

That's what did it for me.




回答4:


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.




回答5:


CTRL+SHIFT+F works fine.

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



来源:https://stackoverflow.com/questions/4911379/how-to-format-html-files-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!