Project

General

Profile

Actions

Bug #4498

closed

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

Added by mfrasca (Michael Frasca) about 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
1.9.2
Backport:
[ruby-core:<unknown>]

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

ruby-core-bug-4498.patch (465 Bytes) ruby-core-bug-4498.patch PATCH - Bug 4498 mfrasca (Michael Frasca), 03/14/2011 03:02 AM
ruby-core-bug-4498.patch (465 Bytes) ruby-core-bug-4498.patch mfrasca (Michael Frasca), 03/25/2011 06:23 AM
ruby-core-bug-4498.patch (465 Bytes) ruby-core-bug-4498.patch mfrasca (Michael Frasca), 04/12/2011 08:17 PM
ruby-core-bug-4498.patch (465 Bytes) ruby-core-bug-4498.patch mfrasca (Michael Frasca), 04/12/2011 08:18 PM

Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #5892: REXML always wraps long tag text regardless the page width setting.Rejectedkou (Kouhei Sutou)01/13/2012Actions
Actions #1

Updated by mfrasca (Michael Frasca) about 13 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

Updated by mfrasca (Michael Frasca) about 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

Actions #3

Updated by shyouhei (Shyouhei Urabe) about 13 years ago

  • Status changed from Open to Assigned

Updated by ko1 (Koichi Sasada) almost 13 years ago

  • Assignee changed from mfrasca (Michael Frasca) to kou (Kouhei Sutou)

Suto-san,

What do you think about it?

Actions #5

Updated by kou (Kouhei Sutou) almost 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!!!
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0