Writing a custom macro for the JIRA Wiki Renderer

Felix Dreissig June 29, 2015

I want to write a very basic custom macro for JIRA text fields. From my understanding, these are basically Confluence macros, but I can't find any information on how to develop and deploy them with focus on JIRA.

Here's what I've tried so far:

  • Writing a Confluence 4.x+ macro as described in Creating a New Confluence Macro and building it as Confluence plugin: This works with Confluence, but when I package it and install it in JIRA, it doesn't appear in the list of Wiki Renderers like mentioned in Configuring Macro Plugins for the Wiki Style Renderer.
  • Writing a Confluence 4.x+ macro and building it as JIRA plugin: Doesn't work because (ursurprisingly) the com.atlassian.confluence.xhtml classes aren't available.
  • Writing an "old-style" Confluence macro as describe by Writing Macros and building it as Confluence plugin: Compiles and can be installed, but cannot be loaded due to errors in Confluence as well as JIRA.
  • Writing an "old-style" Confluence macro and building it as JIRA plugin: Doesn't work as to the  com.atlassian.renderer.v2.macro classes are missing.

Has anyone been successful in writing a custom macro for JIRA or using one from Confluence? Thanks in advance!

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
filiprogaczewski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 13, 2015

Felix, there is a plugin point in JIRA called macro, which allows users to format elements of text fields such as code blocks or quotes. 

I am attaching the code for macro which reverses the text:

<macro name="Reverse Macro" key='reverse' i18n-name-key="module.macro.name"
       class="ReverseMacro">
    <description key="module.macro.description">Macro that reverses input text</description>
</macro>
public class ReverseMacro extends com.atlassian.renderer.v2.macro.BaseMacro
{
    public boolean isInline()
    {
        return true;
    }

    public boolean hasBody()
    {
        return true;
    }

    public RenderMode getBodyRenderMode()
    {
        return RenderMode.INLINE;
    }

    public String execute(Map map, String body, RenderContext renderContext) throws MacroException
    {
        return StringUtils.reverse(body);
    }
}

Hope it helps!

Felix Dreissig July 20, 2015

Thanks for your answer. This basically matches my third strategy from above, although for some reason I couldn't get it working back then and now I can, at least to some degree: However, I am still having trouble actually using the macro in JIRA: It works fine in Confluence and when I install it in JIRA, it reports "3 of 3 modules enabled". But the macro still doesn't show up in the Wiki Renderer list as mentioned by the "Configuring Macro Plugins for the Wiki Style Renderer" paragraph linked above. The question is: Should external macros appear in that list at all, or only the built-ins? Since the add-on is now fully active, I also tried just using it through the `{reverse:arg=foo}` syntax in text fields, but that didn't work either.

0 votes
filiprogaczewski
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2015

Wiki-renderer is a different JIRA module. This is jira-renderer, have a look at the following module:

<jira-renderer key="some-renderer" name="Some Renderer"
    i18n-name-key="sme.renderer"
    class="SomeRenderer">
    <description key="admin.renderer.plugin.wiki.renderer.desc">A renderer that will render wiki style syntax into html markup.</description>
    <resource type="velocity" name="edit" location="templates/some-renderer.vm"/>
</jira-renderer>

SomeRenderer is an implementation of com.atlassian.jira.issue.fields.renderer.JiraRendererPlugin

On which list would you like your macro to appear? BTW, I think the proper syntax for your macro would be 

{reverse} reverse string {reverse}

Felix Dreissig July 20, 2015

According to https://confluence.atlassian.com/display/JIRA/Configuring+Renderers, JIRA uses the "Wiki Style Renderer" for text fields, which support Confluence macros. In the bottom of that page, there is documentation on "Configuring Macro Plugins for the Wiki Style Renderer". It says macros can be enabled or disabled through the "Wiki Renderer Macros Plugin". This is the list I'm referring to. I ask myself whether a custom macro should show up in that list or just work once it's enabled. You're right about the syntax for the "reverse" macro, but my macro doesn't have a body. So I think you just need to enter it once. It probably wasn't that clever to re-use the name form your example.

TAGS
AUG Leaders

Atlassian Community Events