Copied!
  • api
  • since 7.5.0.0
Cloneable Instantiable
Constants
public Highlight\Highlighter ::SPAN_END_TAG = '</span>'
 
  • since 9.12.0.4
Methods
public __construct ( $loadAllLanguages = true )
 
  • param bool $loadAllLanguages If true, will automatically register all languages distributed with this library. If false, user must explicitly register languages by calling `registerLanguage()`.
  • since 9.18.1.4added `$loadAllLanguages` parameter
  • see \Highlighter::registerLanguage()
public static clearAllLanguages ()
 

Clear all registered languages.

  • since 9.18.1.4
  • return void
public disableSafeMode ()
 
  • since 9.17.1.0
  • return void
public enableSafeMode ()
 
  • since 9.17.1.0
  • return void
public getAliasesForLanguage ( $name )
 

Returns list of all available aliases for given language name.

  • param string $name name or alias of language to look-up
  • throws DomainException if the requested language was not in this Highlighter's language set
  • since 9.12.0.3
  • return string [] An array of all aliases associated with the requested language name language. Passed-in name is included as well.
public getClassPrefix ()
 

Get the class prefix string.

  • return string The class prefix string
public getTabReplace ()
 

Get the tab replacement string.

  • return string The tab replacement string
public highlight ( $languageName , $code , $ignoreIllegals = true , $continuation = NULL )
 

Core highlighting function. Accepts a language name, or an alias, and a
string with the code to highlight. Returns an object with the following
properties:

  • relevance (int)
  • value (an HTML string with highlighting markup).
  • todo In v10.x, change the return type from \stdClass to HighlightResult
  • param string $languageName
  • param string $code
  • param bool $ignoreIllegals
  • param Highlight\Mode | null $continuation
  • throws DomainException if the requested language was not in this Highlighter's language set
  • throws Exception if an invalid regex was given in a language file
  • return Highlight\HighlightResult | stdClass
public highlightAuto ( $code , $languageSubset = NULL )
 

Highlight the given code by highlighting the given code with each
registered language and then finding the match with highest accuracy.

  • param string $code
  • param string []| null $languageSubset When set to null, this method will attempt to highlight $text with each language. Set this to an array of languages of your choice to limit the amount of languages to try.
  • throws Exception if an invalid regex was given in a language file
  • throws DomainException if the attempted language to check does not exist
  • return Highlight\HighlightResult | stdClass
public static listBundledLanguages ()
 

Return a list of all available languages bundled with this library.

  • since 9.18.1.4
  • return string [] An array of language names
public static listRegisteredLanguages ( $includeAliases = false )
 

Return a list of all the registered languages. Using this list in
setAutodetectLanguages will turn on auto-detection for all supported
languages.

  • since 9.18.1.4
  • param bool $includeAliases Specify whether language aliases should be included as well
  • return string [] An array of language names
public static registerAllLanguages ()
 

Register all 185+ languages that are bundled in this library.

To register languages individually, use registerLanguage.

  • since 9.18.1.4Method is now public
  • since 8.3.0.0
  • see \Highlighter::registerLanguage
  • return void
public static registerLanguage ( $languageId , $filePath , $overwrite = false )
 

Register a language definition with the Highlighter's internal language
storage. Languages are stored in a static variable, so they'll be available
across all instances. You only need to register a language once.

  • param string $languageId The unique name of a language
  • param string $filePath The file path to the language definition
  • param bool $overwrite Overwrite language if it already exists
  • return Highlight\Language The object containing the definition for a language's markup
public setAutodetectLanguages ( array $set )
 

Set the languages that will used for auto-detection. When using auto-
detection the code to highlight will be probed for every language in this
set. Limiting this set to only the languages you want to use will greatly
improve highlighting speed.

  • param string [] $set An array of language games to use for autodetection. This defaults to a typical set Web development languages.
  • return void
public setClassPrefix ( $classPrefix )
 

Set the class prefix string.

  • param string $classPrefix The class prefix string
  • return void
