ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSyntaxHighlighter.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
14 const JAVA = "java";
15 const PHP = "php";
16 const C = "c";
17 const CPP = "cpp";
18 const HTML = "html4strict";
19 const XML = "xml";
20 const VISUAL_BASIC = "vb";
21 const LATEX = "latex";
22 const DELPHI = "delphi";
23
27 static protected $langs = array (
28 self::JAVA => "Java",
29 self::PHP => "PHP",
30 self::C => "C",
31 self::CPP => "C++",
32 self::HTML => "HTML",
33 self::XML => "XML",
34 self::VISUAL_BASIC => "Visual Basic",
35 self::DELPHI => "Delphi"
36 );
37
41 static protected $v51_map = array(
42 "php3" => "php",
43 "java122" => "java",
44 "html" => "html4strict"
45 );
46
50 protected $lang;
51
58 protected function __construct($a_lang)
59 {
60 $this->lang = $a_lang;
61 }
62
69 public static function getInstance($a_lang)
70 {
71 return new self($a_lang);
72 }
73
80 public static function getSupportedLanguages()
81 {
82 return self::$langs;
83 }
84
91 public static function isSupported($a_lang)
92 {
93 return isset(self::$langs[$a_lang]);
94 }
95
102 public static function getNewLanguageId($a_old_lang_id)
103 {
104 if (isset(self::$v51_map[$a_old_lang_id]))
105 {
106 return self::$v51_map[$a_old_lang_id];
107 }
108 return $a_old_lang_id;
109 }
110
111
118 public static function getSupportedLanguagesV51()
119 {
120 $langs = array();
121 $map = array_flip(self::$v51_map);
122 foreach (self::$langs as $k => $v)
123 {
124 if (isset($map[$k]))
125 {
126 $k = $map[$k];
127 }
128 $langs[$k] = $v;
129 }
130 return $langs;
131 }
132
139 public function highlight($a_code)
140 {
141 include_once("./libs/composer/vendor/geshi/geshi/src/geshi.php");
142 $geshi = new Geshi(html_entity_decode($a_code), $this->lang);
143
144 //var_dump($geshi->get_supported_languages()); exit;
145
146 //$geshi->set_header_type(GESHI_HEADER_NONE); // does not work as expected, see below
147 $a_code = $geshi->parse_code();
148
149 // remove geshi pre tag (setting GESHI_HEADER_NONE gives us undesired br tags)
150 $a_code = substr($a_code, strpos($a_code, ">") + 1);
151 $a_code = substr($a_code, 0, strrpos($a_code, "<"));
152
153 return $a_code;
154 }
155
156
157}
158
159?>
if(strncmp( $real_path, SOURCE_ROOT, $base_path_len)) if(!file_exists($path)) $geshi
Definition: aliased.php:40
An exception for terminatinating execution or to throw for unit testing.
Syntax highlighter wrapper class.
__construct($a_lang)
Constructor.
static isSupported($a_lang)
Is language supported?
static getInstance($a_lang)
Get instance.
static getNewLanguageId($a_old_lang_id)
Get new language id (for an old one)
static getSupportedLanguagesV51()
Get supported languages (keys are ILIAS <= 5.1 internal values, values are for representation)
static getSupportedLanguages()
Get supported languages (keys are internal values, values are for representation)
highlight($a_code)
Highlight code.