aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-12-01 01:39:57 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-12-01 01:39:57 +0100
commitfebdbe4ebad7543875c1e6ce4d1f1e798a4951ef (patch)
tree972f4de1c3b05e9ba928d9419104e88961694ceb
parent0eed74928168dcdaaa5bced1522acbb6072d13b2 (diff)
downloadmht-febdbe4ebad7543875c1e6ce4d1f1e798a4951ef.tar.gz
mht: Handle contiguous elements (like Qp)
Qp is a quoted paragraph. A subsequent Qp should be put within the <blockquote> tag of the previous Qp.
-rwxr-xr-xmht62
1 files 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 => '<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