thephpleague / commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
https://commonmark.thephpleague.com
BSD 3-Clause "New" or "Revised" License
2.72k stars 191 forks source link

Embed extension adds iframe two times #1043

Open cavid90 opened 3 weeks ago

cavid90 commented 3 weeks ago

Version(s) affected

2.5

Description

I use Embed extension in my app. The only problem - it adds iframe two times.

How to reproduce

Just add any youtube or x.com link. You will see that it added 2 iframes for the given link

Possible solution

No response

Additional context

No response

Did this project help you today? Did it make you happy in any way?

No response

colinodell commented 2 weeks ago

Thanks for opening this bug report!

Could you please share your configuration, the code you're using to instantiate the parser, and some sample Markdown showing the issue? I ask because our test suite isn't showing this issue, so it would be helpful to know how/why your instance is behaving differently.

cavid90 commented 2 weeks ago

Hello. Yes, this is the configuration

        $embedLibrary = new Embed();
        $embedLibrary->setSettings([
            'oembed:query_parameters' => [
                'maxwidth' => 800,
                'maxheight' => 600,
            ],
            'twitch:parent' => 'example.com',
            'facebook:token' => '1234|5678',
            'instagram:token' => '1234|5678',
        ]);

        $config = [
            'table' => [
                'wrap' => [
                    'enabled' => true,
                    'tag' => 'div',
                    'attributes' => ['class' => 'table-responsive'],
                ],
                'alignment_attributes' => [
                    'left'   => ['align' => 'left'],
                    'center' => ['align' => 'center'],
                    'right'  => ['align' => 'right'],
                ],
            ],
            'default_attributes' => [
                Table::class => [
                    'class' => 'table table-bordered table-striped table-hover',
                ],
                Link::class => [
                    'class' => '',
                    'target' => '_blank',
                ],
            ],
            'embed' => [
                'adapter' => new OscaroteroEmbedAdapter($embedLibrary), // See the "Adapter" documentation below
                'allowed_domains' => ['youtube.com', 'x.com', 'vakansiya.biz'],
                'fallback' => 'link',
            ],
        ];

        $environment = new Environment($config);
        $environment->addExtension(new CommonMarkCoreExtension());
        $environment->addExtension(new GithubFlavoredMarkdownExtension());
        $environment->addExtension(new TableExtension());
        $environment->addExtension(new TaskListExtension());
        $environment->addExtension(new DefaultAttributesExtension());
        $environment->addExtension(new EmbedExtension());
colinodell commented 6 days ago

Thanks for sharing this!

Unfortunately, I'm still unable to replicate your issue, even with that configuration 😕 I get a single line of output containing a single embed.