(refs #751)Fix issue reference in verbatim node

This commit is contained in:
Naoki Takezoe
2015-06-09 02:24:45 +09:00
parent e5fa43f91c
commit 7297a07466
2 changed files with 18 additions and 5 deletions

View File

@@ -2,7 +2,6 @@ package gitbucket.core.view
import gitbucket.core.controller.Context
import gitbucket.core.service.{RepositoryService, RequestCache}
import gitbucket.core.util.Implicits
import gitbucket.core.util.Implicits.RichString
trait LinkConverter { self: RequestCache =>
@@ -11,10 +10,12 @@ trait LinkConverter { self: RequestCache =>
* Converts issue id, username and commit id to link.
*/
protected def convertRefsLinks(value: String, repository: RepositoryService.RepositoryInfo,
issueIdPrefix: String = "#")(implicit context: Context): String = {
value
// escape HTML tags
.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;")
issueIdPrefix: String = "#", escapeHtml: Boolean = true)(implicit context: Context): String = {
// escape HTML tags
val escaped = if(escapeHtml) value.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;") else value
escaped
// convert issue id to link
.replaceBy(("(?<=(^|\\W))" + issueIdPrefix + "([0-9]+)(?=(\\W|$))").r){ m =>
getIssue(repository.owner, repository.name, m.group(2)) match {

View File

@@ -177,6 +177,18 @@ class GitBucketHtmlSerializer(
}
}
override def visit(node: VerbatimNode) {
val printer = new Printer()
val serializer = verbatimSerializers.get(VerbatimSerializer.DEFAULT)
serializer.serialize(node, printer)
val html = printer.getString
// convert commit id and username to link.
val t = if(enableRefsLink) convertRefsLinks(html, repository, "issue:", escapeHtml = false) else html
this.printer.print(t)
}
override def visit(node: BulletListNode): Unit = {
if (printChildrenToString(node).contains("""class="task-list-item-checkbox" """)) {
printer.println().print("""<ul class="task-list">""").indent(+2)