ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  protected static $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  protected static $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  return self::$v51_map[$a_old_lang_id];
106  }
107  return $a_old_lang_id;
108  }
109 
110 
117  public static function getSupportedLanguagesV51()
118  {
119  $langs = array();
120  $map = array_flip(self::$v51_map);
121  foreach (self::$langs as $k => $v) {
122  if (isset($map[$k])) {
123  $k = $map[$k];
124  }
125  $langs[$k] = $v;
126  }
127  return $langs;
128  }
129 
136  public function highlight($a_code)
137  {
138  include_once("./libs/composer/vendor/geshi/geshi/src/geshi.php");
139  $geshi = new Geshi(html_entity_decode($a_code), $this->lang);
140 
141  //var_dump($geshi->get_supported_languages()); exit;
142 
143  //$geshi->set_header_type(GESHI_HEADER_NONE); // does not work as expected, see below
144  $a_code = $geshi->parse_code();
145 
146  // remove geshi pre tag (setting GESHI_HEADER_NONE gives us undesired br tags)
147  $a_code = substr($a_code, strpos($a_code, ">") + 1);
148  $a_code = substr($a_code, 0, strrpos($a_code, "<"));
149 
150  return $a_code;
151  }
152 }
static getNewLanguageId($a_old_lang_id)
Get new language id (for an old one)
PHP
Definition: index.php:3
Syntax highlighter wrapper class.
highlight($a_code)
Highlight code.
static getSupportedLanguages()
Get supported languages (keys are internal values, values are for representation) ...
Create styles array
The data for the language used.
static getSupportedLanguagesV51()
Get supported languages (keys are ILIAS <= 5.1 internal values, values are for representation) ...
static isSupported($a_lang)
Is language supported?
static getInstance($a_lang)
Get instance.
__construct($a_lang)
Constructor.