MediaWiki  1.34.4
SyntaxHighlight Class Reference

Static Public Member Functions

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

Static Private Member Functions

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

Static Private Attributes

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

Detailed Description

Definition at line 22 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 49 of file SyntaxHighlight.php.

References $lang, and SyntaxHighlightGeSHiCompat\getGeSHiToPygmentsMap().

Referenced by highlight().

◆ getPygmentizePath()

static SyntaxHighlight::getPygmentizePath ( )
static
Returns
string

Definition at line 178 of file SyntaxHighlight.php.

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 223 of file SyntaxHighlight.php.

References $args, $cache, $lang, $lines, getLexer(), makeCacheKeyHash(), parseHighlightLines(), plainCodeWrap(), and wfWarn().

Referenced by ScribuntoContent\highlight(), onApiFormatHighlight(), onContentGetParserOutput(), and parserHook().

◆ onParserFirstCallInit()

static SyntaxHighlight::onParserFirstCallInit ( Parser $parser)
static

Register parser hook.

Parameters
Parser&$parser

Definition at line 85 of file SyntaxHighlight.php.

References Parser\setHook().

◆ parserHook()

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

Parser hook.

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

Definition at line 100 of file SyntaxHighlight.php.

References $args, Html\closeElement(), highlight(), Html\openElement(), Html\rawElement(), and Sanitizer\validateAttributes().

◆ plainCodeWrap()

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

Definition at line 193 of file SyntaxHighlight.php.

References Html\element(), and Html\rawElement().

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 37 of file SyntaxHighlight.php.


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