From 55c75a0c53862083d5d3c52b6ef6e6efa2864c7e Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 4 Oct 2009 01:08:57 +0000 Subject: [PATCH] source: various improvements --- source.plp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/source.plp b/source.plp index 8193de5..aad6898 100644 --- a/source.plp +++ b/source.plp @@ -20,7 +20,7 @@ $header{content_type} = "text/html; charset=utf-8"; .synConstant { color: #008 } .synType, .synIdentifier { color: #804 } - .synStatement { font-weight: bold } + .synStatement { } .synPreProc { } .synSpecial { color: #408 } .synError { font-weight: bold; background-color: #F00; color: #FFF } @@ -33,12 +33,56 @@ $header{content_type} = "text/html; charset=utf-8"; my $source = $ENV{PATH_INFO}; $source =~ s{^/}{}; -$source ||= $0; print "

Source of $source

\n"; +if ($source =~ m{(?:/|^)\.}) { + die "File request not permitted\n"; +} +elsif ($source =~ s{::}{/}g or !-e $source) { + $source .= '.pm'; + for (0 .. $#{@INC}) { + -e ($_ = "$INC[$_]/$source") or next; + $source = $_; + last; + } +} +-r $source or die "Requested file not found\n"; + require Text::VimColor; +delete $Text::VimColor::SYNTAX_TYPE{Underlined}; +my %TYPETAG = ( + Statement => 'strong', + Error => 'em', + Todo => 'em', +); + +my $hl = Text::VimColor->new( + file => $source, + vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'], +); +my $parsed = $hl->marked; print "
\n";
-my $hl = Text::VimColor->new(file => $source);
-print $hl->html;
+foreach (@$parsed) {
+	my $tag = $_->[0] && ($TYPETAG{ $_->[0] } || 'span');
+	my $arg = '';
+	print "<$tag$arg class=\"syn$_->[0]\">" if $tag;
+	if ($_->[0] eq 'Constant' and $_->[1] =~ s/^(')([a-z0-9_.]+\.plp?)(?=\1$)//) {
+		printf '%s%s', $1, "/source/$2", $2;
+	}
+	if (!$_->[0] and $_->[1] =~ s/^([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
+		printf '%s', "/source/$1", $1;
+	}
+	print Text::VimColor::_xml_escape($_->[1]);
+	print "" if $tag;
+}
 print "
\n"; +:> + + -- 2.30.0