in reply to PM Poster (util for ease of posting / reply)

I'd like to send a special shout-out to dws, who understandably wouldn't tell me how to make a post to the forum (I have done some replies already, but never started a thread).

Let's be accurate. You asked (via CB) how you could post so that you could post a tool for helping post. I noted the incongruity, declined to tell you, and suggested that you get some more experience here before offering up posting tools. I've lost the scrollback, but I added something to the effect that gaining some experience here first would save you some grief.

In the specific case of this tool, adding a <br> at line-end makes for messy posts. It's abused, often by people who haven't figured out how to use <code> tags. Unless you're posting poetry, it's arguably better to let the browser width determine line breaks. For paragraph breaks, use <p>.

  • Comment on Re: PM Poster (util for ease of posting / reply)

Replies are listed 'Best First'.
Re: Re: PM Poster (util for ease of posting / reply)
by David Caughell (Monk) on Jul 13, 2003 at 01:09 UTC

    Alright. I have to admit at this point that you were absolutely right about not posting!

    That being said, I like writing in "natural text" and I'll work on a rewrite that will do something to convert that to paragraphs instead of breaks.

    "For fate which has ordained that there shall be no friendship among the evil has also ordained that there shall ever be friendship among the good." - Plato / Socrates

      This is by no means perfect, but it's a step up from your original code.
      #!/usr/bin/perl -T use strict; use warnings; use CGI qw(:standard); print header, start_html('PM Poster'), start_form, textarea('post',undef,8,30), submit('go'), end_form, ; if (param('go')) { for (split /\s*\n(?:\s*\n)(?!.*\n*<\/code>)+/, param('post')) { $_ =~ s/<(\/?)code>/<$1tt><$1pre>/g; print p($_),"\n"; } } print end_html; __END__ lines of source: 29 (including __END__ block) empty lines: 5 commenting (shebang to be considered code): 6 lines containing only "}" or ";": 3 lines of code: 10 (first print is really only 1 line)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
Re: Re: PM Poster (util for ease of posting / reply)
by David Caughell (Monk) on Aug 14, 2003 at 13:54 UTC

    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;

      It would have been nice, if the following line worked (which would have made my code a lot simpler):
      split /\n{2,}/, $inputed_text;

      I find that letting invisible spaces be significant causes lots of problems. This is one of them. Try:

      split /([^\S\n]*\n){2,}/, $input;
      It won't be defeated by trailing white-space (which is usually "invisible"), including cases of "\r\n", which you'll find is very common in multi-line text sent via HTTP (because that is what the standard says you are supposed to send, I believe).

      Note that [^\S\n] means 'any character that is not non-white-space nor "\n"', which can be reworded more clearly as 'any character that *is* white-space other than "\n"', which is a good way to match trailing white-space without risking sucking in the final "\n".

                      - tye

      ("input" is not a verb so I refuse to write "inputted" much less "inputed")