/** * {@inheritDoc} * * @see org.xwiki.rendering.listener.Listener#onMacro(java.lang.String, java.util.Map, java.lang.String, boolean) */ public void onMacro(String id, Map<String, String> macroParameters, String content, boolean isInline) { this.stack.push(new MacroBlock(id, macroParameters, content, isInline)); }
/** * @see #onMacroBlock(String, org.wikimodel.wem.WikiParameters, String) */ public void onMacroInline(String macroName, WikiParameters params, String content) { this.stack.push(new MacroBlock(macroName, convertParameters(params), content, true)); }
/** * A macro block was found and it's separated at least by one new line from the next block. If there's no new line * with the next block then wikimodel calls {@link #onMacroInline(String, org.wikimodel.wem.WikiParameters, String)} * instead. * <p> * In wikimodel block elements can be: * <ul> * <li>at the very beginning of the document (no "\n")</li> * <li>just after at least one "\n"</li> * </ul> */ public void onMacroBlock(String macroName, WikiParameters params, String content) { this.stack.push(new MacroBlock(macroName, convertParameters(params), content, false)); }
@Override public List<Block> execute(FootnoteMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { Block root = context.getXDOM(); Block matchingBlock = root.getFirstBlock(MACRO_BLOCK_MATCHER, Block.Axes.DESCENDANT); if (matchingBlock != null) { return Collections.emptyList(); } Block putFootnotesMacro = new MacroBlock(PutFootnotesMacro.MACRO_NAME, Collections.<String, String>emptyMap(), false); root.addChild(putFootnotesMacro); return Collections.emptyList(); } }
/** * @param xdom the {@link XDOM} to convert * @return an inline version of the passed {@link XDOM} */ private XDOM convertToInline(XDOM xdom) { List<Block> blocks = new ArrayList<Block>(xdom.getChildren()); // TODO: use inline parser instead if (!blocks.isEmpty()) { this.parserUtils.removeTopLevelParagraph(blocks); // Make sure included macro is inline when script macro itself is inline Block block = blocks.get(0); if (block instanceof MacroBlock) { MacroBlock macro = (MacroBlock) block; if (!macro.isInline()) { blocks.set(0, new MacroBlock(macro.getId(), macro.getParameters(), macro.getContent(), true)); } } xdom.setChildren(blocks); } return xdom; }
/** * Clone and filter wiki macro content depending of the context. * * @param context the macro execution context * @return the cleaned wiki macro content */ private XDOM prepareWikiMacroContent() { XDOM xdom = this.wikimacro.getContent().clone(); // Macro code segment is always parsed into a separate xdom document. Now if this code segment starts with // another macro block, it will always be interpreted as a block macro regardless of the current wiki macro's // context (because as far as the nested macro is concerned, it starts on a new line). This will introduce // unnecessary paragraph elements when the wiki macro is used inline, so we need to force such opening macro // blocks to behave as inline macros if the wiki macro is used inline. if (this.inline) { List<Block> children = xdom.getChildren(); if (!children.isEmpty() && children.get(0) instanceof MacroBlock) { MacroBlock old = (MacroBlock) children.get(0); MacroBlock replacement = new MacroBlock(old.getId(), old.getParameters(), old.getContent(), true); xdom.replaceChild(replacement, old); } } return xdom; }
result.set(0, new MacroBlock(macro.getId(), macro.getParameters(), macro.getContent(), true));
result.set(0, new MacroBlock(macro.getId(), macro.getParameters(), macro.getContent(), true));