Pete Freitag Pete Freitag

Widon't and Widows

coldfusionweb

Shaun Innman posted about a technique he call's Widon't, for dealing with the widow problem on the web.

The widow problem is when you have a single word on a line by itself, at the end of a headline or paragraph. In typesetting this word is called a widow.

For example:

Man Walks On 
Moon

Moon is the widow in the above example. Shaun fixes this by replacing the last space with an   He provides a function in PHP, but here's a simple regular expression for ColdFusion to do the same:

ReReplace(headline, " ([^ ]+)$", " \1")

It can get a bit trickier to fix this at the end of paragraphs, here's another regular expression that might work for that (need to test more):

ReReplace(text, " ([^ ]+\r?\n)", " \1", "ALL")

Like this? Follow me ↯

Widon't and Widows was first published on September 05, 2006.

If you like reading about text, type, typesetting, regex, rereplace, widows, or widont then you might also like:

FuseGuard Web App Firewall for ColdFusion

The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.

Comments

Nice solution for IE but I haven't had any luck with   in Firefox
by Ryan Smith on 10/30/2006 at 9:27:05 PM UTC
Marvelous. Thanks, will spread this among my friends!
by hogan on 12/26/2006 at 9:19:25 AM UTC
Marvelous. Thanks, will spread this among my friends!
by intial on 12/26/2006 at 5:08:25 PM UTC
Marvelous. Thanks, will spread this among my friends!
by jewerly on 12/26/2006 at 7:07:32 PM UTC