From 6db4590f9bc598179bbed35b66a3e583a04984c0 Mon Sep 17 00:00:00 2001 From: "travis%sedsystems.ca" <> Date: Thu, 10 Feb 2005 01:30:17 +0000 Subject: Bug 11901 : Change Bugzilla comments line-wrapping policy Patch by Max Kanat-Alexander r=gerv,justdave a=justdave --- Bugzilla/Util.pm | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'Bugzilla/Util.pm') diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index 7bb173e05..6175e0ab2 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -22,6 +22,7 @@ # Jacob Steenhagen # Bradley Baetz # Christopher Aillon +# Max Kanat-Alexander package Bugzilla::Util; @@ -32,14 +33,37 @@ use base qw(Exporter); html_quote url_quote value_quote xml_quote css_class_quote lsearch max min - trim diff_strings + trim diff_strings wrap_comment format_time format_time_decimal file_mod_time); use Bugzilla::Config; use Bugzilla::Error; +use Bugzilla::Constants; use Date::Parse; use Date::Format; +use Text::Autoformat qw(autoformat break_wrap); + +our $autoformat_options = { + # Reformat all paragraphs, not just the first one. + all => 1, + # Break only on spaces, and let long lines overflow. + break => break_wrap, + # Columns are COMMENT_COLS wide. + right => COMMENT_COLS, + # Don't reformat into perfect paragraphs, just wrap. + fill => 0, + # Don't compress whitespace. + squeeze => 0, + # Lines starting with ">" are not wrapped. + ignore => qr/^>/, + # Don't re-arrange numbered lists. + renumber => 0, + # Keep short lines at the end of paragraphs as-is. + widow => 0, + # Even if a paragraph looks centered, don't "auto-center" it. + autocentre => 0, +}; # This is from the perlsec page, slightly modifed to remove a warning # From that page: @@ -178,6 +202,11 @@ sub diff_strings { return ($removed, $added); } +sub wrap_comment ($) { + my ($comment) = @_; + return autoformat($comment, $autoformat_options); +} + sub format_time { my ($time) = @_; @@ -277,6 +306,7 @@ Bugzilla::Util - Generic utility functions for bugzilla # Functions for manipulating strings $val = trim(" abc "); ($removed, $added) = diff_strings($old, $new); + $wrapped = wrap_comment($comment); # Functions for formatting time format_time($time); @@ -402,6 +432,16 @@ compared to the old one. Returns a list, where the first entry is a scalar containing removed items, and the second entry is a scalar containing added items. +=item C + +Takes a bug comment, and wraps it to the appropriate length. The length is +currently specified in C. Lines beginning +with ">" are assumed to be quotes, and they will not be wrapped. + +The intended use of this function is to wrap comments that are about to be +displayed or emailed. Generally, wrapped text should not be stored in the +database. + =back =head2 Formatting Time -- cgit v1.2.3-24-g4f1b