</pre>
% } elsif ($lang =~ /^hl:(.*)$/) {
<pre class="paste">
-<%perl>
- my $hl_lang = $1;
- my $kid = open my $fh, "-|" // die "fork: $!";
- if ($kid == 0) {
- open my $hl, "|-", "highlight", "-Ohtml", "-f", "-t8", "-S$hl_lang"
- or die "open highlight: $!";
- syswrite $hl, $content // die "highlight write: $!";
- close $hl or die "highlight kid: $!, $?";
- exit 0;
- } else {
- while (sysread $fh, my $buf, 8192) { $m->print($buf); }
- close $fh and waitpid $kid, 0
- or die "highlight parent: $!, $?";
- }
-</%perl>
+% filter "highlight", $m, $content,
+% "highlight", "-Ohtml", "-f", "-t8", "-S$1";
</pre>
% } else {
<div class="note">
%#
<%once>
use utf8;
+
+ sub filter ($$$@) {
+ my ($what, $m, $content, @cmd) = @_;
+ my $kid = open my $fh, "-|" // die "fork: $!";
+ if ($kid == 0) {
+ open my $hl, "|-", @cmd or die "open $what: $!";
+ syswrite $hl, $content // die "$what write: $!";
+ close $hl or die "$what kid: $!, $?";
+ exit 0;
+ } else {
+ while (sysread $fh, my $buf, 8192) { $m->print($buf); }
+ close $fh and waitpid $kid, 0
+ or die "$what parent: $!, $?";
+ }
+ }
</%once>