问题
For some reason, Eclipse seems to think that e.g. <div>
and <td>
tags aren't indenting-worthy.
Ctrl+Shift+F indents the following HTML as such:
<div>
<div>
<table>
<tr>
<td>test<br />
test2
<h1>test 2</h1>
<div>testing<br />
test2</div>
<table>
<tr>
<td>
<h1>again</h1>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
Anyone have any idea of how to turn this logic off (I want all tags to indent!), or customize it?
回答1:
I'll give you an example of how to do it in Aptana. Since it's based on Eclipse - it will be more or less the same:
Window > Preferences > Aptana (or Eclipse) > Editors > HTML > Formatting > To edit, save the profile as a new one, and Edit > New lines > Everything in here should be self explanatory.
A sample screenshot: http://img10.imageshack.us/img10/6643/aptanaeclipse.jpg
In case you struggle to find a menu item, just do a filter search on the top left of the Preferences dialog window.
回答2:
Window > Preferences > Web > HTML Files > Editors.
Remove what you want to indent of the "Inline Elements" field.
This solved for me.
Hope its better now.
回答3:
I would suggest you look at html tidy, which is a commandline tool. If you're running linux, then fire up your package manager and search for 'tidy', it will be there. If windows, then see this page: http://tidy.sourceforge.net/#binaries
Typical tidy command from bash/DOS prompt:
tidy -im index.html
This will (-i
) indent the code and (-m
) modify the input file (rather than spitting it on the console). It will also list any warning or errors related to the DOCTYPE you've got in your header.
After you've run the command, eclipse should notify you that you're code has been updated and prompt you to refresh the window with the updated code.
来源:https://stackoverflow.com/questions/4606519/eclipse-html-doesnt-indent-on-some-tags