From: Mark Wooding Date: Mon, 10 Apr 2017 14:54:51 +0000 (+0100) Subject: bin/populate-lang-table, mason/pastebin/%show: Segregate `highlight' languages. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/odin-cgi/commitdiff_plain/969db1ef94e92c88afaa35b683918b2bf33b87f0 bin/populate-lang-table, mason/pastebin/%show: Segregate `highlight' languages. Rename languages processed by `highlight' to be `hl:BLAH'. This will break existing deployments. Benefit: now I can add new language tags which don't interfere with `highlight'. --- diff --git a/bin/populate-lang-table b/bin/populate-lang-table index a5b6bee..407a940 100755 --- a/bin/populate-lang-table +++ b/bin/populate-lang-table @@ -9,11 +9,11 @@ my %newlang, %oldlang; open my $fh, "-|", "highlight", "-p" or die "highlight: $!"; while (<$fh>) { my ($descr, $lang) = /^(.*\S)\s*:\s*(\S+)(?:\s.*|)$/; - next unless defined $lang; - $newlang{$lang} = $descr; + next if !defined $lang or $lang eq "txt"; + $newlang{"hl:$lang"} = $descr; } close $fh or die "close highlight: $! $?"; -$newlang{"txt"} //= "Plain text"; +$newlang{"txt"} = "Plain text"; Odin::xact { my $h = $db->selectall_hashref diff --git a/mason/pastebin/%show b/mason/pastebin/%show index 6ec0bb2..9e6afab 100644 --- a/mason/pastebin/%show +++ b/mason/pastebin/%show @@ -19,14 +19,17 @@ "$Odin::PASTEBIN/$tag" |h %> % } -
 % if ($lang eq 'txt') {
+
 <% $content |h %>\
-% } else {
+
+% } elsif ($lang =~ /^hl:(.*)$/) { +
 <%perl>
+	my $hl_lang = $1;
 	my $kid = open my $fh, "-|" // die "fork: $!";
 	if ($kid == 0) {
-	  open my $hl, "|-", "highlight", "-Ohtml", "-f", "-t8", "-S$lang"
+	  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: $!, $?";
@@ -37,8 +40,17 @@
 	    or die "highlight parent: $!, $?";
 	}
 
-% }
 
+% } else { +
+

I don't know how to display content with language + ‘<% $lang |h %>’. This is a bug in the Pastebin program. + Here's the raw text, in case that's useful. +

+
+<% $content |h %>\
+
+% } %# <%args>