Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to add image class #1060

Open
Mecanik opened this issue Dec 21, 2024 · 1 comment
Open

Impossible to add image class #1060

Mecanik opened this issue Dec 21, 2024 · 1 comment
Labels
not enough info We need more information to properly assist with this

Comments

@Mecanik
Copy link

Mecanik commented Dec 21, 2024

Version(s) affected

2.6.0

Description

I tried with default attributes and also tried with attributes extensions, the class on images will not be added.

Same thing with links, classes are not added.

How to reproduce

Example:

![some image](...){: width="100" height="100" #test .image}

Output:

<img width="100" height="100" id="test" src="..." alt="some image">

@colinodell
Copy link
Member

Thanks for opening this issue! Unfortunately I'm not able to replicate this issue.

I tried testing this with both the default attribute extension:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\CommonMark\Node\Inline\Image;
use League\CommonMark\Extension\DefaultAttributes\DefaultAttributesExtension;
use League\CommonMark\MarkdownConverter;

$markdown = '![some image](...)';

$environment = new Environment([
    'default_attributes' => [
        Image::class => [
            'class' => 'image',
        ],
    ],
]);
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new DefaultAttributesExtension());

$converter = new MarkdownConverter($environment);
$result = $converter->convert($markdown);

echo $result->getContent();

// <p><img class="image" src="..." alt="some image" /></p>

And with the attribute extension:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\Attributes\AttributesExtension;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;

$markdown = '![some image](...){: width="100" height="100" #test .image}';

$environment = new Environment();
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new AttributesExtension());

$converter = new MarkdownConverter($environment);
$result = $converter->convert($markdown);

echo $result->getContent();

// <p><img class="image" width="100" height="100" id="test" src="..." alt="some image" /></p>

Both produce HTML which includes the image class 🤔 Perhaps there's something specific to your configuration which may be causing this? Like maybe one extension is interfering with this functionality somehow?

If you could please share code showing how your Environment is set up (specifically the configuration and extensions are you using) that will allow me to debug this further.

@colinodell colinodell added the not enough info We need more information to properly assist with this label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not enough info We need more information to properly assist with this
Projects
None yet
Development

No branches or pull requests

2 participants