Inject chain listeners from extensions

Hello all,

In the context of Loading..., I’d like to adapt the parsing and rendering of images with caption, but only when the image styles are installed in the wiki.

The best approach we know of is by adding a new chain listener in the during parsing/rendering.
This is currently not possible to add a new listener from an extension and this is what I’d like to propose here.

The idea is to define a new ListenerProvider role with two operations:

  • accept(action, syntaxHint) return true when the registry can return a component for the action (render/parse) for the requested syntax
  • getListener instantiate and return a new instance of the listener

An internal ListenerRegistry helps with the selection of the component for which accept returns true and them to the provided listener chain.

The registry is used in AbstractWikiModelParser and AbstractXWikiSyntaxRenderer to complete the listener chain with the provided listener. They are added at the beginning of the chain. No notion of order is proposed for now.

You can find the corresponding (currently draft) PR at XRENDERING-655: Add the ability to style image captions by manuelleduc · Pull Request #258 · xwiki/xwiki-rendering · GitHub

WDYT?

The general idea sounds OK, but I added a few comments to the implementation.

1 Like

Done as part of Loading...