summaryrefslogtreecommitdiffstats
path: root/modules/template
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-17 22:31:34 -0500
committerUnknwon <u@gogs.io>2015-12-17 22:31:34 -0500
commit1e7e092992164acc243ec01859509eaa2207196d (patch)
treefe0cbf40da66fb92ef40b07704028e13339b8511 /modules/template
parent33a99d587a034ba476328437da60049dbf830d6a (diff)
downloadgitea-1e7e092992164acc243ec01859509eaa2207196d.tar.gz
gitea-1e7e092992164acc243ec01859509eaa2207196d.zip
#2103 Ability to map extensions for syntax highlighting in config
Diffstat (limited to 'modules/template')
-rw-r--r--modules/template/highlight.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/modules/template/highlight.go b/modules/template/highlight.go
index 901376aaa6..bd9813eef2 100644
--- a/modules/template/highlight.go
+++ b/modules/template/highlight.go
@@ -7,6 +7,8 @@ package template
import (
"path"
"strings"
+
+ "github.com/gogits/gogs/modules/setting"
)
var (
@@ -16,13 +18,13 @@ var (
"copying": true,
}
- // File names that are representing highlight class.
+ // File names that are representing highlight classes.
highlightFileNames = map[string]bool{
"dockerfile": true,
"makefile": true,
}
- // Extensions that are same as highlight class.
+ // Extensions that are same as highlight classes.
highlightExts = map[string]bool{
".arm": true,
".as": true,
@@ -57,8 +59,18 @@ var (
".ts": true,
".vb": true,
}
+
+ // Extensions that are not same as highlight classes.
+ highlightMapping = map[string]string{}
)
+func NewContext() {
+ keys := setting.Cfg.Section("highlight.mapping").Keys()
+ for i := range keys {
+ highlightMapping[keys[i].Name()] = keys[i].Value()
+ }
+}
+
// FileNameToHighlightClass returns the best match for highlight class name
// based on the rule of highlight.js.
func FileNameToHighlightClass(fname string) string {
@@ -76,5 +88,10 @@ func FileNameToHighlightClass(fname string) string {
return ext[1:]
}
+ name, ok := highlightMapping[ext]
+ if ok {
+ return name
+ }
+
return ""
}