<commit_before><?php

namespace allejo\stakx\Core;

use Highlight\Highlighter;

class MarkdownEngine extends \Parsedown
{
    protected $highlighter;

    public function __construct ()
    {
        $this->highlighter = new Highlighter();
    }

    public function blockFencedCodeComplete($block)
    {
        // The class has a `language-` prefix, remove this to get the language
        $language = substr($block['element']['text']['attributes']['class'], 9);
        $highlighted = $this->highlighter->highlight($language, $block['element']['text']['text']);
        $block['element']['text']['text'] = $highlighted->value;

        return $block;
    }
}<commit_msg>Fix code highlighting with no language or unknown language<commit_after><?php

namespace allejo\stakx\Core;

use Highlight\Highlighter;

class MarkdownEngine extends \Parsedown
{
    protected $highlighter;

    public function __construct ()
    {
        $this->highlighter = new Highlighter();
    }

    public function blockFencedCodeComplete($block)
    {
        // The class has a `language-` prefix, remove this to get the language
        if (isset($block['element']['text']['attributes']))
        {
            $language = substr($block['element']['text']['attributes']['class'], 9);

            try
            {
                $highlighted = $this->highlighter->highlight($language, $block['element']['text']['text']);
                $block['element']['text']['text'] = $highlighted->value;
            }
            catch (\DomainException $exception) {}
        }

        return $block;
    }
}
{'fraction_non_alphanumeric': 0.14933837429111532, 'fraction_numerical': 0.001260239445494644, 'mean_word_length': 2.9113300492610836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5496357', 'n_tokens_mistral': 440, 'n_tokens_neox': 422, 'n_words': 98}