From michael.burns@cosbit.com Sat Jul 14 15:57:34 2007 From: Michael Burns To: dev@lists.roundcube.net Subject: Re: Long Line Break (was: Preview Pane) Date: Thu, 07 Sep 2006 09:47:29 -0600 Message-ID: In-Reply-To: <45002094.1000509@introweb.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7371570514157151039==" --===============7371570514157151039== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Good morning, On 7-Sep-06, at 7:37 AM, Robin Elfrink wrote: > Now for Internet Explorer to break long lines, didn't even see that > before, was too busy resizing
s ... I've used the following "hack" before to force long lines to break. In my testing, it works in Safari / Firefox / IE / Opera without hassle. The tag is non-standard though so any XHTML validators will complain ... but it's the best I could come up with that was the most compliant and compatible: If you insert that every so often into long strings, it creates an optional line break that doesn't otherwise affect copy/paste or create any odd visual artifacts if no break is required. (I tend to insert it every 15 characters in strings longer than 15 characters.) I don't have any PHP-foo do to that automagically, but here's my Perl- foo that does it. I can feed arbitrary html and it'll intelligently insert it, without clobbering html or anything... if someone can help convert it into PHP, simply add it to the output function for your emails (or anywhere you need it) and it should work. I just call: my $html = '

some html here with reallyreallyreallylongstringsofcharacters and other things.

'; print html_splitter($html); Output:

some html here with reallyreallyreallylongstringsofcharacters and other things.

Let me know, I'm happy to address comments / concerns / criticisms of the technique :-) (note for Perl-isms: all the HTML::Entities stuff is needed to properly work with embedded entities without splitting in the middle; so that & is recognized as one character and preserved and not split half-way through) ---begin perl--- # # call as: html_splitter( $string [, length] ) # returns: your string, with a # # # # inserted every [length] characters (15 by default) on inter-tag # "words" (non-space characters actually) longer than [length] # # the effect (so it seems with testing so far) of letting # browsers and email clients split real long strings (such as # email addresses or urls) while retaining their copy-and-paste # ability # # Note: this code doesn't validate, as isn't a W3C official entity # # Note: we assume the string may contain markup, and so we don't process # and text between <> (tag-like sequences) # # Note: to prevent splitting HTML entities (& for example), we decode # all string fragments into multi-byte chars, do the splitting (if needed), # then re-encode into HTML entities # # Compatibility: tested thus far with Firefox, Safari, IE, Opera # sub html_splitter { my $string = shift; my $length = shift || 15; # find interesting bits and turn to next subroutine $string =~ s/(^|>)([^<]+)(<|$)/$1 . string_splitter($2, $length) . $3/egs; return $string; } # # used by html_splitter() to actually break the chunks # sub string_splitter { my $string = shift; my $length = shift; # first, decode any entities HTML::Entities::decode_entities($string); # next split any long words in this bit $string =~ s/(\S\S{$length,})/word_splitter($1,$length)/eg; return $string; } # # used by string_splitter() to do the work # sub word_splitter { my $string = shift; my $length = shift; my $strlen = length($string); my $out = HTML::Entities::encode_entities(substr($string, 0, $length)); for (my $i = $length; $i < $strlen; $i += $length) { $out .= q||; $out .= HTML::Entities::encode_entities(substr($string, $i, $length)); } return $out; } ---end perl--- > Robin -Michael _______________________________________________________ Michael Burns Cosbit Technologies 403-701-2672 / michael.burns(a)cosbit.com GTalk: cmikeburns AIM: cmikeburns MSN: cmikeburns _______________________________________________________ Box 2173, Station M • Calgary, Alberta, Canada • T2P 2M4 http://cosbit.com --===============7371570514157151039==--