mybin

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

commit c6ed0b4850f394d46a5d4bf9aa5cc0063a814d74
parent 3df1ecf0d07b61da1a701f93bffbfb451af488f7
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat,  3 Oct 2015 19:57:57 +0200

poem2html

Diffstat:
poem2html.pl | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+), 0 deletions(-)

diff --git a/poem2html.pl b/poem2html.pl @@ -0,0 +1,62 @@ +#!/usr/bin/env perl + +# convert to a custom shorthand for poems to HTML + +my $toTxt = 0; +my $inDedication = 0; +(my $toTxt = 1 && shift) if $ARGV[0] eq "-txt"; + +while (<STDIN>) { + chop; + exit if (/^###/); + next if (/^#/); + + if (!$title and !$seen) { + $title = "$_"; + next; + } + + if (/^ /) { + print "<p class=\"dedication\">\n" if not $inDedication; + $inDedication = 1; + print; + print "<br />\n"; + next; + } else { + print "</p>\n" if $inDedication; + $inDedication = 0; + } + print "<h3 class=\"ref\">$1</h3>\n" and next if (/^==\* (.*)$/); + print "<h3>$1</h3>\n" and next if (/^== (.*)$/); + if (/^$/) { + if (!$seen) { + print "<h2 id=\"$ARGV[0]\">$title</h2>\n" if (!$toTxt); + } else { + print "</div>\n" if ($in); + } + $in = 0; + $seen = 1; + next; + } + + print "<div class=\"stanza\">\n" if (!$in && !$toTxt); + if (!$seen) { + print "<p class=\"line\">$title</p>\n"; + $seen = 1; + } + + my $class = "line"; + if ($_ =~ /^> /) { + $class = "line indent"; + $_ =~ s/^> //; + } + if ($toTxt) { + print "$_\n"; + next; + } + $_ =~ s!\*(.*?)\*!<em>$1</em>!g; + print "<p class=\"$class\">\n$_\n</p>\n"; + $in = 1; +} + +