Convert the issue number and the commit id to the link.

This commit is contained in:
takezoe
2013-06-02 02:30:50 +09:00
parent 0cdb7fd5c7
commit 8f9b459123
4 changed files with 31 additions and 26 deletions

View File

@@ -160,7 +160,7 @@ trait WikiControllerBase extends ControllerBase { self: WikiService =>
val repository = params("repository") val repository = params("repository")
val content = params("content") val content = params("content")
contentType = "text/html" contentType = "text/html"
view.helpers.markdown(content, JGitUtil.getRepositoryInfo(owner, repository, servletContext)) view.helpers.markdown(content, JGitUtil.getRepositoryInfo(owner, repository, servletContext), true)
} }
/** /**

View File

@@ -23,13 +23,25 @@ object helpers {
value.replaceAll(" ", "&nbsp;").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").replaceAll("\n", "<br>")) value.replaceAll(" ", "&nbsp;").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").replaceAll("\n", "<br>"))
/** /**
* 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._ import org.pegdown._
val html = new PegDownProcessor(Extensions.AUTOLINKS|Extensions.WIKILINKS|Extensions.FENCED_CODE_BLOCKS) 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 = { override def render(node: WikiLinkNode): Rendering = {
if(wikiLink){
super.render(node)
} else {
try { try {
val text = node.getText val text = node.getText
val (label, page) = if(text.contains('|')){ val (label, page) = if(text.contains('|')){
@@ -45,15 +57,8 @@ object helpers {
case e: java.io.UnsupportedEncodingException => throw new IllegalStateException(); case e: java.io.UnsupportedEncodingException => throw new IllegalStateException();
} }
} }
})
twirl.api.Html(html)
} }
})
/**
* 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) twirl.api.Html(html)
} }

View File

@@ -55,7 +55,7 @@
@readme.map { content => @readme.map { content =>
<table class="table table-bordered"> <table class="table table-bordered">
<tr> <tr>
<td>@helpers.markdown(content)</td> <td>@helpers.markdown(content, repository, false)</td>
</tr> </tr>
</table> </table>
} }

View File

@@ -17,7 +17,7 @@
</li> </li>
</ul> </ul>
<div class="markdown-body"> <div class="markdown-body">
@helpers.markdown(page.content, repository) @helpers.markdown(page.content, repository, true)
</div> </div>
<div class="small"> <div class="small">
<span class="description">Last edited by @page.committer at @helpers.datetime(page.time)</span> <span class="description">Last edited by @page.committer at @helpers.datetime(page.time)</span>