Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Unknown macro

Fabio Scagliola
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 8, 2013

Hello,

I developed a sample Confluence plugin including one very simple macro

Problem: the macro can only be included in a page through the macro browser and not within a Wiki Markup macro using "{MyMacro}" (I tried it lowercase too)

The following image shows the two instances of my macro in the same page: the one within the Wiki Markup macro displays the "Unknown macro: {MyMacro}" error

Here is the macro's source code

package ---.MyPlugin;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import java.util.Map;

public class MyMacro implements Macro {

    @Override
    public String execute(Map<String, String> map, String string, ConversionContext cc) throws MacroExecutionException {
        return "This is my macro!";
    }

    @Override
    public BodyType getBodyType() {
        return BodyType.NONE;
    }

    @Override
    public OutputType getOutputType() {
        return OutputType.BLOCK;
    }
}

Here is the only code I added to the atlassian-plugin.xml file

<xhtml-macro class="---.MyPlugin.MyMacro" key="MyMacro" name="MyMacro">
        <parameters />
    </xhtml-macro>

And, finally, here is the atlas-version output

ATLAS Version:    4.1.4
ATLAS Home:       C:\atlassian-plugin-sdk
ATLAS Scripts:    C:\atlassian-plugin-sdk\bin
ATLAS Maven Home: C:\atlassian-plugin-sdk\apache-maven
--------
Executing: "C:\atlassian-plugin-sdk\apache-maven\bin\mvn.bat" --version
Apache Maven 2.1.0 (r755702; 2009-03-18 20:10:27+0100)
Java version: 1.7.0_10
Java home: C:\Program Files\Java\jdk1.7.0_10\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 8" version: "6.2" arch: "amd64" Family: "windows"

Thank you in advance for you help!

Fabio

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 8, 2013

Wiki markup macros, and rich text editor macros are defined as two separate plugin modules. The xhtml-macro plugin module in your atlassian-plugin.xml is not recognised by the wiki markup rendering engine.

You need to have 2 modules declared in your atlassian-plugin.xml like this:

<xhtml-macro class="---.MyPlugin.MyMacro" key="MyMacro" name="MyMacro">
    <parameters />
</xhtml-macro>

<macro class="---.MyPlugin.MyMacro" key="MyMacro" name="MyMacro">
    <parameters />
</macro>

Additionally, you will need to edit the MyMacro class so that it also extends the com.atlassian.renderer.v2.macro.BaseMacro class, which is the base macro class for all wiki markup macros.

Hope this helps!

Fabio Scagliola
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 8, 2013

Thank you, Joseph

Not exactly straightforward to implement (I found some more info here), but that was the solution indeed

Only one remark: it appears that the values of the two key attributes in the atlassian-plugin.xml file need to be different

<xhtml-macro class="---.MyMacro" key="MyXhtmlMacro" name="MyMacro">
        <parameters />
    </xhtml-macro>

    <macro class="---.MyMacro" key="MyMacro" name="MyMacro">
        <parameters />
    </macro>

In case somebody needs it, here is the updated macro's source code

package ---.MyPlugin;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.renderer.RenderContext;
import com.atlassian.renderer.v2.RenderMode;
import com.atlassian.renderer.v2.macro.BaseMacro;
import com.atlassian.renderer.v2.macro.MacroException;
import java.util.Map;

public class MyMacro extends BaseMacro implements Macro {

    @Override
    public String execute(Map<String, String> map, String string, ConversionContext cc) throws MacroExecutionException {
        try {
            return execute(map, string, (RenderContext) null);
        } catch (MacroException ex) {
            throw new MacroExecutionException(ex);
        }
    }

    @Override
    public BodyType getBodyType() {
        return BodyType.NONE;
    }

    @Override
    public OutputType getOutputType() {
        return OutputType.BLOCK;
    }

    @Override
    public String execute(Map map, String string, RenderContext rc) throws MacroException {
        return "This is my macro!";
    }

    @Override
    public RenderMode getBodyRenderMode() {
        return RenderMode.NO_RENDER;
    }

    @Override
    public boolean hasBody() {
        return false;
    }
}

Thank you once more!

Fabio

TAGS
AUG Leaders

Atlassian Community Events