mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45: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))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<link href="@path/assets/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/>
|
||||
<script src="@path/assets/google-code-prettify/prettify.js"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
$('#preview').click(function(){
|
||||
@@ -24,6 +26,7 @@ $(function(){
|
||||
content: $('#content').val()
|
||||
}, function(data){
|
||||
$('#preview-area').html(data);
|
||||
prettyPrint();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,3 +25,8 @@
|
||||
<span class="description">Last edited by @page.committer at @helpers.datetime(page.time)</span>
|
||||
</div>
|
||||
}
|
||||
<link href="@path/assets/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/>
|
||||
<script src="@path/assets/google-code-prettify/prettify.js"></script>
|
||||
<script>
|
||||
$(function(){ prettyPrint(); });
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user