There are 2 comments.
 
 
XWiki Rendering / cid:jira-generated-image-avatar-2dbcd61e-ec9a-4eec-bd43-7e100f4c49c0 XRENDERING-766 Open

Macros followed by an empty block with parameters gets wrapped in a span when converted to annotated html

 
View issue   ยท   Add comment
 

2 comments

 
cid:jira-generated-image-avatar-755d1a4b-c9ae-4dc9-9b29-a83fc6de7d8a Michael Hamann on 12/Sep/25 12:06
 

What I've reproduced so far is:

.runTransformations
.#-----------------------------------------------------
.input|xwiki/2.0
.#-----------------------------------------------------
{{testsimpleinlinemacro/}}(% id="test" %)hi

(% id="test" %){{testsimpleinlinemacro/}}

{{testsimpleinlinemacro/}}(% id="test" %)

Padding

{{testsimpleinlinemacro/}}(% id="test" %){{testsimpleinlinemacro/}}

{{testsimpleinlinemacro/}}(% id="test" %)

This results in the following event/1.0 output:

beginDocument
beginParagraph
beginFormat [NONE] [[id]=[test]]
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro2]
endMacroMarkerInline [testsimpleinlinemacro] []
onWord [hi]
endFormat [NONE] [[id]=[test]]
endParagraph
beginParagraph
beginFormat [NONE] [[id]=[test]]
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro3]
endMacroMarkerInline [testsimpleinlinemacro] []
endFormat [NONE] [[id]=[test]]
endParagraph
beginMacroMarkerStandalone [testsimpleinlinemacro] []
beginParagraph
onWord [simpleinlinemacro4]
endParagraph
endMacroMarkerStandalone [testsimpleinlinemacro] []
beginParagraph
beginFormat [NONE] [[id]=[test]]
onWord [Padding]
endFormat [NONE] [[id]=[test]]
endParagraph
beginParagraph
beginFormat [NONE] [[id]=[test]]
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro5]
endMacroMarkerInline [testsimpleinlinemacro] []
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro6]
endMacroMarkerInline [testsimpleinlinemacro] []
endFormat [NONE] [[id]=[test]]
endParagraph
beginMacroMarkerStandalone [testsimpleinlinemacro] []
beginParagraph
onWord [simpleinlinemacro7]
endParagraph
endMacroMarkerStandalone [testsimpleinlinemacro] []
endDocument

Notable problems:

  1. The format isn't just wrapped around "hi" but around the whole macro
  2. The macro with format after it is standalone and the format is instead wrapped around the next ("Padding") paragraph
  3. In the line with two macros, both macros are wrapped in the format instead of just the second one (same problem as with "hi", just to demonstrate with a macro instead of a word)
  4. The empty format at the end is ignored, the macro is standalone instead

For the first and third problem, I have found that the following patch works:

Index: xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java b/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java
--- a/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java	(revision aa207af9364de2ffa51c0e667ac423b79873ed26)
+++ b/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java	(date 1757671310318)
@@ -599,9 +599,12 @@
             fMacroName = macroName;
             fVerbatimContent = verbatimContent;
         }
-        openFormat();
+        // First check if we encountered a verbatim or macro that we can now process as inline.
+        // Then open whatever format we encountered. If the format was before the verbatim or macro, we would have
+        // immediately recognized both as inline and processed them already.
         checkVerbatim(true);
         checkMacro(true);
+        openFormat();
     }
 
     private void checkTableCell()

However, this patch doesn't fix the other problems, for those I'm currently not sure where we should produce or discard the format events.

As we're touching the parser here, all of those changes are also very dangerous.

 
cid:jira-generated-image-avatar-755d1a4b-c9ae-4dc9-9b29-a83fc6de7d8a Michael Hamann on 12/Sep/25 12:07
 
What I've reproduced so far is:

{noformat}
.runTransformations
.#-----------------------------------------------------
.input|xwiki/2.0
.#-----------------------------------------------------
{{testsimpleinlinemacro/}}(% id="test" %)hi

(% id="test" %){{testsimpleinlinemacro/}}

{{testsimpleinlinemacro/}}(% id="test" %)

Padding

{{testsimpleinlinemacro/}}(% id="test" %){{testsimpleinlinemacro/}}

{{testsimpleinlinemacro/}}(% id="test" %)
{noformat}

This results in the following event/1.0 output:

{noformat}
beginDocument
beginParagraph
beginFormat [NONE] [[id]=[test]]
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro2]
endMacroMarkerInline [testsimpleinlinemacro] []
onWord [hi]
endFormat [NONE] [[id]=[test]]
endParagraph
beginParagraph
beginFormat [NONE] [[id]=[test]]
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro3]
endMacroMarkerInline [testsimpleinlinemacro] []
endFormat [NONE] [[id]=[test]]
endParagraph
beginMacroMarkerStandalone [testsimpleinlinemacro] []
beginParagraph
onWord [simpleinlinemacro4]
endParagraph
endMacroMarkerStandalone [testsimpleinlinemacro] []
beginParagraph
beginFormat [NONE] [[id]=[test]]
onWord [Padding]
endFormat [NONE] [[id]=[test]]
endParagraph
beginParagraph
beginFormat [NONE] [[id]=[test]]
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro5]
endMacroMarkerInline [testsimpleinlinemacro] []
beginMacroMarkerInline [testsimpleinlinemacro] []
onWord [simpleinlinemacro6]
endMacroMarkerInline [testsimpleinlinemacro] []
endFormat [NONE] [[id]=[test]]
endParagraph
beginMacroMarkerStandalone [testsimpleinlinemacro] []
beginParagraph
onWord [simpleinlinemacro7]
endParagraph
endMacroMarkerStandalone [testsimpleinlinemacro] []
endDocument
{noformat}


Notable problems:

# The format isn't just wrapped around "hi" but
also wraps around the whole macro . This is closest to what's described in this issue.
# The macro with format after it is standalone and the format is instead wrapped around the next ("Padding") paragraph
# In the line with two macros, both macros are wrapped in the format instead of just the second one (same problem as with "hi", just to demonstrate with a macro instead of a word)
# The empty format at the end is ignored, the macro is standalone instead

For the first and third problem, I have found that the following patch works:

{code:java}
Index: xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java b/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java
--- a/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java (revision aa207af9364de2ffa51c0e667ac423b79873ed26)
+++ b/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/impl/InternalWikiScannerContext.java (date 1757671310318)
@@ -599,9 +599,12 @@
             fMacroName = macroName;
             fVerbatimContent = verbatimContent;
         }
-        openFormat();
+        // First check if we encountered a verbatim or macro that we can now process as inline.
+        // Then open whatever format we encountered. If the format was before the verbatim or macro, we would have
+        // immediately recognized both as inline and processed them already.
         checkVerbatim(true);
         checkMacro(true);
+        openFormat();
     }

     private void checkTableCell()
{code}

However, this patch doesn't fix the other problems, for those I'm currently not sure where we should produce or discard the format events.

As we're touching the parser here, all of those changes are also very dangerous.