From: Michael Frasca Date: 2011-03-25T06:04:09+09:00 Subject: [ruby-core:35551] [Ruby 1.8 - Bug #4498][Open] [Patch] REXML Pretty formater does use specified 'width' to wrap lines --0015174795f2635bc9049f40d108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable REXML::Formatters::Pretty has 'width' attribute used to wrap lines. This is not used when the wrap method is invoked. The pretty formatter within the REXML library is used to nicely indent xml files for viewing. I use this feature to present XML files to a user for editing. The width attribute is available to set a maximum line width, and force text wrapping for nodes with long text values. There are two modes for the pretty formatter - @compact =3D { true | false }. When compact is on, @width is used for text wrapping under the condition that ... "If compact and all children are text, and if the formatted output is less than the specified width, then try to print everything on one line" But in the case when @compact =3D false, I believe that the node text should still be wrapped based on user specification. In the current state, max width is hard coded to 80 chars. # lib/rexml/formatters/pretty.rb def write_text( node, output ) =A0 s =3D node.to_s() =A0 s.gsub!(/\s/,' ') =A0 s.squeeze!(" ") =A0 s =3D wrap(s, 80-@level) ## <-- HERE: is hard coded, value should depend on @width and @level (e.g. @width - @level) =A0 s =3D indent_text(s, @level, " ", true) =A0 output << (' '*@level + s) end I've attached a patch for this issue. I've raised bug #4497 for the same issue in 1.8.7 branch -Michael Frasca --0015174795f2635bc9049f40d108 Content-Type: application/octet-stream; name="ruby-core-bug-4498.patch" Content-Disposition: attachment; filename="ruby-core-bug-4498.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_glo65hw40 SW5kZXg6IGxpYi9yZXhtbC9mb3JtYXR0ZXJzL3ByZXR0eS5yYgo9PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBsaWIv cmV4bWwvZm9ybWF0dGVycy9wcmV0dHkucmIJKHJldmlzaW9uIDMxMTAzKQorKysgbGliL3JleG1s L2Zvcm1hdHRlcnMvcHJldHR5LnJiCSh3b3JraW5nIGNvcHkpCkBAIC04OCw3ICs4OCw3IEBACiAg ICAgICAgIHMgPSBub2RlLnRvX3MoKQogICAgICAgICBzLmdzdWIhKC9ccy8sJyAnKQogICAgICAg ICBzLnNxdWVlemUhKCIgIikKLSAgICAgICAgcyA9IHdyYXAocywgODAtQGxldmVsKQorICAgICAg ICBzID0gd3JhcChzLCBAd2lkdGgtQGxldmVsKQogICAgICAgICBzID0gaW5kZW50X3RleHQocywg QGxldmVsLCAiICIsIHRydWUpCiAgICAgICAgIG91dHB1dCA8PCAoJyAnKkBsZXZlbCArIHMpCiAg ICAgICBlbmQK --0015174795f2635bc9049f40d108--