(RESEND) Nesting within Annotated XHTML

classic Classic list List threaded Threaded
4 messages Options
ktc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

(RESEND) Nesting within Annotated XHTML

ktc
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-syntaxes/xwiki-rendering-syntax-annotatedxhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/AnnotatedXHTMLRenderer.java
XWikiCommentHandler.java: https://github.com/xwiki/xwiki-rendering/blob/master/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/parser/xhtml/wikimodel/XWikiCommentHandler.java#L90-L99
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: (RESEND) Nesting within Annotated XHTML

Marius Dumitru Florea
On Tue, Mar 28, 2017 at 12:13 AM, ktc <[hidden email]> wrote:

> 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:
>

A note on this: using XML comments for macro markers (solution 1) has
proven to be fragile for the CKEditor integration because the HTML produced
by rendering macros (especially by those that are not maintained by the
XWiki Development team) is often not valid which creates problems when the
browser attempts to fix the HTML. The start/stop macro comments must be on
the same level and the browser often moves these comments when the HTML is
not valid. See https://jira.xwiki.org/browse/CKEDITOR-131 .

I think it's interesting to investigate using elements or attributes
instead of comments for macro markers (solution 2). Although it doesn't
prevent macros from generating invalid HTML, it may be more robust against
mutations performed by the browser when fixing the HTML.

Thanks,
Marius


>
>   <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-syntaxes/xwiki-rendering-syntax-
> annotatedxhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/
> AnnotatedXHTMLRenderer.java
> XWikiCommentHandler.java:
> https://github.com/xwiki/xwiki-rendering/blob/master/
> xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/
> src/main/java/org/xwiki/rendering/internal/parser/xhtml/wikimodel/
> XWikiCommentHandler.java#L90-L99
>
>
>
> --
> View this message in context: http://xwiki.475771.n2.nabble.
> com/RESEND-Nesting-within-Annotated-XHTML-tp7603271.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
>
ktc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: (RESEND) Nesting within Annotated XHTML

ktc
In reply to this post by ktc
Thanks for the input Marius.

Could you advise on a starting point for implementing an 'element-based' equivalent of the Annotated XHTML syntax? Is there a particular class(es) that could be extended or mimicked to achieve this (ideally building on existing logic for most of the heavy lifting)?

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: (RESEND) Nesting within Annotated XHTML

Marius Dumitru Florea
The AnnotatedXHTMLRenderer can be found at
https://github.com/xwiki/xwiki-rendering/blob/master/xwiki-rendering-syntaxes/xwiki-rendering-syntax-annotatedxhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/AnnotatedXHTMLRenderer.java
. It's a component (see
http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents). But I
don't know this part of the code very well.

Hope this helps,
Marius

On Tue, Mar 28, 2017 at 10:28 PM, ktc <[hidden email]> wrote:

> Thanks for the input Marius.
>
> Could you advise on a starting point for implementing an 'element-based'
> equivalent of the Annotated XHTML syntax? Is there a particular class(es)
> that could be extended or mimicked to achieve this (ideally building on
> existing logic for most of the heavy lifting)?
>
> Thanks!
>
>
>
> --
> View this message in context: http://xwiki.475771.n2.nabble.
> com/RESEND-Nesting-within-Annotated-XHTML-tp7603271p7603277.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
>
Loading...