Bug #4498

REXML Pretty formater does use specified 'width' to wrap lines

Added by Michael Frasca about 4 years ago. Updated almost 4 years ago.

[ruby-core:<unknown>]
Status:Closed
Priority:Normal
Assignee:Kouhei Sutou
ruby -v:1.9.2 Backport:

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

ruby-core-bug-4498.patch Magnifier - PATCH - Bug 4498 (465 Bytes) Michael Frasca, 03/14/2011 03:02 AM

ruby-core-bug-4498.patch Magnifier (465 Bytes) Michael Frasca, 03/25/2011 06:23 AM

ruby-core-bug-4498.patch Magnifier (465 Bytes) Michael Frasca, 04/12/2011 08:17 PM

ruby-core-bug-4498.patch Magnifier (465 Bytes) Michael Frasca, 04/12/2011 08:18 PM


Related issues

Duplicates Ruby trunk - Bug #5892: REXML always wraps long tag text regardless the page width setting. Rejected 01/13/2012

Associated revisions

Revision 31997
Added by Kouhei Sutou almost 4 years ago

  • 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!!!

Revision 31997
Added by Kouhei Sutou almost 4 years ago

  • 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

#1 Updated by Michael Frasca about 4 years ago

=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

#2 Updated by Michael Frasca about 4 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

#3 Updated by Shyouhei Urabe about 4 years ago

  • Status changed from Open to Assigned

#4 Updated by Koichi Sasada almost 4 years ago

  • Assignee changed from Michael Frasca to Kouhei Sutou

Suto-san,

What do you think about it?

#5 Updated by Kouhei Sutou almost 4 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!!!

Also available in: Atom PDF