mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

poem2html.pl (1182B)


      1 #!/usr/bin/env perl
      2 
      3 # convert to a custom shorthand for poems to HTML
      4 
      5 my $toTxt = 0;
      6 my $inDedication = 0;
      7 (my $toTxt = 1 && shift) if $ARGV[0] eq "-txt";
      8 
      9 while (<STDIN>) {
     10   chop;
     11   exit if (/^###/);
     12   next if (/^#/);
     13 
     14   if (!$title and !$seen) {
     15     $title = "$_";
     16     next;
     17   }
     18 
     19   if (/^  /) {
     20     print "<p class=\"dedication\">\n" if not $inDedication;
     21     $inDedication = 1;
     22     print;
     23     print "<br />\n";
     24     next;
     25   } else {
     26     print "</p>\n" if $inDedication;
     27     $inDedication = 0;
     28   }
     29   print "<h3 class=\"ref\">$1</h3>\n" and next if (/^==\* (.*)$/);
     30   print "<h3>$1</h3>\n" and next if (/^== (.*)$/);
     31   if (/^$/) {
     32     if (!$seen) {
     33       print "<h2 id=\"$ARGV[0]\">$title</h2>\n" if (!$toTxt);
     34     } else {
     35       print "</div>\n" if ($in);
     36     }
     37     $in = 0;
     38     $seen = 1;
     39     next;
     40   }
     41 
     42   print "<div class=\"stanza\">\n" if (!$in && !$toTxt);
     43   if (!$seen) {
     44     print "<p class=\"line\">$title</p>\n";
     45     $seen = 1;
     46   }
     47 
     48   my $class = "line";
     49   if ($_ =~ /^> /) {
     50     $class = "line indent";
     51     $_ =~ s/^> //;
     52   }
     53   if ($toTxt) {
     54     print "$_\n";
     55     next;
     56   }
     57   $_ =~ s!\*(.*?)\*!<em>$1</em>!g;
     58   print "<p class=\"$class\">\n$_\n</p>\n";
     59   $in = 1;
     60 }
     61 
     62