ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

Referenced by ilPCSourceCode\highlightText().

70  {
71  return new self($a_lang);
72  }
+ 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.

Referenced by ilPCSourceCode\highlightText().

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  }
+ 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

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

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

◆ getSupportedLanguagesV51()

static ilSyntaxHighlighter::getSupportedLanguagesV51 ( )
static

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

Parameters

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

References $langs, and $map.

Referenced by ilPCSourceCodeGUI\getProgLangOptions().

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  }
+ 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 136 of file class.ilSyntaxHighlighter.php.

References $geshi.

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

◆ 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.

Referenced by ilPCSourceCode\highlightText().

92  {
93  return isset(self::$langs[$a_lang]);
94  }
+ 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 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: