ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSyntaxHighlighter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilSyntaxHighlighter:

Public Member Functions

 highlight (string $a_code)
 

Static Public Member Functions

static getInstance (string $a_lang)
 
static getSupportedLanguages ()
 Get supported languages (keys are internal values, values are for representation) More...
 
static isSupported (string $a_lang)
 Is language supported? More...
 
static getNewLanguageId (string $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 (string $a_lang)
 

Protected Attributes

string $lang
 

Static Protected Attributes

static array $langs
 
static array $v51_map
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Syntax highlighter wrapper class

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilSyntaxHighlighter::__construct ( string  $a_lang)
protected

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

62  {
63  $this->lang = $a_lang;
64  }

Member Function Documentation

◆ getInstance()

static ilSyntaxHighlighter::getInstance ( string  $a_lang)
static

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

Referenced by ilPCSourceCode\highlightText().

66  : self
67  {
68  return new self($a_lang);
69  }
+ Here is the caller graph for this function:

◆ getNewLanguageId()

static ilSyntaxHighlighter::getNewLanguageId ( string  $a_old_lang_id)
static

Get new language id (for an old one)

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

Referenced by ilPCSourceCode\highlightText().

91  : string
92  {
93  return self::$v51_map[$a_old_lang_id] ?? $a_old_lang_id;
94  }
+ Here is the caller graph for this function:

◆ getSupportedLanguages()

static ilSyntaxHighlighter::getSupportedLanguages ( )
static

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

Returns
string[]

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

75  : array
76  {
77  return self::$langs;
78  }

◆ getSupportedLanguagesV51()

static ilSyntaxHighlighter::getSupportedLanguagesV51 ( )
static

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

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

References $langs.

Referenced by ilPCSourceCodeGUI\getProgLangOptions().

100  : 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  }
+ Here is the caller graph for this function:

◆ highlight()

ilSyntaxHighlighter::highlight ( string  $a_code)

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

113  : 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  }

◆ isSupported()

static ilSyntaxHighlighter::isSupported ( string  $a_lang)
static

Is language supported?

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

Referenced by ilPCSourceCode\highlightText().

83  : bool
84  {
85  return isset(self::$langs[$a_lang]);
86  }
+ Here is the caller graph for this function:

Field Documentation

◆ $lang

string ilSyntaxHighlighter::$lang
protected

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

◆ $langs

array 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 39 of file class.ilSyntaxHighlighter.php.

Referenced by getSupportedLanguagesV51().

◆ $v51_map

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

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

◆ C

const ilSyntaxHighlighter::C = "c"

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

◆ CPP

const ilSyntaxHighlighter::CPP = "cpp"

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

◆ DELPHI

const ilSyntaxHighlighter::DELPHI = "delphi"

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

◆ HTML

const ilSyntaxHighlighter::HTML = "html4strict"

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

◆ JAVA

const ilSyntaxHighlighter::JAVA = "java"

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

◆ LATEX

const ilSyntaxHighlighter::LATEX = "latex"

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

◆ PHP

const ilSyntaxHighlighter::PHP = "php"

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

◆ VISUAL_BASIC

const ilSyntaxHighlighter::VISUAL_BASIC = "vb"

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

◆ XML

const ilSyntaxHighlighter::XML = "xml"

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


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