Forums

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

Converting Jira Markdown text to HTML

yossi ben david
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!
September 10, 2020

Hi all, Hope this message finds you safe and well! :)

Our client uses Jira for task management in his company.

Working with Microsoft Power BI, we pull data from our customer Jira DB and import it into our Microsoft  Power Bi database so we can see all data such as Jira tasks and comment  in the Power Bi environment.

Problem we have is when a Jira user has used Markdown text to design the content he adds to Jira.

When we pull out the data we can not use it unless we first convert it to HTML as HTML is the format we use to display the Jira data on our Power Bi app.


As fetching the Jira data is an automated service we wanted to ask if you know any solutions for converting the Jira Markdown text when importing it.



- Is there a way \ functionality in jira to pull out text In HTML format?

- If now, do you know any 3rd party service we can use to automatically convert Jira Markdown Data to HTML?


We will appreciate any top idea on this matter.

1 answer

1 vote
Paul Taggart April 5, 2022

Hi,

Below is the code I'm using to convert from Jira WikiMarkup to HTML and back. The packages are documented here.

 

// (Markdown / Jira Markdown) <-> HTML
import { defaultSchema } from '@atlaskit/adf-schema';
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 };

Suggest an answer

Log in or Sign up to answer