Copied!
  • api
  • since 7.5.0.0
CloneableInstantiable
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 \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 \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 \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 \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<string,string> 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<string,\Language> A mapping of a language ID to a Language definition
private $codeToHighlight = NULL
 
  • var string The current code we are highlighting
private $continuations = []
 
  • var array<string,\Mode>
private $ignoreIllegals = false
 
  • var bool
private $language = NULL
 
  • var \Language|null
private static $languages = ['php']
 
  • var string[] A list of registered language IDs
private $lastMatch = NULL
 
  • var \RegExMatch
private $modeBuffer = ''
 
  • var string
private $options = NULL
 
  • var array<string,mixed>
private $relevance = 0
 
  • var int
private $result = ''
 
  • var string
private $safeMode = true
 
  • var bool
private $top = NULL
 
  • var \Mode|null
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)
 
  • param \RegExMatch $match
  • return int
private doEndMatch( $match)
 
  • param \RegExMatch $match
  • return int|null
private endOfMode( $mode, $lexeme)
 
  • param \Mode $mode
  • param string $lexeme
  • return \Mode|null
private escape( $value)
 
  • param string $value
  • return string
private escapeRe( $value)
 
  • param string $value
  • return \RegEx
private getLanguage( $name)
 
  • param string $name
  • return \Language|null
private keywordMatch( $mode, $match)
 
  • param \Mode $mode
  • param \RegExMatch $match
  • return mixed|null
private processBuffer()
 
  • return void
private processKeywords()
 
  • return string
private processLexeme( $textBeforeMatch, $match = NULL)
 
  • param string $textBeforeMatch
  • param \RegExMatch|null $match
  • return int
private processSubLanguage()
 
  • return string
private replaceTabs( $code)
 

Replace tabs for something more usable.

  • param string $code
  • return string
private startNewMode( $mode)
 
  • param \Mode $mode
  • return void
private testRe( $re, $lexeme)
 
  • param \RegEx|null $re
  • param string $lexeme
  • return bool
Properties
private static $aliases = ['php' => 'php', 'php3' => 'php', 'php4' => 'php', 'php5' => 'php', 'php6' => 'php', 'php7' => 'php']
 
  • var array<string,string> 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<string,\Language> 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 \Language The object containing the definition for a language's markup
© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration