mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Add syntax highlighting in Wiki.
This commit is contained in:
@@ -24,45 +24,11 @@ object helpers {
|
||||
def format(value: String): Html = Html(
|
||||
value.replaceAll(" ", " ").replaceAll("\t", " ").replaceAll("\n", "<br>"))
|
||||
|
||||
/**
|
||||
* Converts the issue number and the commit id to the link.
|
||||
*/
|
||||
private def markdownFilter(value: String, repository: service.RepositoryService.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-f]{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: service.RepositoryService.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(markdownFilter(value, repository), new LinkRenderer(){
|
||||
override def render(node: WikiLinkNode): Rendering = {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Html(html)
|
||||
Html(Markdown.toHtml(value, repository, wikiLink))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user