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.issue.fields.renderer.wiki.AtlassianWikiRenderer;
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.groups.GroupManager;



//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
sender="test@test.com"
sendername="Test Test"


//Email acccount credentials
def username="test@test.com"
def password="test"

//Gmail Default port
port = 25

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

//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");
mp.addBodyPart(htmlPart);

//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("mail.smtp.host", "smtp.gmail.com");
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.setSubject("Title");

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

try{
		Transport transport = session.getTransport("smtp");
		transport.connect( "smtp.gmail.com",port,username,password );
		transport.sendMessage(message,message.getAllRecipients());
		transport.close();
		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())		
		mex.printStackTrace();
}

1 answer

1 accepted

1 vote

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 http://www.i18nguy.com/markup/right-to-left.html?

If i use

<div dir="rtl">
$m_t_u
</div>

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

Using

<div align="right">
$m_t_u
</div>

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">
	  $m_t_u
	  </div>' else out << '<div>
	  $m_t_u
	  </div>'%>
"""

And the email i get is the following

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

' else out << '
test
tetetest
testtesttest

'%>

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 %>
'<div>$m_t_u</div>

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

240 views 1 18
Join discussion

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