Changes To Cookbook
Not logged in

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

289
290
291
292
293
294
295


296


297
298

























































289
290
291
292
293
294
295
296
297
298
299
300


301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357







+
+

+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
  background: #558195;
  font-size: 1.5em;
  color: #ffffff;
}
</pre>
</nowiki>
<h2><a name="source-hilight">Source highlighting</a></h2>
<h3>Motivation</h3>
  *  You want to have source code highlighting for the files in your repository

<h3>Problem</h3>
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.
Found this link in the mailing list:
[http://ilia.org.il/fossil/source_highlight.html|Source highlighting]

However to have a source code highlighting in the presented web pages would still be desirable.

<h3>Solution</h3>
There are two scenarios how to implement such a feature:
   *  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.
   *  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>

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 only all the time.

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.
<p>
<b>Header</b>
<pre>
&lt;html&gt;
 &lt;head&gt;
 &lt;title&gt;$&lt;project_name&gt;: $&lt;title&gt;&lt;/title&gt;
 &lt;link rel="alternate" type="application/rss+xml" title="RSS Feed"
       href="$baseurl/timeline.rss"&gt;
 &lt;link rel="stylesheet" href="$baseurl/style.css" type="text/css"
       media="screen"&gt;
 &lt;link rel="stylesheet" href="$baseurl/doc/tip/www/SyntaxHighlighter.css" type="text/css"
       media="screen"&gt;
 &lt;/head&gt;

. . .
</pre>
</p><p>
<b>Footer</b>
<pre>
&lt;/div&gt;
&lt;div class="footer"&gt;
Fossil version $manifest_version $manifest_date
&gt;/div&gt;
&lt;script language="javascript" src="$baseurl/doc/tip/www/scripts/shCore.js"&gt;&lt;/script&gt;
&lt;script language="javascript" src="$baseurl/doc/tip/www/scripts/shBrushCpp.js"&gt;&lt;/script&gt;
&lt;script language="javascript"&gt;
dp.SyntaxHighlighter.ClipboardSwf = '$baseurl/doc/tip/www/scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
&lt;/script&gt;
&lt;/body&gt;&lt;/html&gt;
</pre>
</p><p>
<b>Fossil/src/info.c</b> function artifact_page
<pre>
if( zMime==0 ){
    @ &lt;pre name="code" class="c"&gt;
    @ %h(blob_str(&content))
    @ &lt;/pre&gt;
</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.