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