diff options
author | Unknwon <u@gogs.io> | 2015-12-17 22:31:34 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-12-17 22:31:34 -0500 |
commit | 1e7e092992164acc243ec01859509eaa2207196d (patch) | |
tree | fe0cbf40da66fb92ef40b07704028e13339b8511 /modules/template | |
parent | 33a99d587a034ba476328437da60049dbf830d6a (diff) | |
download | gitea-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.go | 21 |
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 "" } |