How to apply text alignment for converted jira wiki markup text to html?

Hi everybody,

i'm using JIRA as a helpdesk system. In the workflow we have transitions where user can send email with a custom groovyrunner postfunction. In the post function we convert JIRA wiki markup to html. For Right To Left languages (Arabic, etc) we want to alligh text on the right. I have tried some things by the text allignment does not apply.

Thank you in advance

The code i'm using is the following

import javax.mail.internet.*;
import javax.mail.*
import javax.activation.*
import javax.mail.Multipart;
import javax.mail.internet.MimeMultipart;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
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.history.ChangeItemBean;
import com.atlassian.jira.util.AttachmentUtils;
import groovy.text.GStringTemplateEngine;
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.component.ComponentAccessor;

//Convert wiki markup to HTML
EventPublisher eventPublisher = ComponentAccessor.getOSGiComponentInstanceOfType(EventPublisher.class);
VelocityRequestContextFactory velocityRequestContextFactory = ComponentAccessor.getOSGiComponentInstanceOfType(VelocityRequestContextFactory.class);
AtlassianWikiRenderer wikiRenderer = new AtlassianWikiRenderer(eventPublisher, velocityRequestContextFactory);

def groupManager = ComponentAccessor.getGroupManager()

def currentUser = componentManager.jiraAuthenticationContext?.user

//Get Comment Manager
CommentManager commentManager = componentManager.getCommentManager();

//Get custom field manager
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();

//Get custom field email by id
CustomField customField_email = customFieldManager.getCustomFieldObject( 10205 );

CustomField customField_mtu = customFieldManager.getCustomFieldObject( 11000 );

//get value of customField_email
to = issue.getCustomFieldValue( customField_email )

//get value of customField_mtu
mtu = issue.getCustomFieldValue( customField_mtu ).toString();

//Convert JIRA wiki to HTML
m_t_u = wikiRenderer.render(mtu, null);

//Email Headers
sendername="Test Test"

//Email acccount credentials
def username=""
def password="test"

//Gmail Default port
port = 25

//Email Body
content = """\
<div align="right">

//Creat first part of email, Email Body

Multipart mp = new MimeMultipart("mixed");

MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(content.toString(), "text/html; charset=utf-8");

//Email Properties

props = new Properties()

props.put("mail.smtp.port", port);
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.quitwait", "false");
props.put("", "");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");

//New session

Session session = Session.getInstance(props,
		  new javax.mail.Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username, password);

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender,sendername));

message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

		Transport transport = session.getTransport("smtp");
		transport.connect( "",port,username,password );
		log.warn ("mail sent sucesfully to : "+ issue.getCustomFieldValue( customField_email).toString() + ", for issue: " + issue.getKey())

}catch (MessagingException mex) {
		log.warn ("Could not sent email to : "+ issue.getCustomFieldValue( customField_email).toString() + " for issue: " + issue.getKey())		

1 answer

1 accepted

Interesting... do you think this this an HTML problem or an issue with i18n in jira?

How does it look when you view RTL languages in the browser, is it correct?

If it's an HTML issue have you tried using the dir attrib as per

If i use

<div dir="rtl">

in code the text is alligned on the right. I have just tested it.


<div align="right">

has exactly the same results.

Finally, it was not an HTML problem nor a i18n in JIRA. I was using wrong script in post function. :(

Thanks for the help

I'm trying to add a conditional expression in email's body but in email i get printed the conditional expression also.

what i use is the following

content = """\

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") out << '<div dir="rtl">
	  </div>' else out << '<div>

And the email i get is the following

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") out << '

' else out << '


Any idea what's wrong in the syntax i use?

Thanx in advance

I think it should be like this:

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") %>
	'<div dir="rtl">$m_t_u
<% else %>

I have tried your suggestion but it seems that the way the syntax is ignores the condition. Html works though.

The condition i have used is the following

<% if (issue.getCustomFieldValue( customField_language ).toString() == "Arabic") %>
    '<div dir="rtl">$m_t_u</div>
<% else %>

The result i get is in the next screenshot

I have tried different modifications, without luck.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Jira

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,081 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you