ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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"
 
const PYTHON = "python"
 
const CSS = "css"
 
const JAVASCRIPT = "javascript"
 
const SQL = "sql"
 
const BASH = "bash"
 
const POWERSHELL = "powershell"
 

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
Deprecated:
10

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

Constructor & Destructor Documentation

◆ __construct()

ilSyntaxHighlighter::__construct ( string  $a_lang)
protected

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

77  {
78  $this->lang = $a_lang;
79  }

Member Function Documentation

◆ getInstance()

static ilSyntaxHighlighter::getInstance ( string  $a_lang)
static

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

81  : self
82  {
83  return new self($a_lang);
84  }

◆ getNewLanguageId()

static ilSyntaxHighlighter::getNewLanguageId ( string  $a_old_lang_id)
static

Get new language id (for an old one)

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

106  : string
107  {
108  return self::$v51_map[$a_old_lang_id] ?? $a_old_lang_id;
109  }

◆ getSupportedLanguages()

static ilSyntaxHighlighter::getSupportedLanguages ( )
static

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

Returns
string[]

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

90  : array
91  {
92  return self::$langs;
93  }

◆ getSupportedLanguagesV51()

static ilSyntaxHighlighter::getSupportedLanguagesV51 ( )
static

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

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

References $langs.

Referenced by ilPCSourceCodeGUI\getProgLangOptions().

115  : array
116  {
117  $langs = array();
118  $map = array_flip(self::$v51_map);
119  foreach (self::$langs as $k => $v) {
120  if (isset($map[$k])) {
121  $k = $map[$k];
122  }
123  $langs[$k] = $v;
124  }
125  return $langs;
126  }
+ Here is the caller graph for this function:

◆ highlight()

ilSyntaxHighlighter::highlight ( string  $a_code)

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

128  : string
129  {
130  include_once("./vendor/composer/vendor/geshi/geshi/src/geshi.php");
131  $geshi = new Geshi(html_entity_decode($a_code), $this->lang);
132 
133  //var_dump($geshi->get_supported_languages()); exit;
134 
135  //$geshi->set_header_type(GESHI_HEADER_NONE); // does not work as expected, see below
136  $a_code = $geshi->parse_code();
137 
138  // remove geshi pre tag (setting GESHI_HEADER_NONE gives us undesired br tags)
139  $a_code = substr($a_code, strpos($a_code, ">") + 1);
140  $a_code = substr($a_code, 0, strrpos($a_code, "<"));
141 
142  return $a_code;
143  }

◆ isSupported()

static ilSyntaxHighlighter::isSupported ( string  $a_lang)
static

Is language supported?

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

98  : bool
99  {
100  return isset(self::$langs[$a_lang]);
101  }

Field Documentation

◆ $lang

string ilSyntaxHighlighter::$lang
protected

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

◆ $langs

array ilSyntaxHighlighter::$langs
staticprotected
Initial value:
= array(
self::BASH => "Bash",
self::C => "C",
self::CPP => "C++",
self::CSS => "CSS",
self::DELPHI => "Delphi",
self::HTML => "HTML",
self::JAVA => "Java",
self::JAVASCRIPT => "Javascript",
self::LATEX => "LaTeX",
self::PHP => "PHP",
self::POWERSHELL => "Powershell",
self::PYTHON => "Python",
self::SQL => "SQL",
self::VISUAL_BASIC => "Visual Basic",
self::XML => "XML"
)

Definition at line 47 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 68 of file class.ilSyntaxHighlighter.php.

◆ BASH

const ilSyntaxHighlighter::BASH = "bash"

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

◆ C

const ilSyntaxHighlighter::C = "c"

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

◆ CPP

const ilSyntaxHighlighter::CPP = "cpp"

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

◆ CSS

const ilSyntaxHighlighter::CSS = "css"

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

◆ DELPHI

const ilSyntaxHighlighter::DELPHI = "delphi"

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

◆ HTML

const ilSyntaxHighlighter::HTML = "html4strict"

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

◆ JAVA

const ilSyntaxHighlighter::JAVA = "java"

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

◆ JAVASCRIPT

const ilSyntaxHighlighter::JAVASCRIPT = "javascript"

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

◆ LATEX

const ilSyntaxHighlighter::LATEX = "latex"

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

◆ PHP

const ilSyntaxHighlighter::PHP = "php"

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

◆ POWERSHELL

const ilSyntaxHighlighter::POWERSHELL = "powershell"

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

◆ PYTHON

const ilSyntaxHighlighter::PYTHON = "python"

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

◆ SQL

const ilSyntaxHighlighter::SQL = "sql"

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

◆ VISUAL_BASIC

const ilSyntaxHighlighter::VISUAL_BASIC = "vb"

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

◆ XML

const ilSyntaxHighlighter::XML = "xml"

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


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