<commit_before><?php
namespace nochso\WriteMe\Markdown;

use nochso\Omni\Multiline;
use nochso\Omni\Strings;
use nochso\WriteMe\Document;

/**
 * MarkdownParser extracts elements from Markdown content.
 */
class Parser
{
    /**
     * @param \nochso\WriteMe\Document $document
     *
     * @return \nochso\WriteMe\Markdown\HeaderList
     */
    public function extractHeaders(Document $document)
    {
        $headerList = new HeaderList();
        $lines = Multiline::create($document->getContent());
        $prevLine = null;
        $isFenced = false;
        foreach ($lines as $line) {
            if (preg_match('/^```(?!`)/', $line)) {
                $isFenced = !$isFenced;
            }
            if (!$isFenced) {
                $header = $this->extractHeader($line, $prevLine);
                if ($header !== null) {
                    $headerList->add($header);
                }
            }
            $prevLine = $line;<commit_msg>style: Comment Parser::extractHeaders<commit_after><?php
namespace nochso\WriteMe\Markdown;

use nochso\Omni\Multiline;
use nochso\Omni\Strings;
use nochso\WriteMe\Document;

/**
 * MarkdownParser extracts elements from Markdown content.
 */
class Parser
{
    /**
     * extractHeaders returns a HeaderList containing Header objects.
     *
     * @param \nochso\WriteMe\Document $document
     *
     * @return \nochso\WriteMe\Markdown\HeaderList
     */
    public function extractHeaders(Document $document)
    {
        $headerList = new HeaderList();
        $lines = Multiline::create($document->getContent());
        $prevLine = null;
        $isFenced = false;
        foreach ($lines as $line) {
            if (preg_match('/^```(?!`)/', $line)) {
                $isFenced = !$isFenced;
            }
            if (!$isFenced) {
                $header = $this->extractHeader($line, $prevLine);
                if ($header !== null) {
                    $headerList->add($header);
                }
            }
            $prevLine = $line;
{'fraction_non_alphanumeric': 0.13882002974714924, 'fraction_numerical': 0.0, 'mean_word_length': 2.007451564828614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2096899', 'n_tokens_mistral': 602, 'n_tokens_neox': 586, 'n_words': 118}