Bug 122051 - [fomatting] Formatting of HTML loses indentation
Summary: [fomatting] Formatting of HTML loses indentation
Status: REOPENED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.html (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows XP
: P3 normal with 20 votes (vote)
Target Milestone: 3.3   Edit
Assignee: Nick Sandonato CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords: plan
: 86599 130228 131460 165037 176343 228620 244001 286627 301918 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-12-24 02:09 EST by Chris Reigrut CLA
Modified: 2021-04-23 06:39 EDT (History)
23 users (show)

See Also:
for.work.things: review-


Attachments
Patch to HTMLFormatter so HTML honours indentation settings (1.18 KB, patch)
2007-02-13 11:47 EST, Tom Turrell-Croft CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Reigrut CLA 2005-12-24 02:09:27 EST
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.
Comment 1 Amy Wu CLA 2006-02-08 11:37:14 EST
(formatting bug)
Comment 2 Ben Burgess CLA 2006-02-17 11:19:35 EST
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.
Comment 3 Amy Wu CLA 2006-02-17 15:32:32 EST
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)
Comment 4 Tom Turrell-Croft CLA 2007-02-13 11:47:45 EST
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.
Comment 5 Amy Wu CLA 2007-02-13 16:47:16 EST
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
Comment 6 Amy Wu CLA 2007-02-28 19:51:07 EST
I'll investigate for 2.0 M6.
Comment 7 Amy Wu CLA 2007-03-01 15:19:45 EST
*** Bug 131460 has been marked as a duplicate of this bug. ***
Comment 8 Amy Wu CLA 2007-04-04 15:10:40 EDT
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.
Comment 9 Amy Wu CLA 2007-04-25 21:05:23 EDT
*** Bug 86599 has been marked as a duplicate of this bug. ***
Comment 10 Amy Wu CLA 2007-05-17 14:12:56 EDT
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.
Comment 11 Darren Brierton CLA 2008-01-24 10:16:44 EST
Has there been any progress with this problem since May last year? Indenting all my html by hand is a real pain.
Comment 12 Amy Wu CLA 2008-02-12 18:42:36 EST
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.
Comment 13 David Williams CLA 2008-05-15 09:05:55 EDT
we did some of this a little this release, right? Enough to mark this one as fixed? 
Comment 14 Nitin Dahyabhai CLA 2008-05-15 17:15:29 EDT
No, we spent a lot of time on the XML formatter, but the HTML formatter produces the same results as shown in comment 0.
Comment 15 Ian Tewksbury CLA 2010-02-01 09:39:38 EST
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.
Comment 16 Nick Sandonato CLA 2010-02-05 11:26:59 EST
*** Bug 165037 has been marked as a duplicate of this bug. ***
Comment 17 Nick Sandonato CLA 2010-02-05 11:37:03 EST
*** Bug 301918 has been marked as a duplicate of this bug. ***
Comment 18 Nick Sandonato CLA 2010-02-09 17:32:03 EST
*** Bug 286627 has been marked as a duplicate of this bug. ***
Comment 19 Nick Sandonato CLA 2010-02-16 10:50:22 EST
*** Bug 176343 has been marked as a duplicate of this bug. ***
Comment 20 Nick Sandonato CLA 2010-02-16 10:59:05 EST
*** Bug 244001 has been marked as a duplicate of this bug. ***
Comment 21 Nick Sandonato CLA 2010-02-16 11:06:30 EST
*** Bug 228620 has been marked as a duplicate of this bug. ***
Comment 22 Nick Sandonato CLA 2010-04-27 14:24:23 EDT
*** Bug 130228 has been marked as a duplicate of this bug. ***
Comment 23 Nick Sandonato CLA 2010-04-29 14:26:32 EDT
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.
Comment 24 José Valecillos CLA 2010-07-31 22:55:35 EDT
When you think fix this bug. Maybe they see it like some with no importance but is essencial.
Comment 25 Nick Sandonato CLA 2010-11-04 14:22:43 EDT
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 ***
Comment 26 Ari Meyer CLA 2021-04-22 21:02:56 EDT
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.
Comment 27 Mauro Molinari CLA 2021-04-23 04:08:16 EDT
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.