Method to Convert Jira Wiki Format to HTML

Angela Borchard February 7, 2013

Hi,

Can you please advise how I can convert the Jira Wiki format into HTML? I am using the Jira Java Rest Client API.

I have obtained the field value as follows:

String BusinessNeedWikiFormat = jiraIssue.getFieldByName("Business Need").toString();

Sting BusinessNeedHtmlFormat = ?

Is there a method that I can use to convert this value into HTML?

Thanks,

-Angela

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
ConradR
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.
February 7, 2013
EventPublisher eventPublisher = ComponentAccessor.getOSGiComponentInstanceOfType(EventPublisher.class);
        VelocityRequestContextFactory velocityRequestContextFactory = ComponentAccessor.getOSGiComponentInstanceOfType(VelocityRequestContextFactory.class);
        AtlassianWikiRenderer wikiRenderer = new AtlassianWikiRenderer(eventPublisher, velocityRequestContextFactory);

        String html = wikiRenderer.render("*I am bold*", null);

Angela Borchard February 11, 2013

Oops sorry Conrad ;-)

Angela Borchard February 11, 2013

Hi Conrad,

Thank you very much for the information :-). I have implemented the code in my application however I am seeing the following error:

java.lang.IllegalStateException: ComponentAccessor has not been initialised.

It is failing on the following line:

EventPublisher eventPublisher = ComponentAccessor.getOSGiComponentInstanceOfType (EventPublisher.class);

Can you please advise how to resolve?

Brice Gestas _Elements_
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.
June 26, 2013

Thanks Conrad, it worked perfectly for me ;)

But AtlassianWikiRenderer is provided by jira-core and it is not a good way to work...

Hope Atlassian will expose a public method to get HTML from wiki content :P

Randee024 February 14, 2018

hi can someone help me with AtlassianWikiRenderer cannot find this method. but i already imported import com.atlassian.jira.issue.fields.renderer.wiki.AtlassianWikiRenderer

here is my code

import java.lang.*
import javax.mail.internet.*;
import javax.mail.*
import javax.activation.*
import javax.mail.Multipart;

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.attachment.Attachment;
import com.atlassian.jira.issue.AttachmentManager;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.util.AttachmentUtils;
import com.atlassian.jira.util.PathUtils;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.gzipfilter.org.apache.commons.lang.StringUtils
import groovy.text.GStringTemplateEngine;
import com.atlassian.event.api.EventPublisher
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory
import com.atlassian.jira.issue.fields.renderer.wiki.AtlassianWikiRenderer
import com.atlassian.jira.issue.fields.renderer.JiraRendererPlugin
import org.springframework.beans.factory.DisposableBean

 

 

 

EventPublisher eventPublisher = ComponentAccessor.getOSGiComponentInstanceOfType(EventPublisher.class);
VelocityRequestContextFactory velocityRequestContextFactory = ComponentAccessor.getOSGiComponentInstanceOfType(VelocityRequestContextFactory.class);
AtlassianWikiRenderer wikiRenderer = new AtlassianWikiRenderer(eventPublisher, velocityRequestContextFactory);

0 votes
Preet February 17, 2013

Hi Conard

How can we access the AtlassianWikiRenderer ? I am using .NET client for Rest API via webservice reference but the AtlassianWikiRenderer is not available also I have tried the Atlassian SDK library for .NET but that too does not provide the AtlassianWikiRenderer functionality.

Can you please tell me how can I utilize this functionality in .NET application?

Like Angela; My intention is to convert the wiki format text received from the api to html.

Thanks a lot

Best Regards,

Sp

ConradR
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.
February 17, 2013

There is an undocumented rest resource:

/rest/api/1.0/render

Body:

{"rendererType":"atlassian-wiki-renderer","unrenderedMarkup":"*test*"}

Response:

<p><b>test</b></p>

This resource is used by Jira when you click the preview button in wiki-renderer fields.

Rui Rodrigues
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.
August 3, 2016

Hi Conrad,

Is this working?

Thank you.

Rui Rodrigues
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.
August 3, 2016

Hi again.

It's working fine.

 

Rui Rodrigues
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.
August 4, 2016

There is a problem with that REST service. On JIRA Cloud it doesn't work with JWT token authentication. So, there is an issue opened since 2014 and nothing was made until now.

 

You can see it here: https://jira.atlassian.com/browse/JRA-38731.

Thanks.

Suman Jha March 30, 2018

Conrand,

Does below code will extract all the Description with color / Table everything.

My challenge is not able to get the Images from Story, I am trying to convert Images from JIRA to my JAVA application.

Please help I am stuck from many days.

EventPublisher eventPublisher = ComponentAccessor.getOSGiComponentInstanceOfType(EventPublisher.class);
        VelocityRequestContextFactory velocityRequestContextFactory = ComponentAccessor.getOSGiComponentInstanceOfType(VelocityRequestContextFactory.class);
        AtlassianWikiRenderer wikiRenderer = new AtlassianWikiRenderer(eventPublisher, velocityRequestContextFactory);

        String html = wikiRenderer.render("*I am bold*", null);


TAGS
AUG Leaders

Atlassian Community Events