public setTabReplace ( $tabReplace )
 

Set the tab replacement string. This defaults to NULL: no tabs
will be replaced.

  • param string $tabReplace The tab replacement string
  • return void
Properties
private static $aliases = [ 'php' => 'php' , 'php3' => 'php' , 'php4' => 'php' , 'php5' => 'php' , 'php6' => 'php' , 'php7' => 'php' ]
 
  • var array A mapping from alias (key) to main language ID (value)
private static $bundledLanguages
 
  • var string [] A list of all the bundled languages
private static $classMap = [ 'php' => Highlight\Language ]
 
  • var array A mapping of a language ID to a Language definition
private $codeToHighlight
 
  • var string The current code we are highlighting
private $continuations
 
  • var array
private $ignoreIllegals
 
  • var bool
private $language
 
private static $languages = [ 'php' ]
 
  • var string [] A list of registered language IDs
private $lastMatch
private $modeBuffer
 
  • var string
private $options
 
  • var array
private $relevance
 
  • var int
private $result
 
  • var string
private $safeMode
 
  • var bool
private $top
 
Methods
private autoDetection ( $name )
 

Determine whether or not a language definition supports auto detection.

  • param string $name Language name
  • return bool
private buildSpan ( $className , $insideSpan , $leaveOpen = false , $noPrefix = false )
 
  • param string $className
  • param string $insideSpan
  • param bool $leaveOpen
  • param bool $noPrefix
  • return string
private doBeginMatch ( $match )
 
private doEndMatch ( $match )
 
private endOfMode ( $mode , $lexeme )
 
private escape ( $value )
 
  • param string $value
  • return string
private escapeRe ( $value )
 
private getLanguage ( $name )
 
private keywordMatch ( $mode , $match )
 
private processBuffer ()
 
  • return void
private processKeywords ()
 
  • return string
private processLexeme ( $textBeforeMatch , $match = NULL )
 
private processSubLanguage ()
 
  • return string
private replaceTabs ( $code )
 

Replace tabs for something more usable.

  • param string $code
  • return string
private startNewMode ( $mode )
 
private testRe ( $re , $lexeme )
 
Properties
private static $aliases = [ 'php' => 'php' , 'php3' => 'php' , 'php4' => 'php' , 'php5' => 'php' , 'php6' => 'php' , 'php7' => 'php' ]
 
  • var array A mapping from alias (key) to main language ID (value)
private static $bundledLanguages
 
  • var string [] A list of all the bundled languages
private static $classMap = [ 'php' => Highlight\Language ]
 
  • var array A mapping of a language ID to a Language definition
private static $languages = [ 'php' ]
 
  • var string [] A list of registered language IDs
Methods
public static clearAllLanguages ()
 

Clear all registered languages.

  • since 9.18.1.4
  • return void
public static listBundledLanguages ()
 

Return a list of all available languages bundled with this library.

  • since 9.18.1.4
  • return string [] An array of language names
public static listRegisteredLanguages ( $includeAliases = false )
 

Return a list of all the registered languages. Using this list in
setAutodetectLanguages will turn on auto-detection for all supported
languages.

  • since 9.18.1.4
  • param bool $includeAliases Specify whether language aliases should be included as well
  • return string [] An array of language names
public static registerAllLanguages ()
 

Register all 185+ languages that are bundled in this library.

To register languages individually, use registerLanguage.

  • since 9.18.1.4Method is now public
  • since 8.3.0.0
  • see \Highlighter::registerLanguage
  • return void
public static registerLanguage ( $languageId , $filePath , $overwrite = false )
 

Register a language definition with the Highlighter's internal language
storage. Languages are stored in a static variable, so they'll be available
across all instances. You only need to register a language once.

  • param string $languageId The unique name of a language
  • param string $filePath The file path to the language definition
  • param bool $overwrite Overwrite language if it already exists
  • return Highlight\Language The object containing the definition for a language's markup
© 2021 Bruce Wells
Search Namespaces \ Classes
Configuration