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

2 votes
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?

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

344 views 20 10
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