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:
com.atlassian.confluence.xhtml
classes aren't available.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!
Community moderators have prevented the ability to post new answers.
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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.