@@ -4547,6 +4547,29 @@ sub git_print_page_path {
4547
4547
print $cgi -> a({-href => href(action => " blob_plain" , file_name => $file_name ,
4548
4548
hash_base => $hb ),
4549
4549
-title => $name }, esc_path($basename ));
4550
+ if (gitweb_check_feature(' highlight' )) {
4551
+ print '
4552
+ <a id="lineNoToggle" href="#" onclick="toggleLineNumbers();"></a>
4553
+ <script>
4554
+ function toggleLineNumbers() {
4555
+ e = document.getElementById("lineNoStyle");
4556
+ e2 = document.getElementById("lineNoToggle");
4557
+ if (e2.innerHTML == "[Hide line numbers]") {
4558
+ e.innerHTML = ".linenr { display:none; }";
4559
+ e2.innerHTML = "[Show line numbers]";
4560
+ }
4561
+ else {
4562
+ e.innerHTML = "";
4563
+ e2.innerHTML = "[Hide line numbers]";
4564
+ }
4565
+ }
4566
+ var style = document.createElement("style");
4567
+ style.setAttribute("id", "lineNoStyle");
4568
+ document.getElementsByTagName("head")[0].appendChild(style);
4569
+ toggleLineNumbers();
4570
+ </script>
4571
+ ' ;
4572
+ }
4550
4573
} elsif (defined $type && $type eq ' tree' ) {
4551
4574
print $cgi -> a({-href => href(action => " tree" , file_name => $file_name ,
4552
4575
hash_base => $hb ),
@@ -7058,7 +7081,19 @@ sub git_blob {
7058
7081
# we can have blame only for text/* mimetype
7059
7082
$have_blame &&= ($mimetype =~ m ! ^text/! );
7060
7083
7084
+ my $highlight_js = gitweb_check_feature(' syntaxhighlighter_js' );
7085
+ if ($highlight_js ) {
7086
+ push @stylesheets , $highlight_js -> {url } . ' /styles/shCore'
7087
+ . $highlight_js -> {style } . ' .css' ;
7088
+ push @stylesheets , $highlight_js -> {url } . ' /styles/shTheme'
7089
+ . $highlight_js -> {theme } . ' .css' ;
7090
+ }
7091
+
7061
7092
my $highlight = gitweb_check_feature(' highlight' );
7093
+ if ($highlight_js && $highlight ) {
7094
+ die_error(500, ' The highlight and syntaxhighlighter_js are'
7095
+ . ' mutually exclusive' );
7096
+ }
7062
7097
my $syntax = guess_file_syntax($highlight , $mimetype , $file_name );
7063
7098
$fd = run_highlighter($fd , $highlight , $syntax )
7064
7099
if $syntax ;
@@ -7106,6 +7141,72 @@ sub git_blob {
7106
7141
href(action => " blob_plain" , hash => $hash ,
7107
7142
hash_base => $hash_base , file_name => $file_name ) .
7108
7143
qq! " />\n ! ;
7144
+ } elsif ($highlight_js ) {
7145
+ my $ext = $file_name ;
7146
+ $ext =~ s / .*\. // ;
7147
+ print qq! <pre class="brush:! .$ext .qq! ">! ;
7148
+ while (my $line = <$fd >) {
7149
+ $line =~ s ! &! \& #38;! g ;
7150
+ $line =~ s ! <! \& #60;! g ;
7151
+ print $line ;
7152
+ }
7153
+ print qq! </pre>! ;
7154
+ foreach my $name (' Core' , ' Autoloader' ) {
7155
+ print qq! <script src="! .$highlight_js -> {url }
7156
+ .qq! /scripts/sh! .$name
7157
+ .qq! .js" type="text/javascript"></script>! ;
7158
+ }
7159
+ print qq! <script type="text/javascript">! ;
7160
+ print qq! SyntaxHighlighter.defaults["pad-line-numbers"] = 3;! ;
7161
+ print qq! SyntaxHighlighter.defaults["toolbar"] = false;! ;
7162
+ # for XHTML compliance
7163
+ print qq! SyntaxHighlighter.config["space"] = ' ';! ;
7164
+ print qq! SyntaxHighlighter.autoloader(! ;
7165
+ my $brush_prefix = $highlight_js -> {url } . ' /scripts/shBrush' ;
7166
+ foreach my $language (' applescript AppleScript' ,
7167
+ ' actionscript3 as3 AS3' ,
7168
+ ' bash shell Bash' ,
7169
+ ' clj Clojure' ,
7170
+ ' coldfusion cf ColdFusion' ,
7171
+ ' cpp c Cpp' ,
7172
+ ' c# c-sharp csharp CSharp' ,
7173
+ ' css Css' ,
7174
+ ' delphi pascal Delphi' ,
7175
+ ' diff patch pas Diff' ,
7176
+ ' erl erlang Erlang' ,
7177
+ ' groovy Groovy' ,
7178
+ ' java Java' ,
7179
+ ' jfx javafx JavaFX' ,
7180
+ ' js jscript javascript JScript' ,
7181
+ ' perl pl Perl' ,
7182
+ ' php Php' ,
7183
+ ' text plain Plain' ,
7184
+ ' py python Python' ,
7185
+ ' ruby rails ror rb Ruby' ,
7186
+ ' scala Scala' ,
7187
+ ' scm Scheme' ,
7188
+ ' sql Sql' ,
7189
+ ' vb vbnet Vb' ,
7190
+ ' xml xhtml xslt html Xml' ) {
7191
+ my $lang = $language ;
7192
+ $lang =~ s ! (\S +)$! $brush_prefix$1 ! ;
7193
+ print " '" .$lang .qq! .js',! ;
7194
+ }
7195
+ print qq! ''); SyntaxHighlighter.all();!
7196
+ .qq! function scrollTo(number) {!
7197
+ .qq! var elements = document.getElementsByClassName(number);!
7198
+ .qq! if (elements.length == 0) setTimeout('scrollTo("' + number + '");', 50);!
7199
+ .qq! else {!
7200
+ .qq! window.scroll(0, elements[0].offsetTop);!
7201
+ .qq! window.scrollTo(0, elements[0].offsetTop);!
7202
+ .qq! elements[0].style.color = '#ff0000';!
7203
+ .qq! }!
7204
+ .qq! }!
7205
+ .qq! var lineRegex = /#l(\\ d+)\$ /;!
7206
+ .qq! var lineNumber = lineRegex.exec(document.URL);!
7207
+ .qq! if (lineNumber)!
7208
+ .qq! scrollTo('number' + lineNumber[1]);!
7209
+ .qq! </script>! ;
7109
7210
} else {
7110
7211
my $nr ;
7111
7212
while (my $line = <$fd >) {
0 commit comments