Bug #4498
closedREXML Pretty formater does use specified 'width' to wrap lines
Description
=begin
REXML::Formatters::Pretty has 'width' attribute used to wrap lines. This is not used when the wrap method is invoked
pretty.rb¶
def write_text( node, output )
s = node.to_s()
s.gsub!(/\s/,' ')
s.squeeze!(" ")
s = wrap(s, 80-@level) ## HERE - 80 is hard coded, value should depend on @width and @level (e.g. @width - @level)
s = indent_text(s, @level, " ", true)
output << (' '*@level + s)
end
=end
Files
Updated by mfrasca (Michael Frasca) over 13 years ago
- File ruby-core-bug-4498.patch ruby-core-bug-4498.patch added
=begin
Patch attached for 'lib/rexml/formatters/pretty.rb'. @width attribute is used to compute line width when wrapping text output. @level is subtracted from @width to account for indenting of current xml node.
-Michael Frasca
=end
Updated by mfrasca (Michael Frasca) over 13 years ago
=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
Updated by shyouhei (Shyouhei Urabe) over 13 years ago
- Status changed from Open to Assigned
Updated by ko1 (Koichi Sasada) over 13 years ago
- Assignee changed from mfrasca (Michael Frasca) to kou (Kouhei Sutou)
Suto-san,
What do you think about it?
Updated by kou (Kouhei Sutou) over 13 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r31997.
Michael, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- lib/rexml/formatters/pretty.rb
(REXML::Formatters::Pretty#write_text),
test/rexml/test_core.rb
(Tester#test_pretty_format_long_text_finite): don't ignore
'width' parameter in pretty formatter. fixes #4498
Reported by Michael Frasca. Thanks!!!