php-markdown icon indicating copy to clipboard operation
php-markdown copied to clipboard

Attributes on image by reference

Open jerry1970 opened this issue 6 years ago • 4 comments

I am too busy on a project that already has an extension of MarkdownExtra or I would fork this and make a pull request, but if in doImages the pattern for images by references gets this extra line:

(?:[ ]? ' . $this->id_class_attr_catch_re . ' )?	 # $4 = id/class attributes

almost at the end, right before the closing bracket for $1, then _doImages_reference_callback can have this at the top:

$attr  = $this->doExtraAttributes("img", $dummy =& $matches[4]);

That means you can add a class to an image by reference same as you can with an inline image:

![alt text][logo]{.some-class-name}

[logo]: https://mydomain.com/icon.png "This is our logo"

jerry1970 avatar Mar 28 '18 04:03 jerry1970

You can already do it this way:

![alt text][logo]

[logo]: https://mydomain.com/icon.png "This is our logo" {.some-class-name}

Does that work for you?

michelf avatar Mar 28 '18 10:03 michelf

Oh, had not tried that, thanks.

However, I can think of a way where this is not sufficient. If I have an image referenced more than once and they need different class names in both places (first time class=profile-avatar, second time class=message-avatar), then this would not work.

There's going to be confusion if both the reference and the instance can have a class, so if the instance has a class, too, then the reference class would be the default, the instance class would be added to the default.

jerry1970 avatar Mar 28 '18 13:03 jerry1970

Indeed, how to merge two is not obvious.

michelf avatar Mar 28 '18 14:03 michelf

Well, there is some logic in hacing a reference being the default and the instance overwriting it since that is the unique element. But merging or overwriting - the difference is not obvious. Could be a setting then.

jerry1970 avatar Mar 28 '18 14:03 jerry1970