Community
Participate
Working Groups
Formatting an HTML document does not product correctly indented code. The following document: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <ul> <li>Test</li> <li>Test2</li> </ul> </body> </html> becomes: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <ul> <li>Test</li> <li>Test2</li> </ul> </body> </html> This is particularly strange since the formatting examples (Window->Preferences->Web and XML->HTML Files->HTML Styles) actually show properly indented code! Note, however, that the same document is created as an XML file, then it formats correctly.
(formatting bug)
I am responding as per the message from the newsgroup that I have attached below. I think that formating an HTML file (or JSP with HTML code in it) should make it follow the reccomendations provided by the official specification at www.w3.org - namely: 1) All HTML element names should be changed to uppercase, and all attributes to lowercase (see: http://www.w3.org/TR/html4/about.html#h-1.2.1) 2) Elements should be indented like you would an XML file (see sample: http://www.w3.org/TR/html4/struct/global.html#h-7.1) From the newsgroup: Re: HTML indentation/auto-indent? --------------------------------- On Tue, 07 Feb 2006 07:46:25 -0500, Jay Levitt <jay+news@xxxxxxxx> wrote: Is this type of functionality targeted for an upcoming release yet? I don't imagine this is very high on the priority list. Jay Levitt --------------------------------- It is a know bug, or feature reuest. I don't think it would take much to do it differently, but ... HTML is formatted that way by decign ... many well ecperience HTML editors we would like originally, long long ago, like 2 year, said that was the prefered and expected formatting (semi-compact). So, I'm guessing, we'd eventually want some preferences that better controlled the formpormatting so users could poick their own styles. If you and enough other "vote" in the bug for it to changed, and if you have some simple concrete directions for us so we know exactly what you are talking about, to be changed .... and, sometime to focus on it.
Regarding 1) All HTML element names should be changed to uppercase, and all attributes to lowercase (see: http://www.w3.org/TR/html4/about.html#h-1.2.1) There is a cleanup option (Cleanup Document.. in the context menu of the editor) that allows you to specify that you want to change tag/attribute names to upper or lowercase. There are also preferences in HTML Source for tag/attribute case for generated tags/attributes (like tags inserted from content assist)
Created attachment 58866 [details] Patch to HTMLFormatter so HTML honours indentation settings The method getBreakSpaces(Node node) in the class HTMLFormatter was calling the method getProperty in the class CMElementDeclaration from the package org.w3c.dom.contentModel. It seems as though getProperty is returning false for the constanint HTMLCMProperties.SHOULD_INDENT_CHILD_SOURCE for all HTML nodes apart from <table> <ol> and <ul>. I am not sure if this is desired behaviour or not but it does prohibit the indentation settings from being honoured.
Thanks for the patch. I'll take a look at it. As mentioned briefly in the newsgroup repost in comment #2, I believe previous users actually stated that they wanted the semi-compact formatting which was why we only indented table, ul, ol's children. But it seems there are other users that want more tags indented. Best option would be to turn this into a preference. Maybe something like the following: x=radio button -=checkbox Formatting: x Do not indent tags x Indent all possible tags x Indent children of -html -head -body -table -ul -ol
I'll investigate for 2.0 M6.
*** Bug 131460 has been marked as a duplicate of this bug. ***
Didn't get around to fixing this for 2.0 M6. Retargetting to 2.0 RC0. I won't be able to add any new preferences, but I think I might be able to offer a bit more indentation.
*** Bug 86599 has been marked as a duplicate of this bug. ***
Unfortunately, I was not able to come up with a good fix for 2.0 RC0. I came close, but I found that solution really made bug 102082 a lot more visible. Also, preferences would make fixing this bug a lot better (for example, indent all child tags vs only indent children of non-block tags like <head> vs <p>) At this point, I feel it's too late to fix this for 2.0, so I'll target 3.0 to make sure we try to look at it first thing next release.
Has there been any progress with this problem since May last year? Indenting all my html by hand is a real pain.
As mentioned in comment #5 & comment #10, rather than just fixing html formatting so that it always indents like the attached patch does, I think it's better to provide more formatting preferences so the user can decide what they really want to indent. Nick, I'm reassigning this bug to you since I believe you're investigating providing more formatting preferences. And I'm going to go ahead and mark the attached patch as obsolete.
we did some of this a little this release, right? Enough to mark this one as fixed?
No, we spent a lot of time on the XML formatter, but the HTML formatter produces the same results as shown in comment 0.
This is a long standing issue that still exists and I know I have seen other bugs open for the same thing, if I run across them again I will dupe. I agree due to conflicting requests from users the formatting should be based on a preference.
*** Bug 165037 has been marked as a duplicate of this bug. ***
*** Bug 301918 has been marked as a duplicate of this bug. ***
*** Bug 286627 has been marked as a duplicate of this bug. ***
*** Bug 176343 has been marked as a duplicate of this bug. ***
*** Bug 244001 has been marked as a duplicate of this bug. ***
*** Bug 228620 has been marked as a duplicate of this bug. ***
*** Bug 130228 has been marked as a duplicate of this bug. ***
Unfortunately, we didn't come up with a great strategy for this in the Helios timeframe. We'd like to try and reuse the XML formatter, but at this point it's a little too rigid to allow for formatting contained regions like <script> or <style>. We'll have to look at this in the 3.3 timeframe.
When you think fix this bug. Maybe they see it like some with no importance but is essencial.
We've recently made significant changes to the HTML formatter to provide the suggested style of indenting through Bug 203252 that you will notice in WTP 3.2.3 and 3.3M3. Thanks for your patience. *** This bug has been marked as a duplicate of bug 203252 ***
Nitin Dahyabhai asked that I open a new bug report, but I think it's better to just reopen this one as it explains everything and provides context. I had initially commented on Bug 203252, as this bug was marked as a duplicate of it. I've tried everything suggested in Bug 203252 and elsewhere to get HTML files to format correctly with proper indentation -- they still render flat (unindented), as shown in comment 0. I'm running Eclipse 4.19.0 (STS 4.10.0.RELEASE, which bundles WTP 3.21.0. I then installed Web Developer Tools 3.21, but that didn't help with this problem, either. FYI, the HTML Tidy plugin is not available through the Marketplace (at least not for this version of Eclipse/WTP). Let me know if you still need me to open a new bug report for this issue.
As of comment #26, bug #203252 comment #25 and since the steps to repro of this bug in comment #0 are indeed still valid, I'm reopening this. @Nitin please feel free to close again if you still think a new bug report should be opened.