Returns an array of options formatted for use with pygmentize

@param array $options Options passed to the highlighter
@param string $code The code to highlight
@return array
320575
protected function parsePygmentsOptions(array $options, $code)
    {
        $pygmentsOptions = ['encoding' => 'utf-8'];

        if (!empty($options['linenos']) && $options['linenos'] === true) {
            $pygmentsOptions['linenos'] = 'table';
        }

        if (!empty($options['start'])) {
            $pygmentsOptions['linenostart'] = $options['start'];
        }

        if (!empty($options['mark'])) {
            $pygmentsOptions['hl_lines'] = $this->parseMarks($options['mark']);
        }

        if (!empty($options['lang'])
            && strtolower($options['lang']) === 'php'
            && stripos($code, '<?php') === false
        ) {
            $pygmentsOptions['startinline'] = 'True';
        }

        return $pygmentsOptions;
    }
239386
private static function extractColorAndOptions($colorCode)
    {
        $options = array();
        foreach (self::$options as $name => $bit) {
            if (($colorCode & $bit) === $bit) {
                $options[] = self::$codes[$bit];
                $colorCode = $colorCode & ~$bit;
            }
        }
        if (!isset(self::$codes[$colorCode])) {
            throw new ConsoleException("Cannot parse color code");
        }
        return array(self::$codes[$colorCode], $options);
    }
414070
protected function minify($code)
    {
        $code = (string) parent::minify($code);

        $code = preg_replace('/( )?=( )?/', '=', $code);

        $code = preg_replace('/( )?\(( )?/', '(', $code);

        return preg_replace('/( )?var ( )?/', '', $code);
    }
624610
public static function getTokensFromString($code) {
      try {
        $tokens = token_get_all($code, TOKEN_PARSE);
      } catch (\ParseError $e) {
        // with TOKEN_PARSE flag, the function throws on invalid code
        // let's just ignore the error and tokenize the code without the flag
        $tokens = token_get_all($code);
      }

      foreach ($tokens as $index => $tokenData) {

        if (!is_array($tokenData)) {
          $previousIndex = $index - 1;

          /** @var Token $previousToken */
          $previousToken = $tokens[$previousIndex];
          $line = $previousToken->getLine() + substr_count($previousToken->getValue(), "\n");
          $tokenData = [
            Token::INVALID_TYPE,
            $tokenData,
            $line,
          ];
        }

        $token = new Token($tokenData);
        $token->setIndex($index);
        $tokens[$index] = $token;

      }

      return $tokens;
    }
984318
protected function shrinkPhpCode (& $code = '') {
		if (!defined('T_DOC_COMMENT')) define ('T_DOC_COMMENT', -1);
		if (!defined('T_ML_COMMENT')) define ('T_ML_COMMENT', -1);
		$chars = '!"#$&\'()*+,-./:;<=>?@[\]^`{|}';
		$chars = array_flip(preg_split('//',$chars));
		$result = '';
		$space = '';
		$tokens = token_get_all($code);
		$tokensToRemove = [
			T_COMMENT		=> 1,
			T_ML_COMMENT	=> 1,
			T_WHITESPACE	=> 1,
		];
		if (count($this->cfg->keepPhpDocComments) === 0) 
			$tokensToRemove[T_DOC_COMMENT] = 1;
		foreach ($tokens as & $token) {
			if (is_array($token)) {
				$tokenId = $token[0];
				$token[3] = token_name($tokenId);
				if (isset($tokensToRemove[$tokenId])) {
					if ($tokenId == T_WHITESPACE) $space = ' ';
				} else {
					$oldPart = $token[1];
					if ($tokenId == T_ECHO) $oldPart .= ' ';
					if (
						isset($chars[substr($result, -1)]) ||
						isset($chars[$oldPart{0}])
					) $space = '';
					if ($tokenId == T_DOC_COMMENT) 
						$oldPart = $this->shrinkPhpCodeReducePhpDocComment($oldPart);
					$result .= $space . $oldPart;
					$space = '';
				}
			} else if (is_string($token)) {
				$result .= $token; // control char: !"#$&\'()*+,-./:;<=>?@[\]^`{|}
			}
		}
		return $result;
	}
407284
protected function getCode($code)
    {
        if (is_array($code)) {
            return $this->getCodeArray($code);
        }

        return $this->get($code);
    }
1329504
private function instrumentCode($code)
    {
        return $this->printer->prettyPrint($this->traverser->traverse($this->parse($code)));
    }
554106
private function getMergedOptions(array $options)
    {
        $options = array_merge(
            $this->getDefaultOptions(),
            $options
        );

        if (isset($options['formats'])) {
            $options['formats'] = self::mergeFormats($this->getDefaultFormats(), $options['formats']);
        } else {
            $options['formats'] = $this->getDefaultFormats();
        }

        if (is_null($options['line_ending'])) {
            $options['line_ending'] = $options['type'] === 'html' ? '<br/>' : "\n";
        }

        if (is_null($options['indentation'])) {
            $options['indentation'] = $options['type'] === 'html' ? '&nbsp;&nbsp;&nbsp;&nbsp;' : '    ';
        }

        // `parts_newline` requires `clause_newline`
        $options['parts_newline'] &= $options['clause_newline'];

        return $options;
    }
