Display image always as link

In confluence there is very handy functionality, that I miss in xwiki. When user pastes a picture to the CKeditor, the image (when viewed later on the page) is by default clickable and linked to the attachement (and displayed using lightbox).

I m trying to implement the same in xwiki as it saves ton of work.

Basically I want pasted image [[image:myimage.png||width=“100"]] to be always displayed as [[[[image:myimage.png||width=“100"]]>>attach:myimage.png]]

In the old post in the mailing list it is suggested to use DefaultXHTMLImageRenderer - in this case probably AttachmentXHTMLImageTypeRenderer (probably to generate extra A tag around IMG?)

Is this (still) recommended approach?

I’m curious: could you explain why it’s handy? :slight_smile:

In XWiki, page content is parsed as a DOM of elements (we call it a XDOM) and when rendering an XDOM to a syntax (XHTML in this case), we generate events, and we have Listener or Renderer (a Renderer is a Listener) to decide what to generate for each element (paragraph, images, etc).

The XHTML renderer is itself using some ancillary components to perform its rendering, one of them is the XHTMLImageRenderer (https://github.com/xwiki/xwiki-rendering/blob/9e4974d280f409b3ad216a6dba48b3328cbb5788/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/image/XHTMLImageRenderer.java).

So you can override this with your component, see https://extensions.xwiki.org/xwiki/bin/view/Extension/Component%20Module#HOverrides