=begin
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 = { 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 = 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 )
s = node.to_s()
s.gsub!(/\s/,' ')
s.squeeze!(" ")
s = wrap(s, 80-@level) ## <-- HERE: is hard coded, value should
depend on @width and @level (e.g. @width - @level)
s = indent_text(s, @level, " ", true)
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
=end