diff --git a/src/main/scala/gitbucket/core/view/helpers.scala b/src/main/scala/gitbucket/core/view/helpers.scala index c5f1a40..848981a 100644 --- a/src/main/scala/gitbucket/core/view/helpers.scala +++ b/src/main/scala/gitbucket/core/view/helpers.scala @@ -3,6 +3,7 @@ import java.text.SimpleDateFormat import java.util.{Date, Locale, TimeZone} +import com.nimbusds.jose.util.JSONObjectUtils import gitbucket.core.controller.Context import gitbucket.core.model.CommitState import gitbucket.core.plugin.{PluginRegistry, RenderRequest} @@ -462,4 +463,44 @@ */ def readableSize(size: Option[Long]): String = FileUtil.readableSize(size.getOrElse(0)) + /** + * Make HTML fragment of the partial diff for a comment on a line of diff. + * + * @param jsonString JSON string which is stored in COMMIT_COMMENT table. + * @return HTML fragment of diff + */ + def diff(jsonString: String): Html = { + import org.json4s._ + import org.json4s.jackson.JsonMethods._ + implicit val formats = DefaultFormats + + val diff = parse(jsonString).extract[Seq[CommentDiffLine]] + + val sb = new StringBuilder() + sb.append("
""") + line.oldLine.foreach { oldLine => + sb.append(oldLine) + } + sb.append(" | ") + sb.append(s"""""") + line.newLine.foreach { newLine => + sb.append(newLine) + } + sb.append(" | ") + + sb.append(s"""""") + sb.append(StringUtil.escapeHtml(line.text)) + sb.append(" | ") + sb.append("
---|