Converting HTML to Wikimarkup

The script below takes the response that has a property called description in HTML format and convert that to wikimarkup.

import com.atlassian.jira.component.ComponentAccessor import groovy.lang.GroovyClassLoader import com.fasterxml.jackson.databind.ObjectMapper //load the class Class DefaultWysiwygConverter = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.atlassian.renderer.wysiwyg.converter.DefaultWysiwygConverter"); ObjectMapper mapper = new ObjectMapper() //response is passed in from the parent action def payload = mapper.readValue(response, HashMap.class) String descHtml = payload.description //get description from json body def converter = DefaultWysiwygConverter.newInstance() String descWiki = converter.convertXHtmlToWikiMarkup(descHtml) return descWiki

Example payload

{ "description":"<b>This text is bold</b>" }

Output *This text is bold*