Support links around the image in captioned images

As it was discussed in this forum thread and reported in XRENDERING-670, we have an inconsistency between CKEditor and XWiki syntax: CKEditor allows adding a link to an image when that image has a caption but this cannot be represented in XWiki syntax.

My proposal is to represent this as

[[~[~[Caption Content~>~>image:Sandbox.WebHome@XWikiLogo.png~]~]>>doc:Sandbox.TestPage2]]

in XWiki syntax, so basically we would nest the captioned image in a link. The idea is to only recognize this if the captioned image is the only content of the link, otherwise this will be treated as a regular link and the caption will be lost. Similarly, only if the figure contains just a link with a nested image, it is transformed into this XWiki syntax.

I don’t like how this is further reversing the nesting of the elements, but given the current syntax and the current parser (which shouldn’t be changed for backwards compatibility reasons), this seems the only logical and somehow nice syntax.

An alternative would be to store the information of the link in attributes of the image (there could be an attribute for the reference and a prefix to store all other attributes), but this seems much less logical and would probably require a lot more extra code.

The escaping on the nested image syntax is required, as otherwise the parser doesn’t recognize it (the parser doesn’t accept nested links, the link label is parsed in a sub-parser after removing one level of escaping).

My proposal is to implement this for 15.5 and also backport it to 14.10.x. I would either backport it directly if the fix looks simple enough or wait until 15.5 has been out for at least two weeks to ensure some testing happened.

Any opinions, also on the question of backporting?

+1

+0

Thanks,
Marius

It’s clearly not a nice syntax (it’s almost unusable by a wiki markup editor and I dare any user to use it directly ;)), but I understand that the idea is not to add the syntax for markup users to use it but more to avoid not supporting a CKEditor feature.

I guess the proposal is to add this syntax to both xwiki/2.1 and xwiki/2.0 syntaxes, right?

BTW, I think we’ve added the ability to add captions in CK not too long ago (by enabling the existing “caption” feature, is that correct? This is probably when this issue stared appearing but we also forgot that we introduced the same problem for all other syntaxes that we support and that have parsers and renderers (ie that can be used in the WYSIWYG editor). See https://rendering.xwiki.org/xwiki/bin/view/Main/WebHome#HSupportedSyntaxes

As an example, I have in mind markdown/1.2 and I’m far from sure that its renderer will generate some valid MD markup when used in CK. I’ll test it.

The new syntax can break existing content so we will need to document it in the RN for sure.

The other option is to disallow the ability to add a link around a captioned image in CK but I agree it’s less nice, so +1 for 15.5 and 14.10.x since from a user POV it’s a bug.

It would be interesting to discuss a future nice markup syntax for xwiki/2.2 (for this topic and for captioned images too) and create some jiras in Loading...

Thanks

Confirmed that it’s broken: Loading...

As discussed in the chat in the meantime, caption and figure support has only been enabled for XWiki syntax and not for Markdown, see xwiki-platform/config.js at 74534047e7e56705653f702a7bae7fad8ec1ca97 · xwiki/xwiki-platform · GitHub. The fact that caption support is enabled for Markdown is a regression most likely related to the new image dialog.

A problem is also that you would need to disable captions when the image already has a link. And then users will start wondering why some options/buttons are disabled in some cases, so you would need a message with some explanation so this is also not really simple, unfortunately.