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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

88 views 0 6
Read article

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