Bug #4498
REXML Pretty formater does use specified 'width' to wrap lines
| Status: | Closed | Start date: | 03/13/2011 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 100% |
||
| Category: | lib | |||
| Target version: | 2.0.0 | Estimated time: | 1.00 hour | |
| ruby -v: | 1.9.2 |
Description
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
Related issues
Associated revisions
* 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!!!
* 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!!!
History
Updated by mfrasca (Michael Frasca) about 1 year ago
- File ruby-core-bug-4498.patch added
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
Updated by mfrasca (Michael Frasca) about 1 year ago
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
Updated by shyouhei (Shyouhei Urabe) about 1 year ago
- Status changed from Open to Assigned
Updated by ko1 (Koichi Sasada) 12 months ago
- Assignee changed from mfrasca (Michael Frasca) to kou (Kouhei Sutou)
Suto-san,
What do you think about it?
Updated by kou (Kouhei Sutou) 12 months 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!!!