Changes To Cookbook
Not logged in

Changes to "Cookbook" between 2009-01-13 21:00:07 and 2009-01-27 21:40:05

   289    289     background: #558195;
   290    290     font-size: 1.5em;
   291    291     color: #ffffff;
   292    292   }
   293    293   </pre>
   294    294   </nowiki>
   295    295   <h2><a name="source-hilight">Source highlighting</a></h2>
          296  +<h3>Motivation</h3>
          297  +  *  You want to have source code highlighting for the files in your repository
          298  +
          299  +<h3>Problem</h3>
          300  +The main purpose of Fossil is to do versioning the 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) is out of scope for an SCM. Just keep the Unix principle: small little programs that do their task and do it well.
          301  +
          302  +However to have a source code highlighting in the presented web pages would still be desirable.
          303  +
          304  +<h3>Solution</h3>
          305  +There are two scenarios how to implement such a feature:
          306  +   *  Pipe the source code through a filter that could be defined as a configuration option. One solutions for this might be the <a href="http://www.gnu.org/software/src-highlite">GNU Source code Highlighting</a> program.
          307  +   *  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>
          308  +
          309  +I estimate that the <i>pipe</i> solution needs some more work/ code changes. Thus I am solely looking at the Javascript solution.
          310  +
          311  +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 only all the time.
          312  +
          313  +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.
          314  +<p>
          315  +<b>Header</b>
          316  +<pre>
          317  +&lt;html&gt;
          318  + &lt;head&gt;
          319  + &lt;title&gt;$&lt;project_name&gt;: $&lt;title&gt;&lt;/title&gt;
          320  + &lt;link rel="alternate" type="application/rss+xml" title="RSS Feed"
          321  +       href="$baseurl/timeline.rss"&gt;
          322  + &lt;link rel="stylesheet" href="$baseurl/style.css" type="text/css"
          323  +       media="screen"&gt;
          324  + &lt;link rel="stylesheet" href="$baseurl/doc/tip/www/SyntaxHighlighter.css" type="text/css"
          325  +       media="screen"&gt;
          326  + &lt;/head&gt;
          327  +
          328  +. . .
          329  +</pre>
          330  +</p><p>
          331  +<b>Footer</b>
          332  +<pre>
          333  +&lt;/div&gt;
          334  +&lt;div class="footer"&gt;
          335  +Fossil version $manifest_version $manifest_date
          336  +&gt;/div&gt;
          337  +&lt;script language="javascript" src="$baseurl/doc/tip/www/scripts/shCore.js"&gt;&lt;/script&gt;
          338  +&lt;script language="javascript" src="$baseurl/doc/tip/www/scripts/shBrushCpp.js"&gt;&lt;/script&gt;
          339  +&lt;script language="javascript"&gt;
          340  +dp.SyntaxHighlighter.ClipboardSwf = '$baseurl/doc/tip/www/scripts/clipboard.swf';
          341  +dp.SyntaxHighlighter.HighlightAll('code');
          342  +&lt;/script&gt;
          343  +&lt;/body&gt;&lt;/html&gt;
          344  +</pre>
          345  +</p><p>
          346  +<b>Fossil/src/info.c</b> function artifact_page
          347  +<pre>
          348  +if( zMime==0 ){
          349  +    @ &lt;pre name="code" class="c"&gt;
          350  +    @ %h(blob_str(&content))
          351  +    @ &lt;/pre&gt;
          352  +</pre>
          353  +</p>
          354  +<h3>Discussion</h3>
          355  +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.
   296    356   
   297         -Found this link in the mailing list:
   298         -[http://ilia.org.il/fossil/source_highlight.html|Source highlighting]
          357  +The pipe solution would also be nice but would probably need some more work than this little patch.