To convert wiki text to HTML, you will need the XhtmlContent (see how to retrieve it).
The XhtmlContent
has convertWikiToView()
method. See the following examples on how to use it.
To convert wiki text to HTML in a macro, do the following:
1 2public String execute(Map<String, String> map, String s, ConversionContext conversionContext) throws MacroExecutionException { String wiki = "## Some wiki"; String xhtml = ""; try { xhtml = xhtmlContent.convertWikiToView(wiki, conversionContext, new ArrayList<>()); } catch (XMLStreamException | XhtmlException e) { e.printStackTrace(); } return xhtml; }
If you don't have ConversionContext
, you can pass DefaultConversionContext
, which takes RenderContext
as an argument.
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()
.
For example:
1 2public String someMethod() { String wiki = "## Some wiki"; String xhtml = ""; try { xhtml = xhtmlContent.convertWikiToView(wiki, new DefaultConversionContext(new PageContext()), new ArrayList<>()); } catch (XMLStreamException | XhtmlException e) { e.printStackTrace(); } return xhtml; }
Rate this page: