<commit_before><?php

namespace Phpillip\Service;

use Parsedown as BaseParsedown;
use Phpillip\Service\Pygments;

/**
 * Parsedown
 */
class Parsedown extends BaseParsedown
{
    /**
     * Pygment highlighter
     *
     * @var Pygment
     */
    protected $pygments;

    /**
     * Constructor
     *
     * @param Pygments|null $pygments
     */
    public function __construct(Pygments $pygments = null)
    {
        $this->pygments = $pygments;
    }

    /**
     * {@inheritdoc}
     */
    protected function blockCodeComplete($Block)
    {
        $Block['element']['text']['text'] = $this->getCode($Block);

        return $Block;
    }

    /**
     * {@inheritdoc}
     */
    protected function blockFencedCodeComplete($Block)
    {
        $Block['element']['text']['text'] = $this->getCode($Block);

        return $Block;
    }

    /**
     * {@inheritdoc}
     */
    protected function inlineLink($Excerpt)
    {
        $data = parent::inlineLink($Excerpt);

        if (preg_match('#(https?:)?//#i', $data['element']['attributes']['href'])) {
            $data['element']['attributes']['target'] = '_blank';
        }

        return $data;
    }

    /**
     * Process code content
     *
     * @param string $text
     *
     * @return string
     */
    protected function getCode($Block)
    {
        if (!isset($Block['element']['text']['text'])) {
            return null;
        }

        $text = $Block['element']['text']['text'];

        if ($this->pygments && $language = $this->getLanguage($Block)) {
            return $this->pygments->highlight($text, $language);
        }

        return htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
    }

    /**
     * Get language of the given block
     *
     * @param array $Block
     *
     * @return string
     */
    protected function getLanguage($Block)
    {
        if (!isset($Block['element']['text']['attributes'])) {
            return null;
        }

        return substr($Block['element']['text']['attributes']['class'], strlen('language-'));
    }
}<commit_msg>Added IDs for title in markdown parser<commit_after><?php

namespace Phpillip\Service;

use Parsedown as BaseParsedown;
use Phpillip\Service\Pygments;

/**
 * Parsedown
 */
class Parsedown extends BaseParsedown
{
    /**
     * Pygment highlighter
     *
     * @var Pygment
     */
    protected $pygments;

    /**
     * Constructor
     *
     * @param Pygments|null $pygments
     */
    public function __construct(Pygments $pygments = null)
    {
        $this->pygments = $pygments;
    }

    /**
     * {@inheritdoc}
     */
    protected function blockCodeComplete($Block)
    {
        $Block['element']['text']['text'] = $this->getCode($Block);

        return $Block;
    }

    /**
     * {@inheritdoc}
     */
    protected function blockFencedCodeComplete($Block)
    {
        $Block['element']['text']['text'] = $this->getCode($Block);

        return $Block;
    }

    /**
     * {@inheritdoc}
     */
    protected function inlineLink($Excerpt)
    {
        $data = parent::inlineLink($Excerpt);

        if (preg_match('#(https?:)?//#i', $data['element']['attributes']['href'])) {
            $data['element']['attributes']['target'] = '_blank';
        }

        return $data;
    }

    /**
     * {@inheritdoc}
     */
    protected function blockHeader($Line)
    {
        $Block = parent::blockHeader($Line);

        $Block['element']['attributes']['id'] = $this->getId($Block);

        return $Block;
    }

    /**
     * Process code content
     *
     * @param string $text
     *
     * @return string
     */
    protected function getCode($Block)
    {
        if (!isset($Block['element']['text']['text'])) {
            return null;
        }

        $text = $Block['element']['text']['text'];

        if ($this->pygments && $language = $this->getLanguage($Block)) {
            return $this->pygments->highlight($text, $language);
        }

        return htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
    }

    /**
     * Get language of the given block
     *
     * @param array $Block
     *
     * @return string
     */
    protected function getLanguage($Block)
    {
        if (!isset($Block['element']['text']['attributes'])) {
            return null;
        }

        return substr($Block['element']['text']['attributes']['class'], strlen('language-'));
    }

    /**
     * Get ID for the given block
     *
     * @param array $Block
     *
     * @return string
     */
    protected function getId($Block)
    {
        return preg_replace('#[^a-z]+#i', '-', strtolower($Block['element']['text']));
    }
}
{'fraction_non_alphanumeric': 0.17294852466077967, 'fraction_numerical': 0.0004307559767391773, 'mean_word_length': 2.1678035470668484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2728439', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1358, 'n_words': 251}