Confluence Macro: Output Wiki Markup?

Alex Church July 11, 2011

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
Answer accepted
Paul Curren
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 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);

Alex Church September 14, 2011

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?

0 votes
Azwandi Mohd Aris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2011

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

Alex Church July 12, 2011

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
TAGS
AUG Leaders

Atlassian Community Events