EDITED: Resending this message to fix some escaping issues when the email
went out the first time.
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: (NOTE: in all examples below I have added
extra spaces around the ! chars to prevent these from getting stripped out
in this email)
< ! --startmacro:outermacro|-||-|outer text before < !
--startmacro:innermacro|-||-|inner text-->< ! --stopmacro--> outer text
after-->< ! --stopmacro-->
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:
< ! --startmacro:outermacro|-||-|outer text before {{innermacro}}inner
text{{//innermacro}} outer text after-->< ! --stopmacro-->
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
</xannotation>
outer text after
</xannotation>
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 XWikiCommentHandler.java.
References:
AnnotatedXHTMLRenderer.java:
https://github.com/xwiki/xwiki-rendering/blob/master/xwiki-rendering-syntax…
XWikiCommentHandler.java:
https://github.com/xwiki/xwiki-rendering/blob/master/xwiki-rendering-syntax…
--
View this message in context:
http://xwiki.475771.n2.nabble.com/RESEND-Nesting-within-Annotated-XHTML-tp7…
Sent from the XWiki- Dev mailing list archive at
Nabble.com.