From febdbe4ebad7543875c1e6ce4d1f1e798a4951ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 1 Dec 2020 01:39:57 +0100 Subject: mht: Handle contiguous elements (like Qp) Qp is a quoted paragraph. A subsequent Qp should be put within the
tag of the previous Qp. --- mht | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/mht b/mht index 070c121..1591730 100755 --- a/mht +++ b/mht @@ -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 => '
{

%

}
', +); + +# 1.2.2 Block elements my %blels = ( Pp_0 => '

%

', - Qp_0 => '

%

', Pr_0 => '
%
', Sh_0 => '

%

', Sh_1 => '%', Ti_0 => '%', ); -# 1.2.2 Inline elements +# 1.2.3 Inline elements my %inels = ( Au_1 => '', Bd_0 => '\\$3\\$1\\$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 -- cgit v1.2.3