http://www.perlmonks.org?node_id=314621
Category: PerlMonks Related Scripts
Author/Contact Info Soren / somian / Intrepid check here
Description:

This is "pmnodecomp-blockquoter", and if you can say that 5 times and still chew salt-water taffy afterwards you get a prize. It's a helper for working in a Xterm shell and composing node text for posts here on Perlmonks. If you are replying to an existing node and wish to cite a brief part of what a previous poster has written, you may like to do so using a style that embraces the quote text in <blockquote> tags. This makes it visually stand out as being text attributable to another poster than yourself.

Related Links:

A cryptographically signed copy of the latest release of the program may also be obtained at the site:
here.


Update:

Now does what theorbtwo's reply and bart's reply wanted it to do. Also fixed a few other flaws. We now have a plugin-ready script that users can invent their own transmutations for.

Also the example shown below ought to be something like this instead (but see later at Second Update for an even better plan):


Then I switch to a text term (Xterm) and type:
$ pmnodecomp-blockquote <<'NOPOL8N'
which waits for me to paste the X cutbuffer / clipboard selection at the prompt.
Thanks to merlyn for the righteous slap that dispels brain-fevered idiocy like a bucket of icewater on a pair of amorous mutts.

There's nothing automagickal or sophisticated about it, it's a very simple tool. It is for when you don't care to fire up a text editor just for a quick-ish reply node, but you want to efficiently create a blockquote as part of your contribution. It's for a very lazy approach, made especially for those of us who's typing skills are not world-class ;-).

This was also an excuse for me to beat my head against the strangeness that is Perl's format and write functionality until I understood it well enough to write something useful employing them.

Users of a *NIX-like ('sh'-like) shell will get the best use out of this.

The next section is superceded by later refinements and corrections. Left for historical thread context.

I like the style of workflow in which I make an X-Windows selection of the text I wish to quote from the Perlmonks node (in my WWW browser). Then I switch to a text term (Xterm) and type:

$ cat <<'DONE' | pmnodecomp-blockquote
which waits for me to paste the X cutbuffer / clipboard selection at the prompt. Shell veterans may know other ways (TMTOWTDI) of getting the desired text poured into STDIN and then issuing the EOF (generally <CTRL-D> on *NIX, IAMNM). Anyway that's the general idea.

A completely empty newline must be present for paragraphs to be handled as separate from the preceeding one. This could be construed as a limitation ;-).

    Have fun --
Soren / somian / Intrepid


Second Update

After doing some testing I can recommend a refined "workflow" scheme for those who might be left in a second or two of puzzlement about how to use this tool otherwise. If you have the Linux/*nix tool xclip(1) on your system you can use it nicely like so:

  1. Make your selection with mouse in the source application/document window.
  2. Switch to your Xterm-like tool and issue the following command, i.e. :
    $ xclip -selection p -o | \ pmnodecomp-blockquoter | \ xclip -fi -selection c
    The -f switch to the last invocation of xclip will let that tool echo the output processed text to your terminal, acting as a preview so that you can see what was done. Eliminate it if you want silent operation.
  3. Switch to the Perlmonks node you wish to compose in your browser, place text cursor in the input box and issue CTRL-V or whatever maps to "paste" in your X environment. The blockquoted text now on the X clipboard will appear at your cursor position.

I realize these instructions will seem like huge overkill to many of the experts on the site, but we all had to learn somewhere, and I didn't want to leave novices to X or computers completely up the creek w/o a periscope. Adapting these instructions for another kind of environment that still has a usable shell (DOS would not fall under that category) is left as an exercise to the readers :-)

#!/usr/bin/env perl
eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

# $Author$ Last modified: 14 Dec 2003 15:30:18
# Suggested name: "pmnodecomp-blockquoter" - shorten if wished.
# Or better yet make a symlink or alias.
use strict;
BEGIN  {
    use vars qw! $plugin !;
    $plugin =
       (eval    { # Place your own home-brewed filter module below.
              # This is only a suggestive example / default.
         require PMntextFilter;
           # import  PMnTextFilter "quazzle wrench bangbar";
        }) ? 'extern' : 'intern';
}

use warnings;
use vars qw! $DeBug $acq $outfm $rcnt $pictstr !,
         qw! $amps $ltgt $sqbr !;
use subs qw! bbegin bendin newblk filtermeta !;

$DeBug = 0;
use constant rCNT => 66; # arbitrary length for output lines.
format EBLK =
  </blockquote>

.
format BBLK =
  <blockquote>
.
format NBLK =
  <br><br>
.

if    ($plugin eq 'extern')
{
    $amps = sub { PMntextFilter::amps(@_) };
    $ltgt = sub { PMntextFilter::ltgt(@_) };
    $sqbr = sub { PMntextFilter::sqbr(@_) };
}
else
{
    $amps = sub
    {
    my $amper = '&amp;';
    my $para = shift;
    $para =~ s% \& %$amper%oxgm;
    return $para;
    };
    $ltgt = sub
    {
    my ($lt,$gt) = ( '&lt;','&gt;' );
    my $para = shift;
    $para =~ s% \< %$lt%oxgm;
    $para =~ s% \> %$gt%oxgm;
    print STDERR "\n$acq\n" if $DeBug;
    return $para;
    };
    $sqbr = sub
    {
    my ($sqbro,$sqbrc) =
                  ( '&#91;','&#93;' );
    my $para = shift;
    $para =~ s% \[ %$sqbro%oxgm;
    $para =~ s% \] %$sqbrc%oxgm;
    print STDERR "\n$acq\n" if $DeBug;
    return $para;
    };
}

$pictstr = q[^] . q[<] x rCNT;
$outfm = qq[format STDOUT = ]
        .qq[\n        $pictstr\n]
        . q[$acq] . qq[\n.\n];
eval $outfm;
   die "Bad perl format!: $@" if $@;
my $splurt = sub { local $/ = qq[]; $acq = <STDIN> };
my $pc = 0;
bbegin;
while (&$splurt and $pc++ < 10000)
{
    filtermeta  $acq;
    write while $acq;
    newblk unless eof(STDIN);
}
bendin;

exit 0;

sub filtermeta
{ # Do what you want to here. Given is a minimal default.
    $acq=&$amps($acq);
    $acq=&$ltgt($acq);
    $acq=&$sqbr($acq);
}
sub newblk
{
    local $~ = "NBLK";
    write;
}
sub bbegin
{
    local $~ = "BBLK";
    write;
}
sub bendin
{
    local $~ = "EBLK";
    write;
}