488302
public function filter($code)
    {
        if (strpos($code, '<html') === false)
        {
            return $this->minify($code);
        }

        $utf8 = (string) '<?xml encoding="UTF-8">';

        $dom = new \DOMDocument;

        @$dom->loadHTML((string) $utf8 . $code);

        $elements = $dom->getElementsByTagName('*');

        $this->remove($elements);

        $html = $this->minify($dom->saveHTML());

        return $this->restore((string) $html);
    }
1368350
public static function format($query, array $options = [])
    {
        $lexer = new Lexer($query);
        $formatter = new self($options);

        return $formatter->formatList($lexer->list);
    }
462543
public function addJs($scriptCode, array $options = [])
    {
        if (!isset($options['position'])) {
            $options['position'] = self::POS_END;
        }

        return $this->loggingCodeAsset($scriptCode, self::ASSET_JS, $options);
    }
284959
public static function shortCodeFigure($options)
    {
        // Merge incoming options with default and expose as variables
        $options= array_merge(
            [
                "id"    => null,
                "class" => null,
                "src"   => null,
                "title" => null,
                "alt"   => null,
                "caption" => null,
                "href"  => null,
                "nolink" => false,
            ],
            self::ShortCodeInit($options)
        );
        extract($options, EXTR_SKIP);

        $id = $id ? " id=\"$id\"" : null;
        $class = $class ? " class=\"figure $class\"" : " class=\"figure\"";
        $title = $title ? " title=\"$title\"" : null;

        if (!$alt && $caption) {
            $alt = $caption;
        }

        if (!$href) {
            $pos = strpos($src, "?");
            $href = $pos ? substr($src, 0, $pos) : $src;
        }

        $start = null;
        $end = null;
        if (!$nolink) {
            $start = "<a href=\"{$href}\">";
            $end = "</a>";
        }

        if ($caption) {
            $caption = "<figcaption markdown=1>{$caption}</figcaption>";
        }

        $html = <<<EOD
<figure{$id}{$class}>
{$start}<img src="{$src}" alt="{$alt}"{$title}/>{$end}
{$caption}
</figure>
EOD;

        return $html;
    }
484287
protected function getGroupFormFieldConfig($code)
    {
        if (!$code) {
            return null;
        }

        $fields = array_get($this->groupDefinitions, $code.'.fields');

        if (!$fields) {
            return null;
        }

        return ['fields' => $fields];
    }
892600
def highlight(code, lexer='html', formatter='html', output_wrapper=None):
    """"""
    if not pygments:
        raise TypeError("pygments module required")
    if not isinstance(code, six.string_types):
        code = pprint.pformat(code)
    if isinstance(lexer, six.string_types):
        lexer = pygments.lexers.get_lexer_by_name(lexer)
    if isinstance(formatter, six.string_types):
        formatter = pygments.formatters.get_formatter_by_name(formatter)
        if formatter.name.lower() == 'html':
            formatter.full = True
            formatter.cssclass = "pygments-%s" % uuid.uuid4()
            if output_wrapper is None:
                output_wrapper = HTML
    return output_wrapper(pygments.highlight(code, lexer, formatter))
14770
public static function stripComments($code)
    {
        $output = '';
        $commentTokens = array(T_COMMENT, T_DOC_COMMENT);
        foreach (token_get_all($code) as $token) {
            if (is_array($token)) {
                if (in_array($token[0], $commentTokens)) {
                    continue;
                }
                $token = $token[1];
            }
            $output .= $token;
        }

        return $output;
    }
1266048
protected function getTreeOptionsFromRequest($options = [])
    {
        $options = array_merge([
            'subclasses' => true,
            'instances' => true,
            'highlightUri' => '',
            'chunk' => false,
            'offset' => 0,
            'limit' => 0
        ], $options);

        if ($this->hasRequestParameter('loadNode')) {
            $options['uniqueNode'] = $this->getRequestParameter('loadNode');
        }

        if ($this->hasRequestParameter("selected")) {
            $options['browse'] = array($this->getRequestParameter("selected"));
        }

        if ($this->hasRequestParameter('hideInstances')) {
            if((bool) $this->getRequestParameter('hideInstances')) {
                $options['instances'] = false;
            }
        }
        if ($this->hasRequestParameter('classUri')) {
            $options['class'] = $this->getCurrentClass();
            $options['chunk'] = !$options['class']->equals($this->getRootClass());
        } else {
            $options['class'] = $this->getRootClass();
        }

        if ($this->hasRequestParameter('offset')) {
            $options['offset'] = $this->getRequestParameter('offset');
        }

        if ($this->hasRequestParameter('limit')) {
            $options['limit'] = $this->getRequestParameter('limit');
        }

        if ($this->hasRequestParameter('order')) {
            $options['order'] = tao_helpers_Uri::decode($this->getRequestParameter('order'));
        }

        if ($this->hasRequestParameter('orderdir')) {
            $options['orderdir'] = $this->getRequestParameter('orderdir');
        }
        return $options;
    }
957540
private function optimizeCssCode($code)
	{
		if (YII_DEBUG)
			return $code;

		require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'CssMin.php';
		return CssMin::minify($code);
	}