MediaWiki REL1_30
SyntaxHighlight Class Reference
Collaboration diagram for SyntaxHighlight:

Static Public Member Functions

static buildHeadItem ( $geshi)
 Backward-compatibility shim for extensions.
 
static getPygmentizePath ()
 
static highlight ( $code, $lang=null, $args=[])
 Highlight a code-block using a particular lexer.
 
static onApiFormatHighlight (IContextSource $context, $text, $mime, $format)
 Hook to provide syntax highlighting for API pretty-printed output.
 
static onContentGetParserOutput (Content $content, Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
 Hook into Content::getParserOutput to provide syntax highlighting for script content.
 
static onParserFirstCallInit (Parser &$parser)
 Register parser hook.
 
static onResourceLoaderRegisterModules (&$resourceLoader)
 Conditionally register resource loader modules that depends on the VisualEditor MediaWiki extension.
 
static parserHook ( $text, $args=[], $parser)
 Parser hook.
 
static prepare ( $text, $lang)
 Backward-compatibility shim for extensions.
 

Static Protected Member Functions

static parseHighlightLines ( $lineSpec)
 Take an input specifying a list of lines to highlight, returning a raw list of matching line numbers.
 
static validHighlightRange ( $start, $end)
 Validate a provided input range.
 

Static Private Member Functions

static getLexer ( $lang)
 Get the Pygments lexer name for a particular language.
 
static makeCacheKey ( $code, $lexer, $options)
 Construct a cache key for the results of a Pygments invocation.
 

Static Private Attributes

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

Detailed Description

Definition at line 23 of file SyntaxHighlight.class.php.

Member Function Documentation

◆ buildHeadItem()

static SyntaxHighlight::buildHeadItem ( $geshi)
static

Backward-compatibility shim for extensions.

Deprecated
since MW 1.25
Parameters
GeSHi$geshi
Returns
string

Definition at line 547 of file SyntaxHighlight.class.php.

References wfDeprecated().

◆ 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 51 of file SyntaxHighlight.class.php.

References $lang, and SyntaxHighlightGeSHiCompat\getGeSHiToPygmentsMap().

Referenced by highlight().

◆ getPygmentizePath()

static SyntaxHighlight::getPygmentizePath ( )
static
Returns
string

Definition at line 185 of file SyntaxHighlight.class.php.

◆ highlight()

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

Highlight a code-block using a particular lexer.

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

References $args, $cache, $code, $lang, $lines, $options, $output, $pre, $type, getLexer(), highlight(), makeCacheKey(), parseHighlightLines(), and wfWarn().

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

◆ makeCacheKey()

static SyntaxHighlight::makeCacheKey ( $code,
$lexer,
$options )
staticprivate

Construct a cache key for the results of a Pygments invocation.

Parameters
string$codeCode to be highlighted.
string$lexerLexer name.
array$optionsOptions array.
Returns
string Cache key.

Definition at line 338 of file SyntaxHighlight.class.php.

References $options, and wfGlobalCacheKey().

Referenced by highlight().

◆ onApiFormatHighlight()

static SyntaxHighlight::onApiFormatHighlight ( IContextSource $context,
$text,
$mime,
$format )
static

Hook to provide syntax highlighting for API pretty-printed output.

Parameters
IContextSource$context
string$text
string$mime
string$format
Since
MW 1.24
Returns
bool

Definition at line 462 of file SyntaxHighlight.class.php.

References $context, $mime, $out, $output, and highlight().

◆ onContentGetParserOutput()

static SyntaxHighlight::onContentGetParserOutput ( Content $content,
Title $title,
$revId,
ParserOptions $options,
$generateHtml,
ParserOutput & $output )
static

Hook into Content::getParserOutput to provide syntax highlighting for script content.

Returns
bool
Since
MW 1.21

Definition at line 406 of file SyntaxHighlight.class.php.

References $options, $out, $output, $wgParser, $wgTextModelsToParse, ContentHandler\getContentText(), ExtensionRegistry\getInstance(), Content\getModel(), and highlight().

◆ onParserFirstCallInit()

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

Register parser hook.

Parameters
$parserParser

Definition at line 87 of file SyntaxHighlight.class.php.

References $parser.

◆ onResourceLoaderRegisterModules()

static SyntaxHighlight::onResourceLoaderRegisterModules ( & $resourceLoader)
static

Conditionally register resource loader modules that depends on the VisualEditor MediaWiki extension.

Parameters
ResourceLoader$resourceLoader

Definition at line 494 of file SyntaxHighlight.class.php.

References $resourceLoader, and ExtensionRegistry\getInstance().

◆ parseHighlightLines()

static SyntaxHighlight::parseHighlightLines ( $lineSpec)
staticprotected

Take an input specifying a list of lines to highlight, returning a raw list of matching line numbers.

Input is comma-separated list of lines or line ranges.

Parameters
string$lineSpec
Returns
int[] Line numbers.

Definition at line 357 of file SyntaxHighlight.class.php.

References $lines, $value, and list.

Referenced by highlight().

◆ parserHook()

static SyntaxHighlight::parserHook ( $text,
$args = [],
$parser )
static

Parser hook.

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

Definition at line 102 of file SyntaxHighlight.class.php.

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

◆ prepare()

static SyntaxHighlight::prepare ( $text,
$lang )
static

Backward-compatibility shim for extensions.

Deprecated
since MW 1.25

Definition at line 536 of file SyntaxHighlight.class.php.

References $lang, and wfDeprecated().

◆ validHighlightRange()

static SyntaxHighlight::validHighlightRange ( $start,
$end )
staticprotected

Validate a provided input range.

Parameters
$start
$end
Returns
bool

Definition at line 385 of file SyntaxHighlight.class.php.

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


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