Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert HTML into JIRA format C#.Net

Kapil Soni July 20, 2020

Hi @Nir Haimov 

 

Can you please help me that how to convert from HTML into JIRA format using C# or javascript?

5 answers

0 votes
Milind Suresh Nikam September 2, 2021

Hello @Nir Haimov

I am using the html-2-jira-markup  nuget package manager.  But facing the problem with ul, ol tag. Can you please suggest is there way to resolve this.

Nir Haimov
Community Champion
September 2, 2021

Hi @Milind Suresh Nikam 

Please share the HTML string you are trying to convert and the output converted string you get

Milind Suresh Nikam September 2, 2021

Hello @Nir Haimov

Html String

<b>From</b>: Test \\\\<b>To</b>: Test \\\\<b>Subject</b>: Test for Bullet points \\\\<b>Email Body</b>: <p>Hello,</p><p>&nbsp;</p><p>This is a<strong> test email.</strong></p><ul><li>test</li><li>test</li></ul><p><strong>checking below:</strong></p><ol><li>test</li><li>test</li></ol><p>Thank you,</p><p>&nbsp;</p><p><strong>Test </strong><i>Test<strong> </strong>Test</i></p><p>Test</p>

Nir Haimov
Community Champion
September 2, 2021

@Milind Suresh Nikam and what string you get when you try to convert this?

Also, why you have multiple \\\\ in your HTML string?

Milind Suresh Nikam September 2, 2021

Hello @Nir Haimov

I am using this for commenting email subject and body into jira comment. so after subject i want new line so i have added \\

Nir Haimov
Community Champion
September 2, 2021

ok @Milind Suresh Nikam i will check it out

Nir Haimov
Community Champion
September 2, 2021

instead of adding \\\\ use html tag <br>

Milind Suresh Nikam September 2, 2021

Thank you @Nir Haimov 

Nir Haimov
Community Champion
September 3, 2021

new version 1.0.4 published with a fix

Like Patrick Le Garrec likes this
Milind Suresh Nikam September 3, 2021

 

Hello @Nir Haimov 

It work's. Thank you for quick response

0 votes
Nir Haimov
Community Champion
August 18, 2021
0 votes
Patrick Le Garrec August 18, 2021

Hi, this does not work for me:

original string :

<p>Le prix total d&#39;un computer ne peux jamais d&eacute;passer 1000 $<br />
Le contr&ocirc;le est effectu&eacute; sur la page caddie.</p>

 

after using Jira markup Html2JiraMarkup, here is the converted string :

\ \Le prix total d&#39;un computer ne peux jamais d&eacute;passer 1000 $<br />\Le contr&ocirc;le est effectu&eacute; sur la page caddie.\


REST Error 400

After doing this :

private static string CleanStringDescription(string str)
{
string s = HttpUtility.HtmlDecode(str);
string cleanStr;
cleanStr = Regex.Replace(s, @"\n", "");
cleanStr = Regex.Replace(cleanStr, @"\r", "");
cleanStr = Regex.Replace(cleanStr, @"\t", "");
cleanStr = Regex.Replace(cleanStr, @"<p>", "");
cleanStr = Regex.Replace(cleanStr, @"</p>", "");
cleanStr = Regex.Replace(cleanStr, @"<br />", "");

return cleanStr;
}

 

It works ! 

Le prix total d'un computer ne peux jamais dépasser 1000 $Le contrôle est effectué sur la page caddie.

 

I hope this help.



Nir Haimov
Community Champion
August 18, 2021

Hi @Patrick Le Garrec 

except for the <br /> that i will fix, there is nothing to do with Html2JiraMarkup to "REST Error 400"

If the API fails for you that because something you are not doing right.

In worst case, Html2JiraMarkup will convert partial of the HTML string but the still the string will be post to Jira, even if you just send HTML as is to Jira, it will post it, and you will see all the HTML tags in your Jira field, so in any case this should not fail in API, unless you are doing something wrong, and it's not related to the conversion of the HTML string

Patrick Le Garrec August 18, 2021

