How to Convert XHTML to JIRA Markup and Vice Versa Using AtlassianRenderer?

I have developed a Java application that integrates with Jira, enabling users to create issues in the application’s format, which are then sent to the Jira Server. Conversely, users can initiate issues on the Jira Server, and these will be transferred back to the application. The problem is that the application stores issue descriptions in XHTML format, while Jira uses its own markup. Therefore, I require a conversion tool.

To address this, I opted for the com.atlassian.renderer:atlassian-renderer library, which simplifies the conversion from XHTML to Jira markup as follows:

private DefaultWysiwygConverter myConverter = new DefaultWysiwygConverter();
String jiraMarkup = myConverter.convertXHtmlToWikiMarkup(xhtmlContent);

However, I’m struggling with the reverse conversion, which is significantly more complicated. A direct call to convert back to XHTML results in an error:

String xhtmlContent = myConverter.convertWikiMarkupToXHtml(newJiraMarkup);

The DefaultWysiwygConverter requires an instance of WikiStyleRenderer, but the library does not provide a default implementation. Although there is a V2RendererFacade, its constructor necessitates four parameters, each of which requires specific implementations.

public V2RendererFacade(RendererConfiguration config, LinkRenderer linkRenderer, EmbeddedResourceRenderer resourceRenderer, Renderer renderer) {
    this.rendererConfiguration = config;
    this.defaultLinkRenderer = linkRenderer;
    this.defaultEmbeddedRenderer = resourceRenderer;
    this.renderer = renderer;
}

Is there a straightforward approach to achieve this conversion? Any practical examples would be greatly appreciated.

the hurdle with WikiStyleRenderer can be eased a bit using some implementations from the xhtml-to-jira library. try looking into any existing third-party plugins or libraries focusing on atlassian. sometimes, going through their resources or forums can yield solutions as users share custom implementations. good luck!

From my experience integrating Jira, one possible approach is to explore the Atlassian SDK, which might have some hidden gems in its older utility packages not immediately visible in documentation. If building custom parameters for the V2RendererFacade seems overwhelming, another solution is examining the modules available in the Atlassian Marketplace. There are plugins specifically designed for similar conversions. Have a look there, and you might find something that fits your need with less hassle. Setting up local test scripts to verify conversions can also help ensure your solutions are efficient and reliable when scaling.