Tested and running on the test server. Sorry about the strange regex delimiters. Several versions of Perl don't agree on how to escape the embedded delimiters and I blame mod_perl in this case (my copy of Perl agrees with me).

# Insert spaces to prevent the nodelets from getting too wide. # We leave the loopholes of using a bunch of "&nonentity;"s or # "<!--> -->" to intentionally make the nodelets wide (intended for # /msg'ing to yourself) as the problem is more accidents than abuse +. # "&123" and "&lt" work in some browsers, but we might put spaces i +n # the middle of them (if you don't like it, then remember the ";"). my $len= 0; $text =~ s[(\s+)|([^\s<&]+)|(<[^<>]*>)|(&#?\w{1,10};)|(.)]` if( $1 ) { $len= 0; $1; } elsif( length( $2 ) ) { # $2 is the only case that can be "0" (ie. false) my $res= $2; my $tot= $len + length($res); if( 18 < $tot ) { my $max = 18 - $len; my $min = $max - 9; $min = 0 if $min < 0; $res =~ s[ ( \S{$min,$max} (?: (?<!\W) (?![\w\[{(;,/]) | (?<![\w\$@%&*]) (?!\W) ) | \S{$max} )(?=\S) ][$1 ]x; $res =~ s[ ( \S{9,18} (?: (?<!\W) (?![\w\[{(;,/]) | (?<![\w\$@%&*]) (?!\W) ) | \S{18} )(?=(\S+)) ]{ length( $1 . $2 ) > 18 ? "$1 " : $1 }gex; $res =~ /(\S*)$/; $len= length( $1 ); } else { $len= $tot; } $res; } elsif( $3 ) { $3; } else { my $res= $4 || $5; my $add= $5 ? 1 : int( length($4)/3 ); $len += $add; if( 18 < $len ) { $len= $add; " $res"; } else { $res; } } `egis; return $text;

It tries to not put spaces in front of any of [{(;,/1 and not after $@%&* because they can be Perl sigils.

(Updated)

1 The first 5 because of Perl syntax, the last two because of IE silliness -- the "," is included for two reasons. IE won't wrap on " ," nor on " /".

Update2: I realized that [ will be encoded as &#91; and will be matched separately so I can remove the \[s from the regexes and probably revert to my best-practice method of using [ ] delimiters for regexes despite the mod_perl(?) bug. This also means that spaces won't be inserted in front of other characters that get encoded, namely any of <>], which is probably not worth trying to work around.

- tye        


In reply to Re: A call to keyboards: Better chatterbox wrapping (tye) by tye
in thread A call to keyboards: Better chatterbox wrapping by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.