- enclosed highlighted body in <pre> .. </pre>
- added reference to the used .css
my $documentroot = '/projects/matita/public_html/';
my $protohrc = $documentroot . 'helm-proto.hrc';
my $scriptsdir = $documentroot . 'library/';
my $documentroot = '/projects/matita/public_html/';
my $protohrc = $documentroot . 'helm-proto.hrc';
my $scriptsdir = $documentroot . 'library/';
-my $hlformat = "grafite";
+
+my %formatmap = (
+ ".ma" => "grafite",
+ ".c" => "c", # debug
+);
# Code
my $query = CGI->new; # used globally by some 'sub' below
# Code
my $query = CGI->new; # used globally by some 'sub' below
-print $query->header, $query->start_html;
+ print $query->start_html;
print 'Invalid script.';
print $query->end_html;
exit 0;
print 'Invalid script.';
print $query->end_html;
exit 0;
sub lookup_script($) {
my ($f) = @_;
sub lookup_script($) {
my ($f) = @_;
- die_invalid_file() unless $f =~ /^(.*)(\.ma)$/;
+ die_invalid_file() unless $f =~ /^(.*)(\.[^.]+)$/;
die_invalid_file() unless $base =~ /[-a-zA-Z_]+(\/[-a-zA-Z_])*/;
die_invalid_file() unless $base =~ /[-a-zA-Z_]+(\/[-a-zA-Z_])*/;
+ die_invalid_file() unless exists $formatmap{$extension};
my $path = $scriptsdir . $f;
die_invalid_file() unless -f $path;
my $path = $scriptsdir . $f;
die_invalid_file() unless -f $path;
+ return ($path, $formatmap{$extension});
}
my $fname = $query->param('f');
}
my $fname = $query->param('f');
my $highlighter = Syntax::Highlight::Universal->new;
$highlighter->addConfig($protohrc);
my $highlighter = Syntax::Highlight::Universal->new;
$highlighter->addConfig($protohrc);
-my $script = lookup_script($fname);
+my ($script, $format) = lookup_script($fname);
open SCRIPT, "< $script" or die "Can't open Matita script \"$script\"\n";
my @lines = <SCRIPT>;
my $text = join "", @lines;
close SCRIPT;
open SCRIPT, "< $script" or die "Can't open Matita script \"$script\"\n";
my @lines = <SCRIPT>;
my $text = join "", @lines;
close SCRIPT;
-my $result = $highlighter->highlight($hlformat, $text);
+print $query->start_html(-style=>{"src"=>"/$format-format.css"});
+my $result = $highlighter->highlight($format, $text);
+print "<pre>\n";