mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
#2103 Ability to map extensions for syntax highlighting in config
This commit is contained in:
@@ -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 ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user