<commit_before><?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\apidoc\helpers;

use DomainException;
use Highlight\Highlighter;

/**
 * MarkdownHighlightTrait provides code highlighting functionality for Markdown Parsers.
 *
 * @since 2.1.1
 * @author <NAME> <<EMAIL>>
 */
trait MarkdownHighlightTrait
{
    /**
     * @var Highlighter
     */
    private static $highlighter;


    /**
     * @inheritdoc
     */
    protected function renderCode($block)
    {
        if (self::$highlighter === null) {
            self::$highlighter = new Highlighter();
            self::$highlighter->setAutodetectLanguages([
                'apache', 'nginx',
                'bash', 'dockerfile', 'http',
                'css', 'less', 'scss',
                'javascript', 'json', 'markdown',
                'php', 'sql', 'twig', 'xml',
            ]);
        }
        try {
            if (isset($block['language'])) {
                if ($block['language'] === 'php' && strpos($block['content'], '<?=')) {
                    $block['language'] = 'html';
                }

                $result = self::$highlighter->highlight($block['language'], $block['content'] . "\n");
                return "<pre><code class=\"hljs {$result->language} language-{$block['language']}\">{$result->value}</code></pre>\n";
            } else {
                $result = self::$highlighter->highlightAuto($block['content'] . "\n");
                return "<pre><code class=\"hljs {$result->language}\">{$result->value}</code></pre>\n";
            }
        } catch (DomainException $e) {<commit_msg>Fixed strpos usage (#230)<commit_after><?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\apidoc\helpers;

use DomainException;
use Highlight\Highlighter;

/**
 * MarkdownHighlightTrait provides code highlighting functionality for Markdown Parsers.
 *
 * @since 2.1.1
 * @author <NAME> <<EMAIL>>
 */
trait MarkdownHighlightTrait
{
    /**
     * @var Highlighter
     */
    private static $highlighter;


    /**
     * @inheritdoc
     */
    protected function renderCode($block)
    {
        if (self::$highlighter === null) {
            self::$highlighter = new Highlighter();
            self::$highlighter->setAutodetectLanguages([
                'apache', 'nginx',
                'bash', 'dockerfile', 'http',
                'css', 'less', 'scss',
                'javascript', 'json', 'markdown',
                'php', 'sql', 'twig', 'xml',
            ]);
        }
        try {
            if (isset($block['language'])) {
                if ($block['language'] === 'php' && strpos($block['content'], '<?=') !== false) {
                    $block['language'] = 'html';
                }

                $result = self::$highlighter->highlight($block['language'], $block['content'] . "\n");
                return "<pre><code class=\"hljs {$result->language} language-{$block['language']}\">{$result->value}</code></pre>\n";
            } else {
                $result = self::$highlighter->highlightAuto($block['content'] . "\n");
                return "<pre><code class=\"hljs {$result->language}\">{$result->value}</code></pre>\n";
            }
        } catch (DomainException $e) {
{'fraction_non_alphanumeric': 0.18691588785046728, 'fraction_numerical': 0.004964953271028037, 'mean_word_length': 2.183085501858736, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5609516', 'n_tokens_mistral': 1029, 'n_tokens_neox': 966, 'n_words': 190}