in reply to Re: PM Poster (util for ease of posting / reply)
in thread PM Poster (util for ease of posting / reply)
I've returned to this post at the close of my semester in college.
I've read through a book on CGI/Perl that was an introductory book, as well as through the first chapter and a bit of Programming Perl. Because I don't have too much reading under my belt, the code for this is a little sloppy.
I rewrote the script (even after Jeffa posted a good one) for two reasons: One, that I didn't understand Jeffa's script, and Two, that it's important that the script output as text/plain, so that it will be easy to cut and paste into the post window (otherwise the paragraph tags disappear). I made sure to take out the break tags, too!
It would have been nice, if the following line worked (which would have made my code a lot simpler):
split /\n{2,}/, $inputed_text;
However, that doesn't work, hence the messy code for determining what a paragraph is:
#!/usr/bin/perl -w use strict; use CGI qw(:standard -debug); # Perlmonks.org Poster, by David Caughell, grasp_the_sun@yahoo.co.uk # Converts simple text into text that can be cut and paste into PM pos +ts print "Content-type: text/plain\n\n"; my $text = param('FPost'); my @sections = split('code'.'>', $text); # get rid of leftovers from code tags for (@sections) { chop if /\/$/; chop if /<$/; } for (0 .. $#sections) { unless ($_ % 2) { my @lines = split /\n/, $sections[$_]; my @paragraphs = (''); for (@lines) { if (length $_ <= 1) { push(@paragraphs,'') if length($paragraphs[$#paragraphs]); } $paragraphs[$#paragraphs] .= $_ if length $_ > 1; } pop(@paragraphs) unless length $paragraphs[$#paragraphs]; print "<P>\n$_\n</P>\n\n" for @paragraphs; } else { print '<code'.">\n$sections[$_]</code".">\n\n"; } }
Dave.
$scratchpad_public = 0 unless $scratchpad;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: PM Poster (util for ease of posting / reply) (invisible)
by tye (Sage) on Aug 14, 2003 at 19:59 UTC |