ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSyntaxHighlighter Class Reference

Syntax highlighter wrapper class. More...

+ Collaboration diagram for ilSyntaxHighlighter:

Public Member Functions

 highlight ($a_code)
 Highlight code. More...
 

Static Public Member Functions

static getInstance ($a_lang)
 Get instance. More...
 
static getSupportedLanguages ()
 Get supported languages (keys are internal values, values are for representation) More...
 
static isSupported ($a_lang)
 Is language supported? More...
 
static getNewLanguageId ($a_old_lang_id)
 Get new language id (for an old one) More...
 
static getSupportedLanguagesV51 ()
 Get supported languages (keys are ILIAS <= 5.1 internal values, values are for representation) More...
 

Data Fields

const JAVA = "java"
 
const PHP = "php"
 
const C = "c"
 
const CPP = "cpp"
 
const HTML = "html4strict"
 
const XML = "xml"
 
const VISUAL_BASIC = "vb"
 
const LATEX = "latex"
 
const DELPHI = "delphi"
 

Protected Member Functions

 __construct ($a_lang)
 Constructor. More...
 

Protected Attributes

 $lang
 

Static Protected Attributes

static $langs
 
static $v51_map
 

Detailed Description

Syntax highlighter wrapper class.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilSyntaxHighlighter.php.

Constructor & Destructor Documentation

◆ __construct()

ilSyntaxHighlighter::__construct (   $a_lang)
protected

Constructor.

Parameters
string$a_langlanguage constant
Returns
ilSyntaxHighlighter

Definition at line 58 of file class.ilSyntaxHighlighter.php.

59 {
60 $this->lang = $a_lang;
61 }

Member Function Documentation

◆ getInstance()

static ilSyntaxHighlighter::getInstance (   $a_lang)
static

Get instance.

Parameters
string$a_langlanguage constant
Returns
ilSyntaxHighlighter

Definition at line 69 of file class.ilSyntaxHighlighter.php.

70 {
71 return new self($a_lang);
72 }

Referenced by ilPCSourceCode\highlightText().

+ Here is the caller graph for this function:

◆ getNewLanguageId()

static ilSyntaxHighlighter::getNewLanguageId (   $a_old_lang_id)
static

Get new language id (for an old one)

Parameters
string$a_old_lang_id
Returns
string

Definition at line 102 of file class.ilSyntaxHighlighter.php.

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 }

Referenced by ilPCSourceCode\highlightText().

+ Here is the caller graph for this function:

◆ getSupportedLanguages()

static ilSyntaxHighlighter::getSupportedLanguages ( )
static

Get supported languages (keys are internal values, values are for representation)

Parameters

return string[]

Definition at line 80 of file class.ilSyntaxHighlighter.php.

81 {
82 return self::$langs;
83 }

References $langs.

◆ getSupportedLanguagesV51()

static ilSyntaxHighlighter::getSupportedLanguagesV51 ( )
static

Get supported languages (keys are ILIAS <= 5.1 internal values, values are for representation)

Parameters

return string[]

Definition at line 118 of file class.ilSyntaxHighlighter.php.

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 }

References $langs.

Referenced by ilPCSourceCodeGUI\getProgLangOptions().

+ Here is the caller graph for this function:

◆ highlight()

ilSyntaxHighlighter::highlight (   $a_code)

Highlight code.

Parameters
string$a_code
Returns
string highlighted code

Definition at line 139 of file class.ilSyntaxHighlighter.php.

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 }
if(strncmp( $real_path, SOURCE_ROOT, $base_path_len)) if(!file_exists($path)) $geshi
Definition: aliased.php:40

References $geshi.

◆ isSupported()

static ilSyntaxHighlighter::isSupported (   $a_lang)
static

Is language supported?

Parameters
string$a_lang
Returns
bool

Definition at line 91 of file class.ilSyntaxHighlighter.php.

92 {
93 return isset(self::$langs[$a_lang]);
94 }

Referenced by ilPCSourceCode\highlightText().

+ Here is the caller graph for this function:

Field Documentation

◆ $lang

ilSyntaxHighlighter::$lang
protected

Definition at line 50 of file class.ilSyntaxHighlighter.php.

◆ $langs

ilSyntaxHighlighter::$langs
staticprotected
Initial value:
= array (
self::JAVA => "Java",
self::PHP => "PHP",
self::C => "C",
self::CPP => "C++",
self::HTML => "HTML",
self::XML => "XML",
self::VISUAL_BASIC => "Visual Basic",
self::DELPHI => "Delphi"
)

Definition at line 27 of file class.ilSyntaxHighlighter.php.

Referenced by getSupportedLanguages(), and getSupportedLanguagesV51().

◆ $v51_map

ilSyntaxHighlighter::$v51_map
staticprotected
Initial value:
= array(
"php3" => "php",
"java122" => "java",
"html" => "html4strict"
)

Definition at line 41 of file class.ilSyntaxHighlighter.php.

◆ C

const ilSyntaxHighlighter::C = "c"

Definition at line 16 of file class.ilSyntaxHighlighter.php.

◆ CPP

const ilSyntaxHighlighter::CPP = "cpp"

Definition at line 17 of file class.ilSyntaxHighlighter.php.

◆ DELPHI

const ilSyntaxHighlighter::DELPHI = "delphi"

Definition at line 22 of file class.ilSyntaxHighlighter.php.

◆ HTML

const ilSyntaxHighlighter::HTML = "html4strict"

Definition at line 18 of file class.ilSyntaxHighlighter.php.

◆ JAVA

const ilSyntaxHighlighter::JAVA = "java"

Definition at line 14 of file class.ilSyntaxHighlighter.php.

◆ LATEX

const ilSyntaxHighlighter::LATEX = "latex"

Definition at line 21 of file class.ilSyntaxHighlighter.php.

◆ PHP

const ilSyntaxHighlighter::PHP = "php"

Definition at line 15 of file class.ilSyntaxHighlighter.php.

◆ VISUAL_BASIC

const ilSyntaxHighlighter::VISUAL_BASIC = "vb"

Definition at line 20 of file class.ilSyntaxHighlighter.php.

◆ XML

const ilSyntaxHighlighter::XML = "xml"

Definition at line 19 of file class.ilSyntaxHighlighter.php.


The documentation for this class was generated from the following file: