stephenharris / WP-MarkDown

WP-MarkDown plug-in. Allows Markdown to be enabled in posts, comments and bbPress forums.
http://wordpress.org/extend/plugins/wp-markdown/
112 stars 19 forks source link

Markdown inside captions is not processed #21

Open llbit opened 11 years ago

llbit commented 11 years ago

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.

stephenharris commented 11 years ago

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 commented 11 years ago

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]
llbit commented 11 years ago

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

stephenharris commented 11 years ago

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.

kadamwhite commented 7 years ago

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!