Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 26109b2

Browse files
dschokblees
authored andcommitted
Gitweb: add support for Alex Gorbatchev's SyntaxHighlighter in Javascript
Gitweb is not exactly what you would call server-friendly, so let's offload one more task onto the client. To enable this, put something like this into your gitweb_config.perl: $feature{'syntaxhighlighter_js'}{'default'} = [{ url => '/SyntaxHighlighter/', style => 'Django', theme => 'FadeToGrey' }]; and clone git://github.com/alexgorbatchev/SyntaxHighlighter into the directory you specified via the 'url' parameter. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b96a6fd commit 26109b2

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

gitweb/gitweb.perl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7075,7 +7075,19 @@ sub git_blob {
70757075
# we can have blame only for text/* mimetype
70767076
$have_blame &&= ($mimetype =~ m!^text/!);
70777077

7078+
my $highlight_js = gitweb_check_feature('syntaxhighlighter_js');
7079+
if ($highlight_js) {
7080+
push @stylesheets, $highlight_js->{url} . '/styles/shCore'
7081+
. $highlight_js->{style} . '.css';
7082+
push @stylesheets, $highlight_js->{url} . '/styles/shTheme'
7083+
. $highlight_js->{theme} . '.css';
7084+
}
7085+
70787086
my $highlight = gitweb_check_feature('highlight');
7087+
if ($highlight_js && $highlight) {
7088+
die_error(500, 'The highlight and syntaxhighlighter_js are'
7089+
. 'mutually exclusive');
7090+
}
70797091
my $syntax = guess_file_syntax($highlight, $mimetype, $file_name);
70807092
$fd = run_highlighter($fd, $highlight, $syntax)
70817093
if $syntax;
@@ -7123,6 +7135,58 @@ sub git_blob {
71237135
href(action=>"blob_plain", hash=>$hash,
71247136
hash_base=>$hash_base, file_name=>$file_name) .
71257137
qq!" />\n!;
7138+
} elsif ($highlight_js) {
7139+
my $ext = $file_name;
7140+
$ext =~ s/.*\.//;
7141+
print qq!<pre class="brush:!.$ext.qq!">!;
7142+
while (my $line = <$fd>) {
7143+
$line =~ s!&!\&#38;!g;
7144+
$line =~ s!<!\&#60;!g;
7145+
print $line;
7146+
}
7147+
print qq!</pre>!;
7148+
foreach my $name ('Core', 'Autoloader') {
7149+
print qq!<script src="!.$highlight_js->{url}
7150+
.qq!/scripts/sh!.$name
7151+
.qq!.js" type="text/javascript"></script>!;
7152+
}
7153+
print qq!<script type="text/javascript">!;
7154+
print qq!SyntaxHighlighter.defaults["pad-line-numbers"] = 3;!;
7155+
print qq!SyntaxHighlighter.defaults["toolbar"] = false;!;
7156+
# for XHTML compliance
7157+
print qq!SyntaxHighlighter.config["space"] = '&#160;';!;
7158+
print qq!SyntaxHighlighter.autoloader(!;
7159+
my $brush_prefix = $highlight_js->{url} . '/scripts/shBrush';
7160+
foreach my $language ('applescript AppleScript',
7161+
'actionscript3 as3 AS3',
7162+
'bash shell Bash',
7163+
'clj Clojure',
7164+
'coldfusion cf ColdFusion',
7165+
'cpp c Cpp',
7166+
'c# c-sharp csharp CSharp',
7167+
'css Css',
7168+
'delphi pascal Delphi',
7169+
'diff patch pas Diff',
7170+
'erl erlang Erlang',
7171+
'groovy Groovy',
7172+
'java Java',
7173+
'jfx javafx JavaFX',
7174+
'js jscript javascript JScript',
7175+
'perl pl Perl',
7176+
'php Php',
7177+
'text plain Plain',
7178+
'py python Python',
7179+
'ruby rails ror rb Ruby',
7180+
'scala Scala',
7181+
'scm Scheme',
7182+
'sql Sql',
7183+
'vb vbnet Vb',
7184+
'xml xhtml xslt html Xml') {
7185+
my $lang = $language;
7186+
$lang =~ s! (\S+)$! $brush_prefix$1!;
7187+
print "'".$lang.qq!.js',!;
7188+
}
7189+
print qq!''); SyntaxHighlighter.all();</script>!;
71267190
} else {
71277191
my $nr;
71287192
while (my $line = <$fd>) {

0 commit comments

Comments
 (0)