468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
|
-
+
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
-
-
+
-
+
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
The main purpose of Fossil is to do versioning for source code. Although it provides a standalone server and lets you navigate through the repository files additional features like source code highlighting from my perspective (I am not a developer of Fossil) are out of scope for an SCM. Just keep the Unix principle: small little programs that do their task and do it well.
However to have source code highlighted in the presented web pages would still be desirable.
<h3>Solution</h3>
There are two scenarios how to implement such a feature:
* Fossil pipes the source code through a filter before sending it to the browser. The filter could be defined as a configuration option to Fossil. One solution for this might be the <a href="http://www.gnu.org/software/src-highlite">GNU Source code Highlighting</a> program.
* Use a Javascript library that renders the code within your browser. One solution for this might be <a href="http://code.google.com/p/syntaxhighlighter">Google Syntax Highlighter</a>
* Use a Javascript library that renders the code within your browser. One solution for this might be <a href="http://alexgorbatchev.com/SyntaxHighlighter">Alex Gorbatchev's Syntax Highlighter</a>
I estimate that the <i>pipe</i> solution needs some more work/ code changes. Thus I am solely looking at the Javascript solution.
The SyntaxHighlighter is a library of some Javascript files, a little Flash application and a CSS file. The Flash application is for copying to clipboard, print and view source. You have the option to include all the files into your repository or use the files hosted at Google. The latter may only be an option if you are connected to internet all the time.
The SyntaxHighlighter is a library of some Javascript files and a CSS file. You have the option to include all the files into your repository, put them on a server you have access to or use the files hosted at alexgorbatchev.com. The latter may only be an option if you are connected to internet all the time.
To add the syntax highlighting class to the <pre> element, you also need a copy of <a href="http://jquery.com/">jquery</a> in the SyntaxHighlighter directory.
For syntax highlighting to work the Header and Footer templates need to be modified and a little code change has to be applied to the Fossil sources.
The examples below assume you have added the syntax highlighting library to your repository into a directory www/scripts.
For syntax highlighting to work the Header and Footer templates need to be modified.
The examples below assume you have added the syntax highlighting library to your repository into a directory www/SyntaxHighlighter.
To make it easier to switch between the scripts beeing part of the repository and the scripts beeing hosted on the internet, the header template defines two TH1 variables:
* highlighterpath - used for all references to the actual location of the SyntaxHighlighter. Just set those variable to the basepath of SyntaxHighlighter and you're done. If you would like to use the hosted version at alexgorbatchev.com, replace <i>$baseurl/doc/tip/www/SyntaxHighlighter</i> with <i>http://alexgorbatchev.com/pub/sh/current</i>
* jquerypath - used to define the location of the used jquery script. If you want to use a hosted version, replace <i>$baseurl/doc/tip/www/SyntaxHighlighter/jquery-1.5.min.js</i> with <i>http://code.jquery.com/jquery-1.5.min.js</i> or one of the other URLs availble at the <a href="http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery">jquery download page</a>.
<p>
<b>Header</b>
<pre>
<html>
<head>
<th1>
set highlighterpath "$baseurl/doc/tip/www/SyntaxHighlighter"
set jquerypath "$baseurl/doc/tip/www/SyntaxHighlighter/jquery-1.5.min.js"
</th1>
<title>$<project_name>: $<title></title>
<link rel="alternate" type="application/rss+xml" title="RSS Feed"
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="$baseurl/timeline.rss">
href="$baseurl/timeline.rss">
<link rel="stylesheet" href="$baseurl/style.css" type="text/css"
<link rel="stylesheet" href="$baseurl/style.css" type="text/css" media="screen">
media="screen">
<link rel="stylesheet" href="$baseurl/doc/tip/www/SyntaxHighlighter.css" type="text/css"
<link rel="stylesheet" href="$highlighterpath/styles/shCoreDefault.css" type="text/css" media="screen" />
media="screen">
<script language="javascript" src="$jquerypath"></script>
</head>
. . .
</pre>
</p><p>
<b>Footer</b>
With version 3.x of SyntaxHighlighter it is possible to load the language specific scripts on demand. The footer template uses this feature to identify the programming language of the sourcefile by looking at the extension of the file and then adds the appropriate brush to the <pre> element. SyntaxHighlighter will then load only the brush needed to highlight the current page.
<pre>
</div>
<div class="footer">
Fossil version $manifest_version $manifest_date
</div>
<script language="javascript" src="$baseurl/doc/tip/www/scripts/shCore.js"></script>
<script language="javascript" src="$baseurl/doc/tip/www/scripts/shBrushCpp.js"></script>
<script language="javascript" src="$highlighterpath/scripts/shCore.js"></script>
<script language="javascript" src="$highlighterpath/scripts/shAutoloader.js"></script>
<script language="javascript">
function path()
{
var args = arguments, result = [];
for(var i = 0; i < args.length; i++)
result.push(args[i].replace('@', '$highlighterpath/scripts/'));
return result
};
// Do the highlighting only on artifact pages
if (document.getElementsByTagName("title")[0].innerHTML.indexOf("Artifact") != -1)
{
// try to find out the file type by looking at the file names extension
var file = document.getElementsByTagName("blockquote")[0].getElementsByTagName("a")[0].innerHTML;
var extPos = file.lastIndexOf(".");
var extension = "";
if (extPos != -1)
extension = file.substring(extPos + 1);
// set a default for extensions not recognized
var brush = "brush: text";
// check the extension to select the brush for highlighting
if (extension == "cs")
brush = "brush: c-sharp";
else if (extension == "vb")
brush = "brush: vb";
else if (extension == "xml" || extension == "xsd" || extension == "xslt" || extension == "aml" || extension == "shfbproj" || extension == "csproj")
brush = "brush: xml";
else if (extension == "cmd" || extension == "sh")
brush = "brush: shell";
else if (extension == "sql")
brush = "brush: sql";
else if (extension == "c" || extension == "cpp" || extension == "cxx" || extension == "cc" || extension == "h" || extension == "hpp")
brush = "brush: cpp";
else if (extension == "js")
brush = "brush: javascript";
else if (extension == "css")
brush = "brush: css";
else if (extension == "php")
brush = "brush: php";
else if (extension == "pl")
brush = "brush: perl";
else if (extension == "java")
brush = "brush: java";
else if (extension == "ruby" || extension == "rb" )
brush = "brush: ruby";
else if (extension == "py")
brush = "brush: python";
// disable the highlighter toolbar
brush = brush + "; toolbar: false;";
// Add the brush to the pre element which contains the source file
$("pre:last").addClass(brush);
// initialize SyntaxHighlighter's autoloader
dp.SyntaxHighlighter.ClipboardSwf = '$baseurl/doc/tip/www/scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
SyntaxHighlighter.autoloader.apply(null, path(
'applescript @shBrushAppleScript.js',
'actionscript3 as3 @shBrushAS3.js',
'bash shell @shBrushBash.js',
'coldfusion cf @shBrushColdFusion.js',
'cpp c @shBrushCpp.js',
'c# c-sharp csharp @shBrushCSharp.js',
'css @shBrushCss.js',
'delphi pascal @shBrushDelphi.js',
'diff patch pas @shBrushDiff.js',
'erl erlang @shBrushErlang.js',
'groovy @shBrushGroovy.js',
'java @shBrushJava.js',
'jfx javafx @shBrushJavaFX.js',
'js jscript javascript @shBrushJScript.js',
'perl pl @shBrushPerl.js',
'php @shBrushPhp.js',
'text plain @shBrushPlain.js',
'py python @shBrushPython.js',
'ruby rails ror rb @shBrushRuby.js',
'sass scss @shBrushSass.js',
'scala @shBrushScala.js',
'sql @shBrushSql.js',
'vb vbnet @shBrushVb.js',
'xml xhtml xslt html @shBrushXml.js'
));
// and finally highlight it
SyntaxHighlighter.all()
}
</script>
</body></html>
</pre>
</p><p>
<b>Fossil/src/info.c</b> function artifact_page
<pre>
if( zMime==0 ){
@ <pre name="code" class="c">
@ %h(blob_str(&content))
@ </pre>
</pre>
</p>
<p>
If you only expect one language to be highlighted on a page, then you can implement the above without changing the Fossil code. Just use JQuery in the header like this (this example is for Visual Basic):
<pre>
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
</pre>
and in the footer like this:
<pre>
<script>$("pre:last").addClass("brush: vb");</script>
<script>
$(document).ready(function() {SyntaxHighlighter.all()});
</script>
</pre>
</p>
<h3>Discussion</h3>
The Javascript solution requires a minimum to be fully supported by Fossil. Of course my litte change only applies for C/C++ files. But only little more work needs to be done to get the extension of the file a guess the file type.
The pipe solution would also be nice but would probably need some more work than this little patch.
<h2><a name="win32dev">How to prepare your Windows XP Fossil development Environment</a></h2>
<h4>MinGW+NSIS/WiX</h4>
<ul>
<li>Setup TCL</li>
<li>Setup MinGW</li>
<li>Getting NSIS Windows packaging tool </li>
<li>Getting Fossil source code</li>
|