The problem is that by default we can create only text based descriptions.
I noticed JIRA has it’s own rich text / mark down structured text format (ADF = Atlassian Document Format).
Since we’re using HTML in our client, we need to find a way convert HTML to JIRA “rich text” (ADF). Is there an API or a library to make this happen?
OR can JIRA api interpret standard Markdown as description?
What is the best way to do such a conversion?
Please advise.
@TamasKalman I have automated the Jira ticket creation with Jenkins, Nodejs & Axios using Jira Rest API v3 & I also have the same issue. I have tried many ways of formatting the ticket’s description to add bold styles & h1 tags but with no luck. Did you find a solution to this issue?
When using the REST API to create / edit an issue, the description field must be text formatted using markdown codes. You can’t use HTML formatting.
There is no generic ‘library’ that does this, so you need to do some form of iterative text search and replace in the programming language you are using. Use Google to search for ‘convert HTML to JIRA markdown’ for all the different approaches people have used.
Note, there is a ‘workaround’, but it’s only possible for Jira SERVER, not cloud. Read this article.
Yep, that’s where to put the markdown. Converting HTML to markdown is fairly straight forward task of searching and replacing, but you need to do a few passes to convert all the formatting combinations.
Do a Google search for ‘convert HTML to markdown’ and you’ll find lots of examples.
Below is the code to do the Wiki Markup <-> HTML conversions. I’m pretty sure that you can just stap out the WikiMarkupTransformer for the JSON transformer.
// (Markdown / Jira Markdown) <-> HTML
import { defaultSchema } from '@atlaskit/adf-schema/schema-default';
import { WikiMarkupTransformer } from '@atlaskit/editor-wikimarkup-transformer';
import { DOMParser, DOMSerializer } from 'prosemirror-model';
/**
* Convert Jira "Wiki Markup" -> ProseMirror -> HTML
* @param {string} md The Jira "Markdown" string
* @returns {string} The generated HTML
*/
const toHTML = md => {
// Convert the Wiki Markup from Jira to a ProseMirror node
const transformer = new WikiMarkupTransformer(defaultSchema);
const pmNode = transformer.parse(md);
// Serialize Prose Mirror Node to a DocumentFragment
const dom = DOMSerializer.fromSchema(defaultSchema).serializeFragment(pmNode);
// Get the HTML
const div = document.createElement('div');
div.appendChild(dom);
const html = div.innerHTML;
return html;
};
/**
* Convert HTML -> DOM -> ParseMirror -> Jira "Wiki Markup"
* @param {string} html The HTML
* @returns {string} The generated Jira ADF
*/
const toMD = html => {
// Create a new document and set the body
const dom = document.implementation.createHTMLDocument();
dom.body.innerHTML = html;
console.debug('toMD', { dom });
// Parse the DOM into ProseMirror and export to Wiki Markup
const pmNode = DOMParser.fromSchema(defaultSchema).parse(dom);
const transformer = new WikiMarkupTransformer(defaultSchema);
const md = transformer.encode(pmNode);
return md;
};
export { toHTML, toMD };
Thanks @PaulTaggart - this was very useful
In my case I could not find/use the default schema so I ended up using the confluenceschema ( getting jira or any other schema should be the same)
import { confluenceSchema } from '@atlaskit/adf-schema/schema-confluence'
For the serializeFragment to work I had to change use get the fragment from the node (pmNode.content)
Lastly and the most tricky bit… I did not have the window object, because I am not running the code in
the context of a browser, so I had to use the window package . window - npm (npmjs.com) and pass it as an option to the serializeFragment method . …
Is there a place where I can get information on the schemas (under @atlaskit/adf-schema) like ‘@atlaskit/adf-schema/schema-confluence’ e.g. what other schemas are there
confluenceSchema works but it does not translate come codes like {panel} and the formatting is a bit off
e.g. it marks new lines are instead of , and the code macros are not formatted correctly, among other things
@PaulTaggart the only downside to this is if you use your own prosemirror dependency (for a custom editor) in tandem with the one Atlaskit is dependent on for these html->markup conversions.
Interested to know if anyone has figured out a workaround. For me I just had to abandon pulling in my own prosemirror dependency, which means I’m locked into Atlaskit’s…
Thanks @PaulTaggart, I created a new issue for this. Unfortunately I had to monkey patch prose-mirror in order to interoperate with Atlaskit, so it’s a very fragile work around as discussed in that github issue.
My hope is Atlaskit will consider writing a unit test reproducing this error, so that they avoid it in the future: