mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
Support Wiki links.
This commit is contained in:
@@ -146,9 +146,11 @@ class WikiController extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_preview"){
|
post("/:owner/:repository/wiki/_preview"){
|
||||||
|
val owner = params("owner")
|
||||||
|
val repository = params("repository")
|
||||||
val content = params("content")
|
val content = params("content")
|
||||||
contentType = "text/html"
|
contentType = "text/html"
|
||||||
view.helpers.markdown(content)
|
view.helpers.markdown(content, JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package view
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
|
||||||
|
import org.pegdown._
|
||||||
|
import org.pegdown.LinkRenderer.Rendering
|
||||||
|
import org.pegdown.ast.WikiLinkNode
|
||||||
|
|
||||||
object helpers {
|
object helpers {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,9 +22,38 @@ object helpers {
|
|||||||
def format(value: String): twirl.api.Html = twirl.api.Html(
|
def format(value: String): twirl.api.Html = twirl.api.Html(
|
||||||
value.replaceAll(" ", " ").replaceAll("\t", " ").replaceAll("\n", "<br>"))
|
value.replaceAll(" ", " ").replaceAll("\t", " ").replaceAll("\n", "<br>"))
|
||||||
|
|
||||||
def markdown(value: String): twirl.api.Html = {
|
/**
|
||||||
|
* Converts Markdown of Wiki pages to HTML. This method supports Wiki links.
|
||||||
|
*/
|
||||||
|
def markdown(value: String, repository: app.RepositoryInfo)(implicit context: app.Context): twirl.api.Html = {
|
||||||
import org.pegdown._
|
import org.pegdown._
|
||||||
val html = new PegDownProcessor().markdownToHtml(value)
|
val html = new PegDownProcessor(Extensions.AUTOLINKS|Extensions.WIKILINKS)
|
||||||
|
.markdownToHtml(value, 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)
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
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().markdownToHtml(value, new LinkRenderer())
|
||||||
twirl.api.Html(html)
|
twirl.api.Html(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="markdown-body">
|
<div class="markdown-body">
|
||||||
@helpers.markdown(page.content)
|
@helpers.markdown(page.content, repository)
|
||||||
</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user