MediaWiki REL1_33
SyntaxHighlight Class Reference

Static Public Member Functions

static getPygmentizePath ()
 
static highlight ( $code, $lang=null, $args=[])
 Highlight a code-block using a particular lexer.
 
static onParserFirstCallInit (Parser &$parser)
 Register parser hook.
 
static parserHook ( $text, $args, $parser)
 Parser hook.
 

Static Private Member Functions

static getLexer ( $lang)
 Get the Pygments lexer name for a particular language.
 
static plainCodeWrap ( $code, $inline)
 

Static Private Attributes

static array $mimeLexers
 Mapping of MIME-types to lexer names.
 

Detailed Description

Definition at line 21 of file SyntaxHighlight.php.

Member Function Documentation

◆ getLexer()

static SyntaxHighlight::getLexer ( $lang)
staticprivate

Get the Pygments lexer name for a particular language.

Parameters
string$langLanguage name.
Returns
string|null Lexer name, or null if no matching lexer.

Definition at line 48 of file SyntaxHighlight.php.

References $lang, and(), and SyntaxHighlightGeSHiCompat\getGeSHiToPygmentsMap().

Referenced by highlight().

◆ getPygmentizePath()

static SyntaxHighlight::getPygmentizePath ( )
static
Returns
string

Definition at line 177 of file SyntaxHighlight.php.

References and().

Referenced by UpdateCSS\execute(), and UpdateLexerList\execute().

◆ highlight()

static SyntaxHighlight::highlight ( $code,
$lang = null,
$args = [] )
static

Highlight a code-block using a particular lexer.

This produces raw HTML (wrapped by Status), the caller is responsible for making sure the "ext.pygments" module is loaded in the output.

Parameters
string$codeCode to highlight.
string | null$langLanguage name, or null to use plain markup.
array$argsAssociative array of additional arguments. If it contains a 'line' key, the output will include line numbers. If it includes a 'highlight' key, the value will be parsed as a comma-separated list of lines and line-ranges to highlight. If it contains a 'start' key, the value will be used as the line at which to start highlighting. If it contains a 'inline' key, the output will not be wrapped in <div><pre/></div>.
Returns
Status Status object, with HTML representing the highlighted code as its value.

Definition at line 222 of file SyntaxHighlight.php.

References $args, $cache, $code, $lang, $lines, $options, $output, and(), function, getLexer(), parseHighlightLines(), plainCodeWrap(), and wfWarn().

Referenced by onApiFormatHighlight(), onContentGetParserOutput(), and parserHook().

◆ onParserFirstCallInit()

static SyntaxHighlight::onParserFirstCallInit ( Parser & $parser)
static

Register parser hook.

Parameters
Parser&$parser

Definition at line 84 of file SyntaxHighlight.php.

References $parser.

◆ parserHook()

static SyntaxHighlight::parserHook ( $text,
$args,
$parser )
static

Parser hook.

Parameters
string$text
array$args
Parser$parser
Returns
string
Exceptions
MWException

Definition at line 99 of file SyntaxHighlight.php.

References $args, $out, $parser, and(), and highlight().

◆ plainCodeWrap()

static SyntaxHighlight::plainCodeWrap ( $code,
$inline )
staticprivate
Parameters
string$code
bool$inline

Definition at line 192 of file SyntaxHighlight.php.

References $code, and and().

Referenced by highlight().

Member Data Documentation

◆ $mimeLexers

array SyntaxHighlight::$mimeLexers
staticprivate
Initial value:
= [
'text/javascript' => 'javascript',
'application/json' => 'javascript',
'text/xml' => 'xml',
]

Mapping of MIME-types to lexer names.

Definition at line 36 of file SyntaxHighlight.php.


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