This page last changed on Mar 16, 2006 by mryall.

Cannot resolve external resource into attachment. How do I convert wiki text to HTML?

This depends on where you want to do it:

In a macro...

You will need the SubRenderer (see how to retrieve it).

The SubRenderer has two render methods: one that allows you to specify a specific RenderMode for the rendered content, and another that uses the current RenderMode from the RenderContext.

If you just want the body of your macro rendered, you can have this done for you by the macro subsystem by having your macro's getBodyRenderMode method return the appropriate RenderMode.

In some other component...

You will need the WikiStyleRenderer (see how to retrieve a component).

The WikiStyleRenderer has a convertWikiToHtml method that takes the wiki text you wish to convert, and a RenderContext. If you are converting the text in the context of some ContentEntityObject (for example within a page or blog post), then you can call contentEntityObject.toPageContext() to retrieve its RenderContext. Otherwise pass in a new PageContext().

how would I do this in a vm file?

if I had

$thisstring = "some wiki marked up text"

is there some way to : $textToWiki($thisstring)

similar to how this works : $xHtmlComments.get($comment), except in that case, $comment is a comment object, and I just want to supply a string

Posted by umbi at Feb 15, 2006 14:38

Officially, there's no way of doing this, although you can use $renderBean.renderPage(spaceKey, pageTitle) to render the contents of an existing page.

Unofficially, you could try $helper.renderConfluenceMacro($thisstring) and see if it works.

Posted by cmiller at Feb 16, 2006 18:30

The "how to retreive it" links seem to refer to a non-existent anchor... perhaps they should refer to How do I get a reference to a component?

Posted by goresc at Mar 16, 2006 02:13

Link updated. Thanks for pointing that out.

Posted by mryall at Mar 16, 2006 21:37

Link is still broken, and the item on [How do I get a reference to a component?|
http://confluence.atlassian.com/pages/viewpage.action?pageId=157440] does not say how to actually get the wiki renderer from within a macro: is it wired or autowired ? does it come from the context ? if so what is the Java call ? or from the ContainerManager ? if so what is the name passed in the getComponent call ?

Mik

Posted by mik at Sep 22, 2006 03:51

Macro's are autowired, as mentioned on the page you refer to: any plugin module class named in atlassian-plugin.xml is.

Taking the example on that page and replacing SpaceManager with SubRenderer (keeping the case of the s) looks like this:

public void setSubRenderer(SubRenderer subRenderer)
{
    this.subRenderer = subRenderer;
}

You will clearly need to add a local field to your macro (the doc's assume a level of competancy):

private SubRenderer subRenderer;

You will be then free to use the subRenderer to render your content using the renderContext passed into the macro.

Posted by dhardiker@adaptavist.com at Sep 22, 2006 04:43

Thanks, that is much more useful.
We all have to start somewhere.

Mik

Posted by mik at Sep 22, 2006 07:34
Document generated by Confluence on Mar 22, 2007 20:59