[thelist] soft-wrap unbreaking long words

sam foster potatosculptor at gmail.com
Tue Aug 22 09:48:53 CDT 2006


Here's what I've got so far:
http://www.sam-i-am.com/work/sandbox/javascript/softwrap.html

I'm pretty happy with it as a first pass, but it'll need benchmarking
and probably optimizing for performance, and no doubt there's some
input I've not anticipated. One big one is non-latin characters? I'm
handling their escaped entites (in this case my server should have
escaped them for me), but it could probably improve.

And yes, I understand the fallacy of this. But by using a soft-wrap,
at least it wont hurt, and pushes the problem out to edge cases where
there's diminishing returns.

Browser support btw would be for IE6+, Safari 2+, Opera 8+,
FF/Mozilla. If you wanted to broaden that be my guest.

Sam

On 8/22/06, sam foster <potatosculptor at gmail.com> wrote:
> Does anyone have a good algorithm / routine for manipulating text to
> ensure the browser can wrap it. <snip> This is to *reduce*
> the likelihood of problems, not a silver bullet (it wont account for
> varying font-sizes or character widths).
>
> I made a start myself, but its a surpisingly subtle problem. My goal
> is to add &shy; or <wbr/> at or around a given maxcolumns. I need to
> handle escape entities correctly (i.e. count &eacute; as one
> character, and also html so <b>B</b> is also one character). Ideally,
> the wrap would happen after punctuation, and more ideally, at the end
> of a series of punctuation characters.



More information about the thelist mailing list