Macro execute() method- renderContext.getOutputType() always returns "display"

Hi everyone,
I am currently developing a macro plugin for Jira Data-Center.
I want the Macro to display the text “Hello”, but when exporting the issue to word, I want the macro to render the following text: “Hello - word export”.

Looking at the documentation of RenderContext class: RenderContext (Atlassian Renderer 5.0 API) , and RenderContextOutputType (Atlassian Renderer 5.0 API), I assumed, that the renderContext.getOutputType() inside the execute() should return the output type, e.g: Word, PDF, XML, etc… But the function always returns the value: “display”, even when the issue is exported to Word.

atlassian-plugin.xml file:

<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <param name="plugin-icon">images/pluginIcon.png</param>
        <param name="plugin-logo">images/pluginLogo.png</param>
    </plugin-info>
    
    
    <macro key='hello' name='{hellol} formatting macro'
       class='com.keren.macros.HelloMacro'>
    	<description>Insert footer content with regards.</description>
    	<param name="convert-selector">div.hello-macro:not(.uml-img-ignore)</param>
    	<param name="convert-function">Plugin.Macros.Hello.convert</param>
	</macro>
	
	<web-resource key="handler3" name="JIRA Editor Reference Plugin Context Init">
    	<context>jira.rich.editor</context>
		<dependency>com.atlassian.jira.plugins.jira-editor-plugin:converter</dependency>
    	<resource name="soy/hello-macro.soy.js" type="download" location="soy/hello-macro.soy" />

    	<transformation extension="soy">
        	<transformer key="soyTransformer"/>
    	</transformation>
	</web-resource>
	
	
</atlassian-plugin>

HelloMacro.java class:

public class HelloMacro extends BaseMacro {


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

	@Override
	    public RenderMode getBodyRenderMode() {
			return RenderMode.allow(RenderMode.F_ALL).and(RenderMode.suppress(RenderMode.F_MACROS));
	    }

	    @Override
	    public String execute(Map<String, Object> parameters, String body, RenderContext renderContext) throws MacroException {
	    	
// This is always returning 'display'
	    	String outputType = renderContext.getOutputType();
	    	
	    	if( RenderContext.WORD.equals(outputType)) return "<h1>Hello: Word export</h1>";
	    	return "Hello";

	    }
}

hello-macro.soy:

{namespace Plugin.Macros.Hello}
/**
 * @param content
 */
{template .html}
    <hello-macro>{$content|noAutoescape}</hello-macro>
{/template}

/**
 * @param content
 */
{template .wiki}
    {lb}hello{rb}{$content}{lb}hello{rb}
{/template}

/**
 * @param innerMarkup
 */
{template .convert}
    {lb}hello{rb}{$innerMarkup}{lb}hello{rb}
{/template}

Right now, when I export the issue to Word, I see “Hello” in the issue description.
Can someone help me understand why the renderContext.getOutputType() always returning ‘display’ ?
I tried developing the same plugin for Confluence, and it works.

Thanks in advance!

1 Like