diff --git a/src/main/scala/app/WikiController.scala b/src/main/scala/app/WikiController.scala
index 9cb6db7..0432179 100644
--- a/src/main/scala/app/WikiController.scala
+++ b/src/main/scala/app/WikiController.scala
@@ -160,7 +160,7 @@
val repository = params("repository")
val content = params("content")
contentType = "text/html"
- view.helpers.markdown(content, JGitUtil.getRepositoryInfo(owner, repository, servletContext))
+ view.helpers.markdown(content, JGitUtil.getRepositoryInfo(owner, repository, servletContext), true)
}
/**
diff --git a/src/main/scala/view/helpers.scala b/src/main/scala/view/helpers.scala
index 0cef4d4..7d81ca7 100644
--- a/src/main/scala/view/helpers.scala
+++ b/src/main/scala/view/helpers.scala
@@ -23,26 +23,39 @@
value.replaceAll(" ", " ").replaceAll("\t", " ").replaceAll("\n", "
"))
/**
- * Converts Markdown of Wiki pages to HTML. This method supports Wiki links.
+ * Converts the issue number and the commit id to the link.
*/
- def markdown(value: String, repository: app.RepositoryInfo)(implicit context: app.Context): twirl.api.Html = {
+ private def markdownFilter(value: String, repository: app.RepositoryInfo)(implicit context: app.Context): String = {
+ value
+ .replaceAll("#([0-9]+)", "[$0](%s/%s/%s/issue/$1)".format(context.path, repository.owner, repository.name))
+ .replaceAll("[0-9a-z]{10,40}", "[$0](%s/%s/%s/commit/$0)".format(context.path, repository.owner, repository.name))
+ }
+
+ /**
+ * Converts Markdown of Wiki pages to HTML.
+ */
+ def markdown(value: String, repository: app.RepositoryInfo, wikiLink: Boolean)(implicit context: app.Context): twirl.api.Html = {
import org.pegdown._
val html = new PegDownProcessor(Extensions.AUTOLINKS|Extensions.WIKILINKS|Extensions.FENCED_CODE_BLOCKS)
- .markdownToHtml(value, new LinkRenderer(){
+ .markdownToHtml(markdownFilter(value, repository), new LinkRenderer(){
override def render(node: WikiLinkNode): Rendering = {
- try {
- val text = node.getText
- val (label, page) = if(text.contains('|')){
- val i = text.indexOf('|')
- (text.substring(0, i), text.substring(i + 1))
- } else {
- (text, text)
+ if(wikiLink){
+ super.render(node)
+ } else {
+ try {
+ val text = node.getText
+ val (label, page) = if(text.contains('|')){
+ val i = text.indexOf('|')
+ (text.substring(0, i), text.substring(i + 1))
+ } else {
+ (text, text)
+ }
+ val url = "%s/%s/%s/wiki/%s".format(context.path, repository.owner, repository.name,
+ java.net.URLEncoder.encode(page.replace(' ', '-'), "UTF-8"))
+ new Rendering(url, label);
+ } catch {
+ case e: java.io.UnsupportedEncodingException => throw new IllegalStateException();
}
- val url = "%s/%s/%s/wiki/%s".format(context.path, repository.owner, repository.name,
- java.net.URLEncoder.encode(page.replace(' ', '-'), "UTF-8"))
- new Rendering(url, label);
- } catch {
- case e: java.io.UnsupportedEncodingException => throw new IllegalStateException();
}
}
})
@@ -50,14 +63,6 @@
}
/**
- * Converts Markdown to HTML. This method does not support Wiki links.
- */
- def markdown(value: String): twirl.api.Html = {
- val html = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS).markdownToHtml(value, new LinkRenderer())
- twirl.api.Html(html)
- }
-
- /**
* Cut the given string by specified length.
*/
def cut(message: String, length: Int): String = {
diff --git a/src/main/twirl/repo/files.scala.html b/src/main/twirl/repo/files.scala.html
index 5d0fe92..5cc97fa 100644
--- a/src/main/twirl/repo/files.scala.html
+++ b/src/main/twirl/repo/files.scala.html
@@ -55,7 +55,7 @@
@readme.map { content =>
@helpers.markdown(content) | +@helpers.markdown(content, repository, false) |