Nesting within Annotated XHTML

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Nesting within Annotated XHTML

I have a use case where I need to nest macros to 2+ levels deep using XWiki's Annotated XHTML syntax. We are using this syntax as an input to a transformation process that utilizes XWiki's rendering engine to convert the Annotated XHTML into XWiki-native markup, similarly to how CKEditor does its work.

The problem is that with Annotated XHTML, macros are encoded as HTML comments -- but HTML comments cannot be nested within other HTML comments.

Here is a demonstrative example:

   outer text after-->

The intention is for this to be convertible to this XWiki syntax:

  {{outermacro}}outer text before {{innermacro}}inner text{{/innermacro}} outer text after{{/outermacro}}

However, this doesn't work because the HTML parser sees the first "-->" it encounters as the "end of comment" marker, thus breaking the intended nesting.

Thus, when converted to XWiki syntax, this is what comes out instead:

  {{outermacro}}outer text before <==startmacro:innermacro|-||-|inner text{{/outermacro}} outer text after ~-~->

We have considered a couple possible solutions:

1. Mimic what CKEditor does in this scenario, which is to use an HTML comment for the outermost macro-block, but have any nested macros (embedded inside the HTML comment) be rendered as XWiki-native syntax. Like this:


This approach seems to work, but it's not ideal because our Annotated XHTML generation code will now need to support two varieties of output depending on the current nesting level -- Annotated XHTML for the outermost depth, and XWiki-native for anything nested deeper.

2. Implement a variation of the existing Annotated XHTML parsing logic which, instead of expecting macros encoded in HTML comments, will expect the use of an XHTML structure that models the same information, but doesn't suffer from the nesting restrictions of HTML comments. Something like this:

  <xannotation name="startmacro:outermacro">
    outer text before
    <xannotation name="innermacro">
      inner text
    outer text after

I am looking for input from XWiki experts regarding what approach would make the most sense. Option 2 above seems like the most elegant solution overall, but I'm not sure how difficult this would be to get working in the current XWiki codebase, or what file(s) would need to be extended, etc. Is there another approach that might solve this problem more efficiently?

Note: For brevity, I've referred to "nested macros" above, but for our use case we will actually need to handle all the different comment types recognized in