使用 Jira ScriptRunner 将纯文本/wiki 语法转换为 HTML(显示项目符号、复选标记笑脸等)
Convert plain text / wiki syntax to HTML with Jira ScriptRunner (show bullet points, checkmark smileys, etc.)
我正在尝试检索我在 JIRA 问题页面中输入的最新评论的文本,这是我输入的最新评论的屏幕截图:
我在 Jira 脚本运行程序中使用此代码来检索我输入的最后一条评论:
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat
import com.opensymphony.util.TextUtils
import com.atlassian.jira.issue.comments.*
import org.w3c.dom.*;
import javax.xml.parsers.*;
import groovy.xml.*
import grrovy.util.*;
import org.xml.sax.InputSource;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
def commentManager = ComponentAccessor.getCommentManager()
Comment comment = commentManager.getLastComment (issue)
if(comment != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MMM/yy HH:mm", Locale.ENGLISH)
def body = comment.body //.replaceAll("[\r\n]+","\n")
body= """<div style="max-height:100px; overflow:auto;" title="${comment.authorFullName} added last comment - ${dateFormat.format(comment.created)}">
<span style="white-space: pre-wrap;">${TextUtils.htmlEncode(body)}</span>
</div>"""
return body
}
以上代码的输出如下:
我希望输出以其原始格式显示,意思是,我希望出现项目符号点、笑脸符号和绿色复选标记。我不想看到星星、代码颜色和笑脸缩写 :) 我希望输出如下所示:
我该如何解决这个问题?
您需要将 wiki 语法源渲染到 HTML 输出并使用现有的 wiki 渲染器。
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.issue.fields.renderer.JiraRendererPlugin
import com.atlassian.jira.issue.fields.renderer.IssueRenderContext
RendererManager rendererManager = ComponentAccessor.getComponentOfType(RendererManager.class);
JiraRendererPlugin renderer = rendererManager.getRendererForType("atlassian-wiki-renderer");
String lastComment = "* 1\n* 2\n* 3:)\n* {color:#FF0000}(/){color}"
return renderer.render(lastComment, null)
我正在尝试检索我在 JIRA 问题页面中输入的最新评论的文本,这是我输入的最新评论的屏幕截图:
我在 Jira 脚本运行程序中使用此代码来检索我输入的最后一条评论:
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat
import com.opensymphony.util.TextUtils
import com.atlassian.jira.issue.comments.*
import org.w3c.dom.*;
import javax.xml.parsers.*;
import groovy.xml.*
import grrovy.util.*;
import org.xml.sax.InputSource;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
def commentManager = ComponentAccessor.getCommentManager()
Comment comment = commentManager.getLastComment (issue)
if(comment != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MMM/yy HH:mm", Locale.ENGLISH)
def body = comment.body //.replaceAll("[\r\n]+","\n")
body= """<div style="max-height:100px; overflow:auto;" title="${comment.authorFullName} added last comment - ${dateFormat.format(comment.created)}">
<span style="white-space: pre-wrap;">${TextUtils.htmlEncode(body)}</span>
</div>"""
return body
}
以上代码的输出如下:
我希望输出以其原始格式显示,意思是,我希望出现项目符号点、笑脸符号和绿色复选标记。我不想看到星星、代码颜色和笑脸缩写 :) 我希望输出如下所示:
我该如何解决这个问题?
您需要将 wiki 语法源渲染到 HTML 输出并使用现有的 wiki 渲染器。
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.issue.fields.renderer.JiraRendererPlugin
import com.atlassian.jira.issue.fields.renderer.IssueRenderContext
RendererManager rendererManager = ComponentAccessor.getComponentOfType(RendererManager.class);
JiraRendererPlugin renderer = rendererManager.getRendererForType("atlassian-wiki-renderer");
String lastComment = "* 1\n* 2\n* 3:)\n* {color:#FF0000}(/){color}"
return renderer.render(lastComment, null)