Yes, you are right.

i edit the post to share the way i fixed the issue. 

Nir Haimov
Community Champion
August 18, 2021

I updated the Html2JiraMarkup package, so now your <br /> will be changed

Like Patrick Le Garrec likes this
Patrick Le Garrec August 18, 2021

i edit the post to share the way i fixed the issue. 
The string is taken from the debugger on local (text format), just after the use of the lib, 


and finaly, got a rest error with the wrong string.


The only way i found is to use the HttpUtility shipped with .Net framework.

Patrick Le Garrec August 18, 2021

Thanks Nir :)   you are very reactive 

0 votes
Kapil Soni July 19, 2021

Hi @Nir Haimov 

 

can you please try to create and publish for .Net Core so that would be great as of now .Net core is more usable than standard one and thank you so much for looking into this.

Nir Haimov
Community Champion
July 19, 2021

Hi @Kapil Soni 

I will try to to create something, but can't promise anything, i might be able to create a solution only for part of the conversion from HTML to Jira and not all of it.

I will do my best and keep you update

Kapil Soni July 19, 2021

Hi @Nir Haimov 

 

Thank you so much for quick prompt and its enough for all of us to convert HTML to Jira. Meanwhile day after will post my solution here which covers around 95% HTML to Jira convert using javascript/jQuery.

Nir Haimov
Community Champion
July 20, 2021

Hi @Kapil Soni @faisalamdani @Michael Cowan @Noah Povis 

I create a nuget package:
https://www.nuget.org/packages/Html2JiraMarkup/

you are welcome to download and use it.

No need to mention i tested it and it works for me, but i didn't tested all use cases, so let me know if something not converting well

Once you confirm it works fine, i will post an article so anyone who will search for the same solution will find it easily.

Like faisalamdani likes this
Kapil Soni July 20, 2021

Hi @Nir Haimov 

 

Thank you so much and I will surely look into and let you know if I encounter any bug.

 

kapil

faisalamdani July 22, 2021

Hello @Nir Haimov 

I am working on angular how I will use this package?

Or there is any other npm package?

Nir Haimov
Community Champion
July 23, 2021

Hi @faisalamdani 

This package is for C#, it's not a npm package.

Angular is your front-end... if you are using C# in your backend you can use this package. 

What is your backend?

Nir Haimov
Community Champion
July 28, 2021

@Kapil Soni any update?

Kapil Soni July 28, 2021

Hi @Nir Haimov 

Will provide you update here by End of this week. Due to some project related urgency i wouldn't got chance but for sure by end of this week will validate this and keep you posted here

Nir Haimov
Community Champion
August 10, 2021

Hi @Kapil Soni 

Any update? :)

Felipe Santos August 18, 2021

Hi, is it possible to use your package with nodejs?

Nir Haimov
Community Champion
August 18, 2021

Hi @Felipe Santos 

No,

But when i  will get time, i will create npm package so it will be available for you too

Like Felipe Santos likes this
Nir Haimov
Community Champion
August 18, 2021
Like Felipe Santos likes this
Felipe Santos August 18, 2021

@Nir Haimov thanks, you saved my life sz

Anandraj Rajaram November 30, 2021

@Nir Haimov Do you have any package for Java. To Convert HTML to Jira MarkUp

0 votes
Nir Haimov
Community Champion
July 20, 2020

Hi @Kapil Soni 

I'm not really familiar with a way to achieve this.

Try the answer on this post:

https://community.atlassian.com/t5/Jira-questions/Jira-Text-Formatting-to-HTML-JavaScript-Parser/qaq-p/607235

Michael Cowan
Contributor
April 19, 2021

I am REALLY confused how Jira has not provided a simple SDK or tool to convert HTML into the Jira Markup for use with the REST API. Does everyone have to painfully map HTML tags to markup blocks? 

Noah Povis
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 6, 2021

yeah i agree this is ridiculous

faisalamdani July 16, 2021

@Michael Cowan  @Kapil Soni I am also facing the same issue.

there is one npm module is present though its not converting it properly but you can give it a try

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events