php-markdown
php-markdown copied to clipboard
Attributes on image by reference
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"
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?
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.
Indeed, how to merge two is not obvious.
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.