diff options
-rwxr-xr-x | mht | 62 |
1 files changed, 52 insertions, 10 deletions
@@ -12,22 +12,28 @@ use Text::ParseWords qw/quotewords/; # 1.1 Global program state my $empty = ''; # currently buffered empty lines -my $close = ''; # buffered closing tag for currently opened element +my $close = ''; # buffered closing tag for currently opened block element +my $postclose = ''; # buffered extra closing tag for opened contiguous element +my $opel = ''; # currently opened block element # 1.2 Elements -# 1.2.1 Block elements +# 1.2.1 Contiguous elements +my %ctels = ( + Qp_0 => '<blockquote>{<p>%</p>}</blockquote>', +); + +# 1.2.2 Block elements my %blels = ( Pp_0 => '<p>%</p>', - Qp_0 => '<blockquote><p>%</p></blockquote>', Pr_0 => '<pre>%</pre>', Sh_0 => '<h3>%</h3>', Sh_1 => '<h\\$1>%</h\\$1>', Ti_0 => '<title>%</title>', ); -# 1.2.2 Inline elements +# 1.2.3 Inline elements my %inels = ( Au_1 => '<meta name="author" content="\\$1"/>', Bd_0 => '\\$3<b>\\$1</b>\\$2', @@ -53,15 +59,33 @@ sub request { my $n = @argv; my $elkey = "${el}_$n"; - if (exists $blels{$elkey}) { + if (exists $blels{$elkey} or exists $ctels{$elkey}) { # Clear empty line buffer $empty = ''; # Close currently open block element, open new + my ($base, $prestart, $newpostclose) = ('', '', ''); + if (exists $ctels{$elkey}) { + $base = $ctels{$elkey}; + $prestart = prestart($base); + $newpostclose = postclose($base); + $base = inner($base); + } else { + $base = $blels{$elkey}; + } + my $start = start($base); + my $newclose = interpol(_close($base), @argv) . "\n"; + print $close; - $close = interpol(end($blels{$elkey}), @argv) . "\n"; + $close = $newclose; - print interpol(start($blels{$elkey}), @argv) . "\n"; + print $postclose if $el ne $opel; + $postclose = $newpostclose; + + print $prestart if $el ne $opel; + print interpol($start, @argv) . "\n"; + + $opel = $el; } elsif (exists $inels{$elkey}) { print interpol($inels{$elkey}, @argv) . "\n"; } else { @@ -82,16 +106,34 @@ sub interpol { return $s; } -# 1.3.3 Retrieve first portion of block element string +# 1.3.3 Retrieve opening tag of block element string sub start { return (split '%', shift)[0]; } -# 1.3.4 Retrieve second portion of block element string -sub end { +# 1.3.4 Retrieve closing tag of block element string +sub _close { return (split '%', shift)[1]; } +# 1.3.5 Retrieve extra opening tag of block element string +sub prestart { + return (split '{', shift)[0]; +} + +# 1.3.6 Retrieve extra closing tag of block element string +sub postclose { + return (split '}', shift)[-1]; +} + +# 1.3.7 Retrieve inner block of contiguous tag +sub inner { + my $s = shift; + $s =~ s/^.*?\{//; + $s =~ s/}.*?$//; + return $s +} + # 2 Program |