in reply to Substituting Newline Characters
You possibly want something like this assuming the goal is to make plain text render with formatting intact as HTML.
sub escapeHTML { local $_ = shift; # make the required escapes s/&/&/g; s/"/"/g; s/</</g; s/>/>/g; # change tabs to 4 spaces s/\t/ /g; # make the whitespace escapes - not required within <pre> tags s/( {2,})/" " x length $1/eg; # make the brower bugfix escapes; s/\x8b/‹/g; s/\x9b/›/g; # change newlines to <br> if desired - not required with <pre> s/\n/<br>\n/g; return $_; }
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Substituting Newline Characters
by Happy-the-monk (Canon) on Mar 15, 2004 at 23:51 UTC | |
by tachyon (Chancellor) on Mar 16, 2004 at 00:03 UTC | |
by jeffa (Bishop) on Mar 16, 2004 at 02:35 UTC | |
by tachyon (Chancellor) on Mar 16, 2004 at 03:09 UTC | |
by Aristotle (Chancellor) on Mar 16, 2004 at 14:20 UTC | |
| |
|
Re^2: Substituting Newline Characters
by Anonymous Monk on Mar 16, 2004 at 05:18 UTC | |
by tachyon (Chancellor) on Mar 16, 2004 at 13:11 UTC |