[dokuwiki] Using GeSHi language definition colors instead of fixed colors for all languages

  • From: "D.Hendriks (Dennis)" <D.Hendriks@xxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Fri, 13 Mar 2009 12:55:38 +0100

Hello,

In GeSHi language definition files (.php files), one specifies STYLES. While
DokuWiki uses GeSHi for syntax highlighting, it uses its own coloring scheme.
This coloring scheme is the same for all languages.

Using GeSHi, you can ask GeSHi to output css code with the coloring for the
specific language. I created a very small patch for DokuWiki 2009-02-14,
which makes sure that the colors specified in the language definition are
used. The patch may not account for every situation, but it illustrates the
main idea.

I did test it on our wiki (http://se.wtb.tue.nl/sewiki/cif/start#example_cif_model),
for a code block with the 'cif' language, which is a language for which I
added a custom cif.php language definition. I also updated geshi.php and
the geshi directory with all the language .php files to 1.0.8.2 instead of
the 1.0.8 that ships with DokuWiki 2009-02-14.

This is the patch:

--- inc/parserutils.php    2009-02-14 13:13:25.000000000 +0100
+++ inc/parserutils_changed.php    2009-03-13 10:59:56.000000000 +0100
@@ -658,6 +658,10 @@
    // remove GeSHi's wrapper element (we'll replace it with our own later)
// we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text $highlighted_code = preg_replace('!^<pre[^>]*>|</pre>$!','',$geshi->parse_code());
+
+ $style_code = '<style type="text/css"><!--' . $geshi->get_stylesheet(true) . '--></style>';
+    $highlighted_code = $style_code . $highlighted_code;
+
    io_saveFile($cache,$highlighted_code);
  }

Maybe it would be nice to include this kind of styling of coding. Maybe you
don't want it to be the default. In that case you could add it as an optional
setting to DokuWiki. Let me know what you think. Thanks.

Dennis
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: