Highlight/Highlighter.php
public function highlightAuto($code, $languageSubset = null)
    {
        $res = new \stdClass();
        $res->relevance = 0;
        $res->value = $this->escape($code);
        $res->language = "";
        $scnd = clone $res;

        $tmp = $languageSubset ? $languageSubset : $this->autodetectSet;

        foreach ($tmp as $l) {
            // don't fail if we run into a non-existent language
            try {
                // skip any languages that don't support auto detection
                if (!$this->autoDetection($l)) {
                    continue;
                }

                $current = $this->highlight($l, $code, false);
            } catch (\DomainException $e) {
                continue;
            }

            if ($current->relevance > $scnd->relevance) {
                $scnd = $current;
            }
            if ($current->relevance > $res->relevance) {
                $scnd = $res;
                $res = $current;
            }
        }

        if ($scnd->language) {
            $res->secondBest = $scnd;
        }

        return $res;
    }
public function highlightAuto($code, $languageSubset = null)
    {
        $res = new \stdClass();
        $res->relevance = 0;
        $res->value = $this->escape($code);
        $res->language = "";
        $scnd = clone $res;

        $tmp = $languageSubset ? $languageSubset : $this->autodetectSet;

        foreach ($tmp as $l) {
            // don't fail if we run into a non-existent language
            try {
                // skip any languages that don't support auto detection
                if (!$this->autoDetection($l)) {
                    continue;
                }

                $current = $this->highlight($l, $code, false);
            } catch (\DomainException $e) {
                continue;
            }

            if ($current->relevance > $scnd->relevance) {
                $scnd = $current;
            }
            if ($current->relevance > $res->relevance) {
                $scnd = $res;
                $res = $current;
            }
        }

        if ($scnd->language) {
            $res->secondBest = $scnd;
        }

        return $res;
    }
public function highlightAuto ( $ code , $ languageSubset = null ) { $ res = new \ stdClass ( ) ; $ res -> relevance = 0 ; $ res -> value = $ this -> escape ( $ code ) ; $ res -> language = "" ; $ scnd = clone $ res ; $ tmp = $ languageSubset ? $ languageSubset : $ this -> autodetectSet ; foreach ( $ tmp as $ l ) { // don't fail if we run into a non-existent language try { // skip any languages that don't support auto detection if ( ! $ this -> autoDetection ( $ l ) ) { continue ; } $ current = $ this -> highlight ( $ l , $ code , false ) ; } catch ( \ DomainException $ e ) { continue ; } if ( $ current -> relevance > $ scnd -> relevance ) { $ scnd = $ current ; } if ( $ current -> relevance > $ res -> relevance ) { $ scnd = $ res ; $ res = $ current ; } } if ( $ scnd -> language ) { $ res -> secondBest = $ scnd ; } return $ res ; }
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 $code with each language (170+). Set this to
an array of languages of your choice to limit the amount of languages
to try.

@throws \DomainException if the attempted language to check does not exist
@throws \Exception       if an invalid regex was given in a language file

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