<commit_before><?php

namespace FluxBB\Markdown\Parser\Inline;

use FluxBB\Markdown\Common\Text;
use FluxBB\Markdown\Node\Image;
use FluxBB\Markdown\Node\InlineNodeAcceptorInterface;
use FluxBB\Markdown\Parser\AbstractInlineParser;

class ImageParser extends AbstractInlineParser
{

    /**
     * Parse the given content.
     *
     * Any newly created nodes should be appended to the given target. Any remaining content should be passed to the
     * next parser in the chain.
     *
     * @param Text $content
     * @param InlineNodeAcceptorInterface $target
     * @return void
     */
    public function parseInline(Text $content, InlineNodeAcceptorInterface $target)
    {
        if ($content->contains('![')) {
            $this->parseInlineImage($content, $target);
        } else {
            $this->next->parseInline($content, $target);
        }
    }

    protected function parseInlineImage(Text $content, InlineNodeAcceptorInterface $target)
    {
        $content->handle(
            '{
                (               # wrap whole match in $1
                  !\[
                    (.*?)       # alt text = $2
                  \]
                  \(            # literal paren
                    [ \t]*
                    <?(\S+?)>?  # src url = $3
                    [ \t]*
                    (           # $4
                      ([\'"])   # quote char = $5
                      (.*?)     # title = $6
                      \5        # matching quote
                      [ \t]*
                    )?          # title is optional
                  \)
                )
            }xs',
            function (Text $w, Text $whole, Text $alt, Text $url, Text $a = null, Text $q = null, Text $title = null) use ($target) {
                $target->addInline(new Image($url, $alt, $title));
            },
            function (Text $part) use ($target) {
                $this->next->parseInline($part, $target);
            }
        );
    }

}<commit_msg>Image tags can be escaped.<commit_after><?php

namespace FluxBB\Markdown\Parser\Inline;

use FluxBB\Markdown\Common\Text;
use FluxBB\Markdown\Node\Image;
use FluxBB\Markdown\Node\InlineNodeAcceptorInterface;
use FluxBB\Markdown\Parser\AbstractInlineParser;

class ImageParser extends AbstractInlineParser
{

    /**
     * Parse the given content.
     *
     * Any newly created nodes should be appended to the given target. Any remaining content should be passed to the
     * next parser in the chain.
     *
     * @param Text $content
     * @param InlineNodeAcceptorInterface $target
     * @return void
     */
    public function parseInline(Text $content, InlineNodeAcceptorInterface $target)
    {
        if ($content->contains('![')) {
            $this->parseInlineImage($content, $target);
        } else {
            $this->next->parseInline($content, $target);
        }
    }

    protected function parseInlineImage(Text $content, InlineNodeAcceptorInterface $target)
    {
        $content->handle(
            '{
                (?<!\\\\)!
                \[
                (.*?)       # alt text = $1
                \]
                \(            # literal paren
                [ \t]*
                <?(\S+?)>?  # src url = $2
                [ \t]*
                (           # $3
                  ([\'"])   # quote char = $4
                  (.*?)     # title = $5
                  \5        # matching quote
                  [ \t]*
                )?          # title is optional
                \)
            }xs',
            function (Text $w, Text $alt, Text $url, Text $a = null, Text $q = null, Text $title = null) use ($target) {
                $target->addInline(new Image($url, $alt, $title));
            },
            function (Text $part) use ($target) {
                $this->next->parseInline($part, $target);
            }
        );
    }

}
{'fraction_non_alphanumeric': 0.12233359033667437, 'fraction_numerical': 0.003341043433564636, 'mean_word_length': 1.3980283425754776, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5266114', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1042, 'n_words': 261}