WP-MarkDown icon indicating copy to clipboard operation
WP-MarkDown copied to clipboard

Markdown inside captions is not processed

Open llbit opened this issue 11 years ago • 5 comments

If I insert an image in my posts I get something like this:

[caption id="attachment_1841" align="aligncenter" width="300"]<a href="AAA"><img src="BBB" alt="CCC" width="300" height="250" class="size-medium wp-image-1841" /></a> CCC[/caption]

After this has been pretty printed by WP-Markdown it looks like this:

[caption id="attachment_1841" align="aligncenter" width="300"][<img src="BBB" alt="CCC" width="300" height="250" class="size-medium wp-image-1841" />][3] CCC[/caption]

But the above is not correctly transformed back to HTML.

llbit avatar Jun 23 '13 16:06 llbit

This is definitely a captions issue (without the captions shortcode, it behaves fine). The generated markdown above is valid and is parsed correctly as HTML, however, when you re-save the post, it for some reasons appends another [3] to the link.

Will need to look into this, in the mean time if you specify an attribute on the a tag - e.g. rel or class then it prevents the the link being converted to markdown in the first place...

stephenharris avatar Jun 25 '13 11:06 stephenharris

The problem here is that the caption together with the link around the image:

 [caption...][{img}]

is it self valid markdown, with the text in the first closed brackets linked to the url referenced by the first. Typically this is of the form of an integer:

 [caption...][1]

but any identifier can be used. As far as I can see this is just an inescapable (no pun intended) problem with mixing and matching shortcodes and markdown.

Another workaround is the following:

[caption id="attachment_8169" align="alignnone" width="943"]

[<img src="http://localhost/dev/wp-content/uploads/2013/07/event-map.png" alt="Event map with tooltip. (Looks event better with custom venue markers!)" width="943" height="401" class="size-full wp-image-8169" />][1] Event map with tooltip.

[/caption]

stephenharris avatar Jul 25 '13 11:07 stephenharris

Can I get Wordpress to generate captions according to your workaround so that I don't get these formatting problems?

llbit avatar Jul 25 '13 12:07 llbit

I think there probabaly is but I don't know off the top of my head. I think currently the only way to workaround this is to add a class/attribute to the anchor tag or wrap the caption in <div> tags.

stephenharris avatar Jul 25 '13 17:07 stephenharris

Old issue, but since we ran into it, wanted to share our solution: We ended up customizing image_send_to_editor so that it would insert a <figure> element directly if a $caption is present, which seems to work well!

kadamwhite avatar Feb 03 '17 23:02 kadamwhite