1a79e16d8790411cc232141388eae2a8a9ae3929
[phorkie.git] / src / phorkie / Renderer / Geshi.php
1 <?php
2 namespace phorkie;
3
4 class Renderer_Geshi
5 {
6     /**
7      * Converts the code to HTML
8      *
9      * @param File $file File to render
10      *
11      * @return string HTML
12      */
13     public function toHtml(File $file)
14     {
15         /**
16          * Yes, geshi needs to be in your include path
17          * We use the mediawiki geshi extension package.
18          */
19         require_once 'MediaWiki/geshi/geshi/geshi.php';
20         $geshi = new \GeSHi($file->getContent(), $this->getType($file));
21         $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
22         $geshi->set_header_type(GESHI_HEADER_DIV);
23         return $geshi->parse_code();
24     }
25
26     /**
27      * Returns the type of the file, as used by Geshi
28      *
29      * @return string
30      */
31     public function getType($file)
32     {
33         $ext = $file->getExt();
34         if (isset($GLOBALS['phorkie']['languages'][$ext]['geshi'])) {
35             $ext = $GLOBALS['phorkie']['languages'][$ext]['geshi'];
36         }
37
38         return $ext;
39     }
40
41 }
42
43 ?>