Convert issue id and commit id in commit message to link.

This commit is contained in:
takezoe
2013-06-22 14:07:26 +09:00
parent fb51210ccc
commit 0ee827eaf5
6 changed files with 28 additions and 12 deletions

View File

@@ -26,6 +26,18 @@ object helpers {
Html(Markdown.toHtml(value, repository, enableWikiLink, enableCommitLink, enableIssueLink))
}
/**
* Converts issue id and commit id to link.
*/
def link(value: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context): Html =
Html(value
// escape HTML tags
.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;")
// convert issue id to link
.replaceAll("(^|\\W)#([0-9]+)(\\W|$)", "$1<a href=\"%s/%s/%s/issues/$2\">#$2</a>$3".format(context.path, repository.owner, repository.name))
// convert commit id to link
.replaceAll("(^|\\W)([a-f0-9]{40})(\\W|$)", "$1<a href=\"%s/%s/%s/commit/$0\">$2</a>$3").format(context.path, repository.owner, repository.name))
}
/**