diff options
author | John Ankarström <john@ankarstrom.se> | 2020-12-11 00:24:14 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-12-11 00:24:14 +0100 |
commit | 869295358540c06765b31f853e55b6d6d2e5a99e (patch) | |
tree | 83660f7fdd616f56021a168c9d9f20de34455e25 | |
parent | 7e93c530bde69b4eb971dc400063d2e96a88306e (diff) | |
download | mht-869295358540c06765b31f853e55b6d6d2e5a99e.tar.gz |
mht, mht.1: Remove strict arities
Now, superfluous or missing arguments will be silently ignored.
Furthermore, only one definition of the same request is allowed.
But on the upside, the system is a whole lot simpler and can be made
even more flexible in the future than before.
-rwxr-xr-x | mht | 73 | ||||
-rw-r--r-- | mht.1 | 74 |
2 files changed, 50 insertions, 97 deletions
@@ -22,47 +22,33 @@ my $opel = ''; # currently opened block element # 1.2.1 Contiguous elements my %ctels = ( - Qp_0 => '<blockquote>{<p>%</p>}</blockquote>', + Qp => '<blockquote>{<p>%</p>}</blockquote>', ); # 1.2.2 Block elements my %blels = ( - Pp_0 => '<p>%</p>', - Pr_0 => '<pre>%</pre>', - Sh_0 => '<h3>%</h3>', - Sh_1 => '<h\\$1>%</h\\$1>', - Ti_0 => '<title>%</title>', + Hh => '<h\\$1>%</h\\$1>', + Pp => '<p>%</p>', + Pr => '<pre>%</pre>', + Sh => '<h3>%</h3>', + Ti => '<title>%</title>', ); # 1.2.3 Inline elements my %inels = ( - Au_1 => '<meta name="author" content="\\$1"/>', - Bd_1 => '<b>\\$1</b>', - Bd_2 => '<b>\\$1</b>\\$2', - Bd_3 => '\\$3<b>\\$1</b>\\$2', - br_0 => '<br/>', - Cd_1 => '<code>\\$1</code>', - Cd_2 => '<code>\\$1</code>\\$2', - Cd_3 => '\\$3<code>\\$1</code>\\$2', - Cs_1 => '<meta http-equiv="Content-Type" content="text/html; charset=\\$1"/>', - Da_0 => '<meta name="created" content="\\$1"/>', - Em_1 => '<em>\\$1</em>', - Em_2 => '<em>\\$1</em>\\$2', - Em_3 => '\\$3<em>\\$1</em>\\$2', - Hy_2 => '<a href="\\$2">\\$1</a>', - Im_2 => '<img src="\\$1" alt="\\$2"/>', - It_1 => '<i>\\$1</i>', - It_2 => '<i>\\$1</i>\\$2', - It_3 => '\\$3<i>\\$1</i>\\$2', - St_1 => '<strong>\\$1</strong>', - St_2 => '<strong>\\$1</strong>\\$2', - St_3 => '\\$3<strong>\\$1</strong>\\$2', - Tt_1 => '<tt>\\$1</tt>', - Tt_2 => '<tt>\\$1</tt>\\$2', - Tt_3 => '\\$3<tt>\\$1</tt>\\$2', - Ul_1 => '<u>\\$1</u>', - Ul_2 => '<u>\\$1</u>\\$2', - Ul_3 => '\\$3<u>\\$1</u>\\$2', + Au => '<meta name="author" content="\\$1"/>', + Bd => '\\$3<b>\\$1</b>\\$2', + br => '<br/>', + Cd => '\\$3<code>\\$1</code>\\$2', + Cs => '<meta http-equiv="Content-Type" content="text/html; charset=\\$1"/>', + Da => '<meta name="created" content="\\$1"/>', + Em => '\\$3<em>\\$1</em>\\$2', + Hy => '\\$4<a href="\\$2">\\$1</a>\\$3', + Im => '<img src="\\$1" alt="\\$2"/>', + It => '\\$3<i>\\$1</i>\\$2', + St => '\\$3<strong>\\$1</strong>\\$2', + Tt => '\\$3<tt>\\$1</tt>\\$2', + Ul => '\\$3<u>\\$1</u>\\$2', ); @@ -73,21 +59,20 @@ sub request { my ($el, $args) = @_; my @argv = quotewords('\s+', 0, $args); my $n = @argv; - my $elkey = "${el}_$n"; - if (exists $blels{$elkey} or exists $ctels{$elkey}) { + if (exists $blels{$el} or exists $ctels{$el}) { # Clear empty line buffer $empty = ''; # Close currently open block element, open new my ($base, $prestart, $newpostclose) = ('', '', ''); - if (exists $ctels{$elkey}) { - $base = $ctels{$elkey}; + if (exists $ctels{$el}) { + $base = $ctels{$el}; $prestart = prestart($base); $newpostclose = postclose($base); $base = inner($base); } else { - $base = $blels{$elkey}; + $base = $blels{$el}; } my $start = start($base); my $newclose = interpol(_close($base), @argv) . "\n"; @@ -102,8 +87,8 @@ sub request { print interpol($start, @argv) . "\n"; $opel = $el; - } elsif (exists $inels{$elkey}) { - print interpol($inels{$elkey}, @argv) . "\n"; + } elsif (exists $inels{$el}) { + print interpol($inels{$el}, @argv) . "\n"; } else { print STDERR "Error: $el/$n not implemented\n"; exit 1; @@ -113,12 +98,8 @@ sub request { # 1.3.2 Interpolate \$n parameters sub interpol { my $s = shift; - my $i = 1; - my $arg; - while ($arg = shift) { - $s =~ s/\\\$$i/$arg/g; - $i++; - } + no warnings qw/uninitialized/; + $s =~ s/\\\$(\d+)/$_[$1-1]/g; return $s; } @@ -26,8 +26,8 @@ As such, it supports only a subset of the standard troff requests. .Pp This section describes the various types of requests supported by .Nm . -On the left side are the name and arity of each request, separated by a slash. -On the right side is the HTML expansion of each request. +On the left side is the name of the request. +On the right side is the HTML expansion. .Pp In the HTML expansion of all element requests, a backslash and a dollar sign followed by a number (e.g. \\$1) signify a parameter expansion. .Pp @@ -36,79 +36,51 @@ In block element requests, a percent sign (%) signifies the lines following the Finally, in contiguous element requests, whatever text is on the outside of the area delimited by braces ({...}) is removed when two of the same contiguous element requests are placed next to one another. .Ss Standard troff requests .Bl -tag -.It Sy \&br/0 +.It Sy \&br <br/> .El .Ss Contiguous element requests .Bl -tag -.It Sy \&Qp/0 +.It Sy \&Qp <blockquote>{<p>%</p>}</blockquote> .El .Ss Block element requests .Bl -tag -.It Sy \&Pp/0 +.It Sy \&Hh +<h\\$1>%</h\\$1> +.It Sy \&Pp <p>%</p> -.It Sy \&Pr/0 +.It Sy \&Pr <pre>%</pre> -.It Sy \&Sh/0 +.It Sy \&Sh <h3>%</h3> -.It Sy \&Sh/1 -<h\\$1>%</h\\$1> -.It Sy \&Ti/0 +.It Sy \&Ti <title>%</title> .Ss Inline element requests .Bl -tag -.It Sy \&Au/1 +.It Sy \&Au <meta name="author" content="\\$1"/> -.It Sy \&Bd/1 -<b>\\$1</b> -.It Sy \&Bd/2 -<b>\\$1</b>\\$2 -.It Sy \&Bd/3 +.It Sy \&Bd \\$3<b>\\$1</b>\\$2 -.It Sy \&br/0 -<br/> -.It Sy \&Cd/1 -<code>\\$1</code> -.It Sy \&Cd/2 -<code>\\$1</code>\\$2 -.It Sy \&Cd/3 +.It Sy \&Cd \\$3<code>\\$1</code>\\$2 -.It Sy \&Cs/1 +.It Sy \&Cs <meta http-equiv="Content-Type" content="text/html; charset=\\$1"/> -.It Sy \&Em/1 -<em>\\$1</em> -.It Sy \&Em/2 -<em>\\$1</em>\\$2 -.It Sy \&Em/3 +.It Sy \&Da +<meta name="created" content="\\$1"/> +.It Sy \&Em \\$3<em>\\$1</em>\\$2 -.It Sy \&Hy/2 +.It Sy \&Hy <a href="\\$2">\\$1</a> -.It Sy \&Im/2 +.It Sy \&Im <img src="\\$1" alt="\\$2"/> -.It Sy \&It/1 -<i>\\$1</i> -.It Sy \&It/2 -<i>\\$1</i>\\$2 -.It Sy \&It/3 +.It Sy \&It \\$3<i>\\$1</i>\\$2 -.It Sy \&St/1 -<strong>\\$1</strong> -.It Sy \&St/2 -<strong>\\$1</strong>\\$2 -.It Sy \&St/3 +.It Sy \&St \\$3<strong>\\$1</strong>\\$2 -.It Sy \&Tt/1 -<tt>\\$1</tt> -.It Sy \&Tt/2 -<tt>\\$1</tt>\\$2 -.It Sy \&Tt/3 +.It Sy \&Tt \\$3<tt>\\$1</tt>\\$2 -.It Sy \&Ul/1 -<u>\\$1</u> -.It Sy \&Ul/2 -<u>\\$1</u>\\$2 -.It Sy \&Ul/3 +.It Sy \&Ul \\$3<u>\\$1</u>\\$2 .El . |