xml formating - wrapping line

49 views
Skip to first unread message

Erez F.

unread,
Mar 18, 2015, 4:19:41 PM3/18/15
to prett...@googlegroups.com
Hi,
I'd like to be able to set maximum number of characters for line in xml file. The current wrap function, does wrapping only on characters in the 'text' node. I want it to be done on the whole line.

If someone knows a way to do so already by the API, I'll be glad to know

in...@prettydiff.com

unread,
Mar 18, 2015, 4:29:53 PM3/18/15
to prett...@googlegroups.com
Erez,

What if there were an option to add a new line and indentation on each
attribute of an element?

Example (periods used as pretend whitespace):
<div>
....<test
........something="true"
........other="blah"
........more="fun"/>
</div>

The tool automatically applies this kind of formatting to SVG elements, so
you can play around with those in the tool as examples. Maybe this will
get you closer to what you need. But if I were to supply such an option
it would be available to EVERY element except closing tags.

Austin
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/b9828c16-72e9-4e4d-9166-06b4f17e7441%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


Erez F.

unread,
Mar 19, 2015, 5:57:16 AM3/19/15
to prett...@googlegroups.com
Hi Austin,
Thanks for the quick reply and suggestion;

I Don't think that it will aid my use-case, because the usage I'm dealing with very often includes many attributes per element(so files will become very long by the suggested behaviour-'indent+linefeed'), and there is a specific requirement for configurable line wrapping.

I'd like to ask another requirement - currently, prettyDiff wraps starting-tag expanding on several lines (could happen if it has many attributes)
into 1 line. I'd like to configure it won't. The line could be very long.

Again, thanks for the support

in...@prettydiff.com

unread,
Mar 19, 2015, 11:39:04 AM3/19/15
to prett...@googlegroups.com
Erez,

I will experiment with breaking tags between attributes if the tag is
longer than the provided "wrap" option value. Before I commit to this
enhancement I want to experiment with this first to ensure it is not
visually disruptive for edge cases.

https://github.com/prettydiff/prettydiff/issues/66

Austin
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/f0508c16-f465-470b-a223-1ed5219e5a23%40googlegroups.com.

Erez F.

unread,
Mar 20, 2015, 10:57:59 AM3/20/15
to prett...@googlegroups.com
Thanks Austin,
1)breaking tag to lines between attribues, to align with wrapping will aid. I presive this as wrapping of element.
2) Does formatting of lines, rather of elements, is a possibility?
Example:
Wrapping line after:12 chars

Initial line:
<balance>1234567890</balance>

Formatted result:
<balance>1234567890
</balance>

in...@prettydiff.com

unread,
Mar 20, 2015, 1:44:37 PM3/20/15
to prett...@googlegroups.com
Erez,

I provide a lot of logic to ensure that white space tokens are not
accidentally inserted into text nodes. When XML/HTML are rendered the
output is treated with white space normalization, unless told otherwise.

Initial content of the following:
<balance>1234567890
</balance>

Renders to the screen as:
<balance>1234567890 </balance>

Which is not the same as:
<balance>1234567890</balance>

If I were going to break a line to account for wrapping the safest thing
is to break within a node but not within an attribute.

Thanks,
Austin
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/639feb52-4faf-4da6-b910-51cff3cd23cb%40googlegroups.com.

in...@prettydiff.com

unread,
Mar 28, 2015, 12:39:56 AM3/28/15
to prett...@googlegroups.com
Erez,

I have this feature coded and welcome your feedback. You can test it out at:

http://prettydiff.com/ignore/testlocation/prettydiff.com.xhtml

Austin

Erez F.

unread,
Apr 5, 2015, 4:38:46 AM4/5/15
to prett...@googlegroups.com
Hi Austin,
1) In http://prettydiff.com/ignore/testlocation/prettydiff.com.xhtml - doesn't do wrapping.
2) I've check in http://prettydiff.com/ (version 1.11.10).
If wrapping is marked for X characters and if multiple attributes in line resides in X, then they should be in the same line. Currently, each attributes gets a different line (one attribute per line)

3) other not related issue I saw:
when separating between attribute's value, and the attribute '=' sign, then doing beautification of the XML, result in a red marker over some of the text, and some of the text gets messed.

in...@prettydiff.com

unread,
Apr 5, 2015, 8:42:41 AM4/5/15
to prett...@googlegroups.com
Erez,

Could you provide me an example of point 3?

For point 2 it sounds like you are wanting:
....<a>
........<test another="qwer" erty="fghj" extra="qwer" item="qwer" more="asdf"
............other="zxcv"/>
....</a>

Instead the latest version provides:
....<a>
........<test
............another="qwer"
............erty="fghj"
............extra="qwer"
............item="qwer"
............more="asdf"
............other="zxcv"/>
....</a>

Thanks,

Austin
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/ea1eab6a-0cc6-4698-b2d1-f60fdf31d86b%40googlegroups.com.

in...@prettydiff.com

unread,
Apr 8, 2015, 7:27:22 AM4/8/15
to prett...@googlegroups.com
Erez,

What about this version:
http://prettydiff.com/ignore/testlocation/prettydiff.com.xhtml?m=beautify

Here is a short sample code with long attribute values:

