Confluence Macro: Output Wiki Markup?

Is it possible for plugin macros to return wiki markup as user macros do? I have tried outputting wiki markup but it just renders as plain text.

2 answers

1 accepted

This widget could not be displayed.
Paul Curren Atlassian Team Sep 13, 2011

If the output of your macro is intended for display in a browser (as most are) then it is required to output HTML.

I guess you are asking if you, as the developer can write wiki markup and have it converted to HTML. This is possible but may well be an unnecessary over-head. Is this wiki content dynamic? If not you are much better to just write your HTML output directly.

Anyway, if you do want to convert wiki to XHTML then you will need to inject a com.atlassian.renderer.WikiStyleRenderer to your macro. e.g.

public void setWikiStyleRenderer(WikiStyleRenderer wikiStyleRenderer)
{
    this.wikiStyleRenderer = wikiStyleRenderer;
}

You can then convert your wiki with something like -

return getWikiStyleRenderer().convertWikiToXHtml(new PageContext(), wiki);

You are right - I do the wiki markup to be output as HTML in a browser. I was intending to use existing macros for formatting, to save replicating the HTML they use. It most certainly will be using dynamic content. I will re-assess my needs - you may be right in that it may be unecessary overhead.

What is the 'wiki' variable passed as the second argument to convertWikiToXHtml()? Is that a string containing the wiki markup?

This widget could not be displayed.

Have you tried setting the render mode to RenderMode.NO_RENDER?

If you mean using:

public RenderMode getBodyRenderMode() {

return RenderMode.NO_RENDER;

}

then yes, I have. This does not work, and if I understand the documentation correctly, it describes how the body of the macro - the code between the start and end tags - is to be processed, not the final output of the macro.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

409 views 4 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you