[Boulder.pm] perl/HTML/XHTML

Keanan Smith KSmith at netLibrary.com
Fri Oct 18 12:18:43 CDT 2002


$Content =~ s/\n+(?!(?:(?!<pre).)*<\/pre)/\n/gsi;

Remove all newlines that aren't in <pre>...</pre> tags

-----Original Message-----
From: Walter Pienciak [mailto:walter at frii.com]
Sent: Friday, October 18, 2002 11:10 AM
To: boulder-pm at mail.pm.org
Subject: [Boulder.pm] perl/HTML/XHTML


Howdy, and welcome to the almost-weekend.

For a web-upload mechanism of mine, I'm adding QC modules that
check/delete pesky Control-M's and whack excessive amounts of
empty lines.

Now, with the file contents in $Content, the first is easy:

 $Content =~ s/^M//go;

But the second, hrmmm.  Because if someone is uploading a file
with preformatted content, we DON'T want to whack those newlines.

So while the simple solution of

 $Content =~ s/\n+/\n/go;

works for 99% of the files on the site, it will destroy the last 1%.

And this is a bit too naive:

 $Content =~ /<pre>/io # Skip it

So, any ideas about a robust solution? Or, for that matter, just
a list of tags that should indicate a hands-off approach?

Walter

_______________________________________________
Boulder-pm mailing list
Boulder-pm at mail.pm.org
http://mail.pm.org/mailman/listinfo/boulder-pm



More information about the Boulder-pm mailing list