<a> <test item="qwer" other="It is a long established fact that a reader
will be distracted by the readable content of a page when looking at its
layout. The point of using Lorem Ipsum is that it has a more-or-less
normal distribution of letters, as opposed to using 'Content here, content
here', making it look like readable English. Many desktop publishing
packages and web page editors now use Lorem Ipsum as their default model
text, and a search for 'lorem ipsum' will uncover many web sites still in
their infancy. Various versions have evolved over the years, sometimes by
accident, sometimes on purpose (injected humour and the like)."
erty="fghj" extra="qwer" another="qwer" more="There are many variations of
passages of Lorem Ipsum available, but the majority have suffered
alteration in some form, by injected humour, or randomised words which
don't look even slightly believable. If you are going to use a passage of
Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden
in the middle of text. All the Lorem Ipsum generators on the Internet tend
to repeat predefined chunks as necessary, making this the first true
generator on the Internet. It uses a dictionary of over 200 Latin words,
combined with a handful of model sentence structures, to generate Lorem
Ipsum which looks reasonable. The generated Lorem Ipsum is therefore
always free from repetition."/> </a>

Austin
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/ea1eab6a-0cc6-4698-b2d1-f60fdf31d86b%40googlegroups.com.

Erez F.

unread,
Apr 13, 2015, 3:29:04 PM4/13/15
to prett...@googlegroups.com
Hi Austin,
kindly excuse my delay to answer, as I was in holiday...
I really like your solution; I checked it on 1.11.10 and on prettyDiff.com (version 1.11.11). Thanks you - this looks great !!!

A question about the wrapping:
XML content:
<p att1="4" att2="4" att3="6" att4="a" att3="6" att4="a">
<a att="3"><b att3="4"></b>"asdfasd5asdfas"</a>
</p>
Wrapping amount: 20 chars
1) what characters are counted for wrapping (also XML reserved chars as the '=' and '<' )?
2) what happens if wrapping size is at the middle of attribute name? attribute value? - does new line happens before or after?
3) to sum the 2 Q.s above - why the first line after beautification was:
<p att1="4" att2="4"

===========

on a different topic - found bug when placing space between attribute to its equal sign, or, placing space/s between attribute's value and its respective equal sign - the formatting gets broken
original XML content: <p att1 ="4"></p>
beautified XML: <p ="4" att1></p>

in...@prettydiff.com

unread,
Apr 13, 2015, 11:03:31 PM4/13/15
to prett...@googlegroups.com
Erez,

The wrapping looks first at the length of a start tag or singleton to see
if it is longer than the wrap limit and contains attributes. Then
attributes are broken onto newlines until the tag is no wider than the
wrap limit. If a given attribute value is longer than the wrap limit and
contains spaces it is broken (only at spaces) onto new lines and following
attributes always begin on a new line. Attribute names will not be broken
no matter how long they are. Only attribute values will be broken and only
at spaces.

In your example the first line becomes: `<p att1="4" att2="4"` where a
line break occurs at the space closest to the wrap value when counting
number of characters from the start of the tag.

The defect you found is a valid defect. I have opened an issue on this:
https://github.com/prettydiff/prettydiff/issues/74

Austin

Erez F.

unread,
Apr 15, 2015, 4:14:05 PM4/15/15
to prett...@googlegroups.com
Hi Austin,
on the wrapping length topic,

1)
xml content:
<abc at="33">
<bbb at=3 bt=444 ct=555 dt=ab>
ttt
</bbb>
</abc>

resulted beautified content:
<abc at="33">
<bbb at=3
bt=444 ct=555 dt=ab>
ttt
</bbb>
</abc>

wrap line: 12 characters

Per your explanation, I would expect that it would beautify to the following:
<abc at="33">
<bbb at=3
bt=444 ct=555
dt=ab>
ttt
</bbb>
</abc>

the line: 'bt=444 ct=555 dt=ab>' reaches 12 characters at 'bt=444 ct=555' (the middle of 555...)


2) '...If a given attribute value is longer than the wrap limit and
contains spaces it is broken (only at spaces) onto new lines...'

in...@prettydiff.com

unread,
Apr 15, 2015, 5:00:33 PM4/15/15
to prett...@googlegroups.com
Erez,

I could be that explained the logic poorly. If the limit falls in the
middle of an attribute then I am inserting the line break at the space
before this attribute so that the tag can conform to the wrap limit as
closely as possible. If I inserted the line break after the attribute its
line would be longer than the limit suggested by the wrap property.

I can still change how this logic operates if we can think up a cleaner
approach.

Austin

Erez F.

unread,
Apr 18, 2015, 8:23:39 AM4/18/15
to prett...@googlegroups.com
Hi Austin,
I've now managed to align your explanation with results I got in the online-editor to my xml-examples. What confused me was the difference between the attribute-name and the attribute-value. If the wrapping limit falls in the middle of the attribute-name - the line-break is inserted before the attribute; BUT if the wrap limit falls in the middle of the attribute's value - the line break is inserted after the value.

I don't think you should change the approach, and it should be better and more detailed documented.

in...@prettydiff.com

unread,
Apr 20, 2015, 9:53:40 AM4/20/15
to prett...@googlegroups.com
Erez,

I will update my documentation so that this is clearly explained.

Thank you for the time,
Austin
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/9c7af33e-da83-4683-83b8-bd33254cd8b0%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages