plint_extra

various extra tools around plint
git clone https://a3nm.net/git/plint_extra/
Log | Files | Refs | README

make_poem.pl (1254B)


      1 #!/usr/bin/perl
      2 
      3 use HTML::Entities;
      4 
      5 my $actor;
      6 my $indent;
      7 my $first = 1;
      8 my %actions;
      9 
     10 while (<STDIN>) {
     11   chop;
     12   if (/^<([^>]*)> \/me plint (.*)$/) {
     13     if ($1 ne $actor) {
     14       $actions{$1} = $2;
     15     } else {
     16       my $did = encode_entities($2, '<>&"');
     17       print "</p>\n";
     18       print "<p class=\"did\">$actor $did</p>\n";
     19       print "<p class=\"speech\">\n";
     20     }
     21   } elsif (/^<([^>]*)> (.*)$/) {
     22     if ($1 ne $actor) {
     23       print "</p>\n" unless $first;
     24       $first = 0;
     25       $actor = $1;
     26       my $eactor = encode_entities($actor, '<>&"');
     27       print "<p class=\"actor\"><span class=\"actor\">$eactor</span>";
     28       if (exists $actions{$1}) {
     29         my $did = encode_entities($actions{$1}, '<>&"');
     30         print ", <span class=\"did\">$did</span>";
     31         delete $actions{$1};
     32       }
     33       print "</p>\n";
     34       print "<p class=\"speech\">\n";
     35     }
     36     my $rawverse = $2;
     37     if ($2 =~ m/^ *\.\.\./) {
     38       $indent++;
     39     } else {
     40       $indent = 0;
     41     }
     42     my $verse = encode_entities($rawverse, '<>&"');
     43     if ($indent) {
     44       my $offset = 4 * $indent . "em";
     45       print "<span style=\"margin-left: $offset;\">$verse</span><br />\n";
     46     } else {
     47       print "$verse<br />\n";
     48     }
     49   }
     50 }
     51 
     52 print "</p>\n" unless $first;