ILIAS  release_8 Revision v8.24
class.ilSyntaxHighlighter.php
Go to the documentation of this file.
1<?php
2
25{
26 public const JAVA = "java";
27 public const PHP = "php";
28 public const C = "c";
29 public const CPP = "cpp";
30 public const HTML = "html4strict";
31 public const XML = "xml";
32 public const VISUAL_BASIC = "vb";
33 public const LATEX = "latex";
34 public const DELPHI = "delphi";
35
39 protected static array $langs = array(
40 self::JAVA => "Java",
41 self::PHP => "PHP",
42 self::C => "C",
43 self::CPP => "C++",
44 self::HTML => "HTML",
45 self::XML => "XML",
46 self::VISUAL_BASIC => "Visual Basic",
47 self::DELPHI => "Delphi"
48 );
49
53 protected static array $v51_map = array(
54 "php3" => "php",
55 "java122" => "java",
56 "html" => "html4strict"
57 );
58
59 protected string $lang;
60
61 protected function __construct(string $a_lang)
62 {
63 $this->lang = $a_lang;
64 }
65
66 public static function getInstance(string $a_lang): self
67 {
68 return new self($a_lang);
69 }
70
75 public static function getSupportedLanguages(): array
76 {
77 return self::$langs;
78 }
79
83 public static function isSupported(string $a_lang): bool
84 {
85 return isset(self::$langs[$a_lang]);
86 }
87
91 public static function getNewLanguageId(string $a_old_lang_id): string
92 {
93 return self::$v51_map[$a_old_lang_id] ?? $a_old_lang_id;
94 }
95
96
100 public static function getSupportedLanguagesV51(): array
101 {
102 $langs = array();
103 $map = array_flip(self::$v51_map);
104 foreach (self::$langs as $k => $v) {
105 if (isset($map[$k])) {
106 $k = $map[$k];
107 }
108 $langs[$k] = $v;
109 }
110 return $langs;
111 }
112
113 public function highlight(string $a_code): string
114 {
115 include_once("./libs/composer/vendor/geshi/geshi/src/geshi.php");
116 $geshi = new Geshi(html_entity_decode($a_code), $this->lang);
117
118 //var_dump($geshi->get_supported_languages()); exit;
119
120 //$geshi->set_header_type(GESHI_HEADER_NONE); // does not work as expected, see below
121 $a_code = $geshi->parse_code();
122
123 // remove geshi pre tag (setting GESHI_HEADER_NONE gives us undesired br tags)
124 $a_code = substr($a_code, strpos($a_code, ">") + 1);
125 $a_code = substr($a_code, 0, strrpos($a_code, "<"));
126
127 return $a_code;
128 }
129}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNewLanguageId(string $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)
static isSupported(string $a_lang)
Is language supported?
static getInstance(string $a_lang)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
PHP
Definition: index.php:3