Bug 262206 - [formatting][preferences] Provide an option in window -> preferences to honor white space when formatting
Summary: [formatting][preferences] Provide an option in window -> preferences to honor...
Status: NEW
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: 3.0.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Nick Sandonato CLA
QA Contact: Nick Sandonato CLA
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2009-01-23 12:09 EST by Shaun Elliott CLA
Modified: 2013-06-19 11:14 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaun Elliott CLA 2009-01-23 12:09:52 EST
When you have source like this: 
<foo>   data</foo>
and you run the formatter you get this:
<foo>data</foo>
e.g. the white space within the tags is removed.

additonally, this:
<foo><bar>&lt;data</bar></foo>

yeilds this:
<foo>
   <bar>&lt;data</bar></foo>
Comment 1 Nitin Dahyabhai CLA 2009-01-23 12:40:08 EST
Shaun, are you saying that in your first example that the white space shouldn't be removed?
Comment 2 Shaun Elliott CLA 2009-01-23 14:09:49 EST
(In reply to comment #1)
> Shaun, are you saying that in your first example that the white space shouldn't
> be removed?
> 

That's right, the data between the tags (even though it is white space) is valid and should not be removed when formatting. White space outside tags, yes, inside, no.

Comment 3 Nick Sandonato CLA 2009-01-23 14:23:46 EST
Do you have a grammar for the first example that explicitly states that the whitespace should be preserved?

The second example that you provide looks like the problem reported in bug 238026 where text after an entity reference is not formatted.
Comment 4 Shaun Elliott CLA 2009-01-23 15:36:31 EST
(In reply to comment #3)
> Do you have a grammar for the first example that explicitly states that the
> whitespace should be preserved?
> 
> The second example that you provide looks like the problem reported in bug
> 238026 where text after an entity reference is not formatted.
> 
I agree. I searched for both issues but was not fruitful. Should I alter the description?
Comment 5 Nitin Dahyabhai CLA 2009-01-28 10:13:30 EST
If you're satisfied with bug 238026 describing the second problem, sure.  But as Nick asked, what does your grammar say to do when handling the white space?
Comment 6 Shaun Elliott CLA 2009-01-28 19:31:59 EST
(In reply to comment #5)
> If you're satisfied with bug 238026 describing the second problem, sure.  But
> as Nick asked, what does your grammar say to do when handling the white space?
> 
I am not sure what you mean by 'what does your grammar say to do when handling the white space'. However, it seems problematic that formatting an XML document would remove white space between tags. 
Comment 7 Nick Sandonato CLA 2009-01-28 19:58:53 EST
As the XML specification has a section on white space in XML documents (http://www.w3.org/TR/REC-xml/#sec-white-space). There is essentially "readability" white space and "significant" white space.

For the most part, the XML formatter assumes that all white space in the document is simply there for readability. And that's what the formatter is there for: to improve readability. However, applications (like our formatter) can be notified that the white space within an element is significant using the xml:space attribute.

So, for your example, you could have
<foo xml:space="preserve">   data</foo>
which would end up preserving the white space.

You could also define the grammar of an element using an XML Schema (XSD) or through DTDs to explicitly state that the white space is significant.
Comment 8 Shaun Elliott CLA 2009-01-28 20:34:54 EST
(In reply to comment #7)
> As the XML specification has a section on white space in XML documents
> (http://www.w3.org/TR/REC-xml/#sec-white-space). There is essentially
> "readability" white space and "significant" white space.
> 
> For the most part, the XML formatter assumes that all white space in the
> document is simply there for readability. And that's what the formatter is
> there for: to improve readability. However, applications (like our formatter)
> can be notified that the white space within an element is significant using the
> xml:space attribute.
> 
> So, for your example, you could have
> <foo xml:space="preserve">   data</foo>
> which would end up preserving the white space.
> 
> You could also define the grammar of an element using an XML Schema (XSD) or
> through DTDs to explicitly state that the white space is significant.
> 

I do appreciate your explanation, unfortunately, our message structure is not mutable for such a cause. I would be happy to implement my own formatter as an Eclipse plugin, however I have been unable to locate the proper hooks to override this action, can you provide any help with this?

Lastly, given that this is the intended functionality, I will change this issue to a 'feature request' -> it would be really nice to tell the formatter to honor whitespace in window -> preferences instead of having to alter the message.
Comment 9 Ian Tewksbury CLA 2010-04-07 10:31:45 EDT
There has been some work here in that there is now a "clear all blank lines" preference and there is a "preserve whitespace in tags with PCDATA content".  Probably still need a more general case preference for just preserving whitespace entirely.