如何在 Eclipse 中格式化 html 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4911379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to format html files in Eclipse?
提问by prasad vsv
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.
XML 格式工作完美,但不是 html 格式。事实上,如果我对 html 文件使用“cmd-shift-F”,它只会左对齐几乎所有内容。我附上了之前和之后的照片。
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.
有谁知道如何解决这一问题?我玩弄了 HTML 格式首选项,但没有运气。请注意,相同的文档,如果保存为 xml 格式将完美。
I am using eclipse 3.6 with WTP plugin.
我正在使用带有 WTP 插件的 eclipse 3.6。
回答by prasad vsv
go to Window --> preferences --> Web --> HTML files --> Editor
.
去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).
在 Inline Elements 部分,选择您不希望 eclipse 内联的所有元素(继续同一行)。
Click Applyand then Ok.
Now re format using ctrl + shift + f
.
单击应用,然后单击确定。现在使用ctrl + shift + f
.
回答by Mike G
http://eclipsetidy.sourceforge.net/
http://eclipsetidy.sourceforge.net/
You can specify your formatting preferences too: http://eclipsetidy.sourceforge.net/?act=preferences
您也可以指定格式首选项:http: //eclipsetidy.sourceforge.net/?act=preferences
回答by user3888750
go to Window --> preferences --> Web --> HTML files --> Editor.
转到窗口 --> 首选项 --> Web --> HTML 文件 --> 编辑器。
Make sure "Indentation Size" is not set to zero.
确保“缩进大小”未设置为零。
That's what did it for me.
这就是为我所做的。
回答by Aaron Bono
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.
Eclipse Juno 版本似乎做得很好。它不处理标签(即关闭自身的 div 标签)。不知道为什么有人会使用它,但我们有一个项目,其中散布了它们,可能来自某人正在使用的某个 WYSISYG 编辑器。
回答by Fidele Fison
CTRL+SHIFT+Fworks fine.
CTRL+ SHIFT+F工作正常。
Just click on the source codes you want to format and then press CTRL+SHIFT+F.
只需单击要格式化的源代码,然后按CTRL+ SHIFT+ F。