Skip to content
Snippets Groups Projects
Unverified Commit 423f3cd4 authored by Michael Hamann's avatar Michael Hamann Committed by GitHub
Browse files

XWIKI-22056: Inserted icons on each line via Quick Actions are merged into one...

XWIKI-22056: Inserted icons on each line via Quick Actions are merged into one line in view mode (#3145)

* Always ask for inline icons and wrap the icon in a paragraph if
  necessary to ensure that in standalone mode all icons are actually
  standalone.
* Add a test.
parent 954c5107
No related branches found
No related tags found
No related merge requests found
......@@ -110,5 +110,11 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.xwiki.rendering</groupId>
<artifactId>xwiki-rendering-macro-html</artifactId>
<version>${rendering.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
......@@ -40,6 +40,7 @@
import org.xwiki.rendering.async.internal.AbstractExecutedContentMacro;
import org.xwiki.rendering.async.internal.block.BlockAsyncRendererConfiguration;
import org.xwiki.rendering.block.Block;
import org.xwiki.rendering.block.ParagraphBlock;
import org.xwiki.rendering.block.XDOM;
import org.xwiki.rendering.listener.MetaData;
import org.xwiki.rendering.macro.MacroExecutionException;
......@@ -156,8 +157,14 @@ private XDOM parseIcon(DisplayIconMacroParameters parameters, MacroTransformatio
metaData = new MetaData(Map.of(MetaData.SOURCE, stringReference));
}
return this.parser.parse(iconContent, Syntax.XWIKI_2_1, context, false, metaData,
context.isInline());
XDOM iconXDOM = this.parser.parse(iconContent, Syntax.XWIKI_2_1, context, false, metaData, true);
if (!context.isInline()) {
// Wrap the children of the XDOM in a paragraph. We don't ask the parser to produce block content as
// icons should always be inline, and some icons are defined as raw inline HTML.
Block wrapper = new ParagraphBlock(iconXDOM.getChildren());
iconXDOM.setChildren(List.of(wrapper));
}
return iconXDOM;
}
private IconSet getIconSet(DisplayIconMacroParameters parameters) throws IconException, MacroExecutionException
......
......@@ -72,6 +72,8 @@ public void initialize(MockitoComponentManager componentManager) throws Exceptio
componentManager.registerMockComponent(ContextualAuthorizationManager.class);
// Grant view right on the icon document.
when(authorizationManager.hasAccess(Right.VIEW, ICON_DOCUMENT_REFERENCE)).thenReturn(true);
// Grant script right to disable restricted cleaning in the HTML macro.
when(authorizationManager.hasAccess(Right.SCRIPT)).thenReturn(true);
componentManager.registerMockComponent(AuthorizationManager.class);
// Mock the icon set cache as it fails.
......@@ -118,6 +120,13 @@ private void setupIconThemes(IconSetManager iconSetManager) throws IconException
documentIconSet.setSourceDocumentReference(new DocumentReference(ICON_DOCUMENT_REFERENCE));
when(iconSetManager.getIconSet("document")).thenReturn(documentIconSet);
// An icon theme that uses the HTML macro to display the icon
IconSet htmlSet = new IconSet("html");
htmlSet.addIcon("home", new Icon("htmlHome"));
htmlSet.setRenderWiki("{{html clean=\"false\"}}<span class=\"fa fa-$icon\" aria-hidden=\"true\"></span>"
+ "{{/html}}");
when(iconSetManager.getIconSet("html")).thenReturn(htmlSet);
// The default icon set to test fallback to the default when the current or specified icon set doesn't
// contain an icon.
IconSet defaultSet = new IconSet("default");
......
......@@ -165,8 +165,10 @@ void fallbackWhenAccessDenied() throws MacroExecutionException, IconException
IconSet defaultIconSet = mock(IconSet.class);
when(this.iconSetManager.getDefaultIconSet()).thenReturn(defaultIconSet);
MacroTransformationContext context = new MacroTransformationContext();
context.setInline(true);
List<Block> result =
this.displayIconMacro.execute(this.displayIconMacroParameters, null, new MacroTransformationContext());
this.displayIconMacro.execute(this.displayIconMacroParameters, null, context);
assertEquals(result, List.of(new MetaDataBlock(List.of(new WordBlock("home")))));
verify(this.iconRenderer).render("home", defaultIconSet);
verifyNoInteractions(this.documentContextExecutor);
......@@ -192,8 +194,10 @@ void executesInContext() throws Exception
{
when(this.contextualAuthorizationManager.hasAccess(Right.VIEW, ICON_DOCUMENT_REFERENCE)).thenReturn(true);
MacroTransformationContext context = new MacroTransformationContext();
context.setInline(true);
List<Block> result =
this.displayIconMacro.execute(this.displayIconMacroParameters, null, new MacroTransformationContext());
this.displayIconMacro.execute(this.displayIconMacroParameters, null, context);
assertEquals(result, List.of(new MetaDataBlock(List.of(new WordBlock("home")))));
verify(this.documentContextExecutor).call(any(), eq(this.iconDocument));
}
......
.runTransformations
.#-----------------------------------------------------
.input|xwiki/2.1
.# Verify that icons using HTML are correctly displayed in inline and standalone contexts
.#-----------------------------------------------------
{{displayIcon name="home" iconSet="html" /}}
Inline: {{displayIcon name="home" iconSet="html" /}}
.#-----------------------------------------------------
.expect|event/1.0
.#-----------------------------------------------------
beginDocument
beginMacroMarkerStandalone [displayIcon] [name=home|iconSet=html]
beginMetaData [[syntax]=[XWiki 2.1]]
beginParagraph
beginMacroMarkerInline [html] [clean=false] [<span class="fa fa-htmlHome" aria-hidden="true"></span>]
onRawText [<span class="fa fa-htmlHome" aria-hidden="true"></span>] [html/5.0]
endMacroMarkerInline [html] [clean=false] [<span class="fa fa-htmlHome" aria-hidden="true"></span>]
endParagraph
endMetaData [[syntax]=[XWiki 2.1]]
endMacroMarkerStandalone [displayIcon] [name=home|iconSet=html]
beginParagraph
onWord [Inline]
onSpecialSymbol [:]
onSpace
beginMacroMarkerInline [displayIcon] [name=home|iconSet=html]
beginMetaData [[syntax]=[XWiki 2.1]]
beginMacroMarkerInline [html] [clean=false] [<span class="fa fa-htmlHome" aria-hidden="true"></span>]
onRawText [<span class="fa fa-htmlHome" aria-hidden="true"></span>] [html/5.0]
endMacroMarkerInline [html] [clean=false] [<span class="fa fa-htmlHome" aria-hidden="true"></span>]
endMetaData [[syntax]=[XWiki 2.1]]
endMacroMarkerInline [displayIcon] [name=home|iconSet=html]
endParagraph
endDocument
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment