Php CommonMark标记内联解析器始终在`<;内返回;p>;`标签

Php CommonMark标记内联解析器始终在`<;内返回;p>;`标签,php,laravel,commonmark,Php,Laravel,Commonmark,我正在使用League,并创建自定义扩展以显示getUrl('wide')。“alt=“”。$image->alt_标记。“”>; $this->assertEquals($string,$expected); } } 下面是测试结果: 在测试文件@image(image\u id)中,始终返回标记,这不是我预期的结果。您是否尝试过@image($image)?是否尝试过@image($image)? <figure> <img src="image_url" alt

我正在使用League,并创建自定义扩展以显示
getUrl('wide')。“alt=“”。$image->alt_标记。“”>;
$this->assertEquals($string,$expected);
}
}
下面是测试结果:

在测试文件
@image(image\u id)
中,始终返回

标记,这不是我预期的结果。

您是否尝试过
@image($image)
?是否尝试过
@image($image)
<figure>
   <img src="image_url" alt="image_alt"></img>
</figure>
<?php

namespace App\Markdown\Extensions\Image;

use League\CommonMark\Inline\Element\HtmlInline;
use League\CommonMark\Inline\Parser\AbstractInlineParser;
use League\CommonMark\InlineParserContext;
use App\Storage\Image;

class ImageParser extends AbstractInlineParser
{

    /**
     * @return string[]
     */
    public function getCharacters()
    {
        return ['@'];
    }

    /**
     * @param InlineParserContext $inlineContext
     *
     * @return bool
     */
    public function parse(InlineParserContext $inlineContext)
    {
        $cursor = $inlineContext->getCursor();

        $previous = $cursor->peek(-1);
        if ($previous !== null && $previous !== ' ') {
            return false;
        }

        $previousState = $cursor->saveState();
        $cursor->advance();

        $handle = $cursor->match('/image\((\d+)\)/');
        if (empty($handle)) {
            $cursor->restoreState($previousState);

            return false;
        }

        $imageId = preg_replace("/image\((\d+)\)/", "$1", $handle);
        $image = Image::find($imageId);

        if (is_null($image)) {
            return false;
        }

        $inlineContext->getContainer()->appendChild(new HtmlInline($this->render($image)));

        return true;
    }

    /**
     * Render the image figure.
     *
     * @param \PYM\Storage\Image $image
     *
     * @return string
     */
    protected function render(Image $image)
    {
        $source = empty($image->source) ? null : "<figcaption>{$image->source}</figcaption>";

        return '<figure><img src="' . $image->getUrl('wide') . '" alt="' . $image->alt_tag . '">' . $source . '</figure>';
    }
}
<?php

namespace Tests\Unit\Markdown;

use Tests\TestCase;

class ImageExtensionTest extends TestCase
{
    /** @test */
    public function converts_to_a_image_tag()
    {
        $image = factoryImage();

        $string = \Markdown::convertToHtml("First paragraph

        @image({$image->id})

        Last paragraph");

        dd($string);
        $expected = '<img src="'.$image->getUrl('wide').'" alt="'.$image->alt_tag.'">';

        $this->assertEquals($string, $expected);
    }
}