use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecute.
// Tests
/**
* Test normal wiki macro execution.
*/
@Test
public void testExecute() throws Exception {
registerWikiMacro("wikimacro1", "This is **bold**", Syntax.XWIKI_2_0);
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
converter.convert(new StringReader("{{wikimacro1 param1=\"value1\" param2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<p>This is <strong>bold</strong></p>", printer.toString());
Assert.assertFalse(this.xcontext.containsKey("macro"));
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecuteWhenWikiMacroDirectlyProvideTheResult.
/**
* A wiki macro can directly provide the list of blocks instead of having to render them to let
* {@link DefaultWikiMacro} re-parse it.
*/
@Test
public void testExecuteWhenWikiMacroDirectlyProvideTheResult() throws Exception {
registerWikiMacro("wikimacrowithresult", "{{groovy}}" + "xcontext.macro.result = java.util.Collections.singletonList(new org.xwiki.rendering.block.WordBlock(xcontext.macro.params.param1));" + "{{/groovy}}", Syntax.XWIKI_2_0);
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
// Note: We're putting the macro after the "Hello" text to force it as an inline macro.
converter.convert(new StringReader("Hello {{wikimacrowithresult param1=\"World\" param2=\"param2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<p>Hello World</p>", printer.toString());
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testGetCurrentMacroBlock.
@Test
public void testGetCurrentMacroBlock() throws Exception {
registerWikiMacro("wikimacro", "{{groovy}}" + "println xcontext.macro.context.getCurrentMacroBlock().id\n" + "println xcontext.macro.context.getCurrentMacroBlock().parent.class\n" + "println xcontext.macro.context.getCurrentMacroBlock().nextSibling.children[0].word\n" + "println xcontext.macro.context.getCurrentMacroBlock().previousSibling.children[0].word\n" + "{{/groovy}}", Syntax.XWIKI_2_0, Collections.<WikiMacroParameterDescriptor>emptyList());
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
converter.convert(new StringReader("before\n\n{{wikimacro/}}\n\nafter"), Syntax.XWIKI_2_0, Syntax.PLAIN_1_0, printer);
Assert.assertEquals("before" + "\n\n" + "wikimacro\n" + "class org.xwiki.rendering.block.XDOM\n" + "after\n" + "before" + "\n\n" + "after", printer.toString());
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testExecuteWhenWithDifferentMacroSyntax.
/**
* Check that macro used inside wiki macro are executed with the right syntax.
*/
@Test
public void testExecuteWhenWithDifferentMacroSyntax() throws Exception {
registerWikiMacro("wikimacro", "{{groovy}}println \"[[path:/some/path]]\"{{/groovy}}", Syntax.XWIKI_2_1);
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
converter.convert(new StringReader("{{wikimacro param1=\"value1\" param2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.XHTML_1_0, printer);
// Note: We're using XHTML as the output syntax just to make it easy for asserting.
Assert.assertEquals("<p><span class=\"wikiinternallink\"><a href=\"/some/path\">" + "<span class=\"wikigeneratedlinkcontent\">/some/path</span></a></span></p>", printer.toString());
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultContextualLocalizationManager method getTranslationPlain.
@Override
public String getTranslationPlain(String key, Object... parameters) {
Translation translation = getTranslation(key);
if (translation == null) {
return null;
}
Block block = translation.render(parameters);
DefaultWikiPrinter wikiPrinter = new DefaultWikiPrinter();
this.plainRenderer.render(block, wikiPrinter);
return wikiPrinter.toString();
}
Aggregations