diff --git a/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/main/java/org/xwiki/rendering/internal/macro/footnote/PutFootnotesMacro.java b/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/main/java/org/xwiki/rendering/internal/macro/footnote/PutFootnotesMacro.java index e125cc1ace..d068d53c61 100644 --- a/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/main/java/org/xwiki/rendering/internal/macro/footnote/PutFootnotesMacro.java +++ b/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/main/java/org/xwiki/rendering/internal/macro/footnote/PutFootnotesMacro.java @@ -41,6 +41,7 @@ import org.xwiki.rendering.block.ListItemBlock; import org.xwiki.rendering.block.MacroMarkerBlock; import org.xwiki.rendering.block.NumberedListBlock; +import org.xwiki.rendering.block.ParagraphBlock; import org.xwiki.rendering.block.SpaceBlock; import org.xwiki.rendering.block.WordBlock; import org.xwiki.rendering.block.match.MacroMarkerBlockMatcher; @@ -192,6 +193,7 @@ public List execute(FootnoteMacroParameters parameters, String content, M // Get the list of footnotes in the document macroMarkerBlocks.stream() .filter(macro -> FootnoteMacro.MACRO_NAME.equals(macro.getId())) + .map(PutFootnotesMacro::repairStandaloneFootnote) .map(Footnote::new) .forEach(footnote -> footnotes.put( Objects.requireNonNullElseGet(footnote.id, () -> String.valueOf(temporaryId.getAndIncrement())), @@ -228,6 +230,25 @@ public List execute(FootnoteMacroParameters parameters, String content, M return result; } + /** + * Repair a standalone footnote macro marker block by wrapping it in a paragraph if it is not already inline. + * + * @param macroMarkerBlock the macro marker block to repair + * @return the repaired macro marker block + */ + private static MacroMarkerBlock repairStandaloneFootnote(MacroMarkerBlock macroMarkerBlock) + { + if (macroMarkerBlock.isInline()) { + return macroMarkerBlock; + } else { + // Wrap the macro marker block in a paragraph and make it inline. + MacroMarkerBlock result = new MacroMarkerBlock(macroMarkerBlock.getId(), macroMarkerBlock.getParameters(), + macroMarkerBlock.getContent(), macroMarkerBlock.getChildren(), true); + macroMarkerBlock.getParent().replaceChild(new ParagraphBlock(List.of(result)), macroMarkerBlock); + return result; + } + } + /** * Collect and remove footnote contents from the given putFootnotes macro marker block. * diff --git a/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/test/resources/macrofootnote6.test b/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/test/resources/macrofootnote6.test index 2b1d5ea025..188a5d25ac 100644 --- a/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/test/resources/macrofootnote6.test +++ b/xwiki-rendering-macros/xwiki-rendering-macro-footnotes/src/test/resources/macrofootnote6.test @@ -2,6 +2,7 @@ .#----------------------------------------------------- .input|xwiki/2.0 .# Verify that several footnotes and putFootnotes markers work. +.# Also verify that standalone footnote macros are converted to inline macros in a paragraph. .#----------------------------------------------------- Footnote{{footnote}}content 1{{/footnote}} {{footnote}}content 2{{/footnote}} @@ -46,25 +47,30 @@ endFormat [SUPERSCRIPT] [[class]=[footnoteRef][id]=[x_footnote_ref_2]] endMacroMarkerInline [footnote] [] [content 2] endParagraph beginMacroMarkerStandalone [executedcontent] [] [{{footnote}}Inner footnote{{/footnote}}] -beginMacroMarkerStandalone [footnote] [] [Inner footnote] +beginParagraph +beginMacroMarkerInline [footnote] [] [Inner footnote] beginFormat [SUPERSCRIPT] [[class]=[footnoteRef][id]=[x_footnote_ref_1]] beginLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [x_footnote_1]]] [false] onWord [3] endLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [x_footnote_1]]] [false] endFormat [SUPERSCRIPT] [[class]=[footnoteRef][id]=[x_footnote_ref_1]] -endMacroMarkerStandalone [footnote] [] [Inner footnote] +endMacroMarkerInline [footnote] [] [Inner footnote] +endParagraph endMacroMarkerStandalone [executedcontent] [] [{{footnote}}Inner footnote{{/footnote}}] beginMacroMarkerStandalone [executedcontent] [] [{{footnote}}Second inner footnote{{/footnote}}] -beginMacroMarkerStandalone [footnote] [] [Second inner footnote] +beginParagraph +beginMacroMarkerInline [footnote] [] [Second inner footnote] beginFormat [SUPERSCRIPT] [[class]=[footnoteRef][id]=[x_footnote_ref_1-1]] beginLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [x_footnote_1-1]]] [false] onWord [4] endLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [x_footnote_1-1]]] [false] endFormat [SUPERSCRIPT] [[class]=[footnoteRef][id]=[x_footnote_ref_1-1]] -endMacroMarkerStandalone [footnote] [] [Second inner footnote] +endMacroMarkerInline [footnote] [] [Second inner footnote] +endParagraph endMacroMarkerStandalone [executedcontent] [] [{{footnote}}Second inner footnote{{/footnote}}] onEmptyLines [1] -beginMacroMarkerStandalone [footnote] [] [These are the footnotes: +beginParagraph +beginMacroMarkerInline [footnote] [] [These are the footnotes: {{putFootnotes/}} ] @@ -73,10 +79,11 @@ beginLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [x_footnote_5]]] onWord [5] endLink [Typed = [true] Type = [doc] Parameters = [[anchor] = [x_footnote_5]]] [false] endFormat [SUPERSCRIPT] [[class]=[footnoteRef][id]=[x_footnote_ref_5]] -endMacroMarkerStandalone [footnote] [] [These are the footnotes: +endMacroMarkerInline [footnote] [] [These are the footnotes: {{putFootnotes/}} ] +endParagraph beginMacroMarkerStandalone [putFootnotes] [] beginList [NUMBERED] [[class]=[footnotes]] beginListItem diff --git a/xwiki-rendering-standalone/src/test/java/org/xwiki/rendering/example/ExampleTest.java b/xwiki-rendering-standalone/src/test/java/org/xwiki/rendering/example/ExampleTest.java index f6078eab50..1e70bc24b3 100644 --- a/xwiki-rendering-standalone/src/test/java/org/xwiki/rendering/example/ExampleTest.java +++ b/xwiki-rendering-standalone/src/test/java/org/xwiki/rendering/example/ExampleTest.java @@ -164,8 +164,8 @@ public void executeAllBundledMacros() throws Exception + "

warning

" + "

error

" + "

bold

" - + "" - + "1" + + "

" + + "1

" + "
  1. " + "^" + " footnote
";