mirror of
https://github.com/go-gitea/gitea
synced 2024-12-30 17:35:55 +01:00
#2103 Ability to map extensions for syntax highlighting in config
This commit is contained in:
parent
33a99d587a
commit
1e7e092992
@ -338,6 +338,10 @@ pl-PL = pl
|
||||
bg-BG = bg
|
||||
it-IT = it
|
||||
|
||||
; Extension mapping to highlight class
|
||||
; e.g. .toml=ini
|
||||
[highlight.mapping]
|
||||
|
||||
[other]
|
||||
SHOW_FOOTER_BRANDING = false
|
||||
; Show version information about gogs and go in the footer
|
||||
|
File diff suppressed because one or more lines are too long
@ -43,11 +43,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// Build information.
|
||||
// Build information
|
||||
BuildTime string
|
||||
BuildGitHash string
|
||||
|
||||
// App settings.
|
||||
// App settings
|
||||
AppVer string
|
||||
AppName string
|
||||
AppUrl string
|
||||
@ -55,7 +55,7 @@ var (
|
||||
AppPath string
|
||||
AppDataPath = "data"
|
||||
|
||||
// Server settings.
|
||||
// Server settings
|
||||
Protocol Scheme
|
||||
Domain string
|
||||
HttpAddr, HttpPort string
|
||||
@ -71,7 +71,7 @@ var (
|
||||
EnableGzip bool
|
||||
LandingPageUrl LandingPage
|
||||
|
||||
// Security settings.
|
||||
// Security settings
|
||||
InstallLock bool
|
||||
SecretKey string
|
||||
LogInRememberDays int
|
||||
@ -79,13 +79,13 @@ var (
|
||||
CookieRememberName string
|
||||
ReverseProxyAuthUser string
|
||||
|
||||
// Database settings.
|
||||
// Database settings
|
||||
UseSQLite3 bool
|
||||
UseMySQL bool
|
||||
UsePostgreSQL bool
|
||||
UseTiDB bool
|
||||
|
||||
// Webhook settings.
|
||||
// Webhook settings
|
||||
Webhook struct {
|
||||
QueueLength int
|
||||
DeliverTimeout int
|
||||
@ -94,7 +94,7 @@ var (
|
||||
PagingNum int
|
||||
}
|
||||
|
||||
// Repository settings.
|
||||
// Repository settings
|
||||
Repository struct {
|
||||
AnsiCharset string
|
||||
ForcePrivate bool
|
||||
@ -104,7 +104,7 @@ var (
|
||||
RepoRootPath string
|
||||
ScriptType string
|
||||
|
||||
// UI settings.
|
||||
// UI settings
|
||||
ExplorePagingNum int
|
||||
IssuePagingNum int
|
||||
FeedMaxCommitNum int
|
||||
@ -113,47 +113,47 @@ var (
|
||||
AdminNoticePagingNum int
|
||||
AdminOrgPagingNum int
|
||||
|
||||
// Markdown sttings.
|
||||
// Markdown sttings
|
||||
Markdown struct {
|
||||
EnableHardLineBreak bool
|
||||
}
|
||||
|
||||
// Picture settings.
|
||||
// Picture settings
|
||||
PictureService string
|
||||
AvatarUploadPath string
|
||||
GravatarSource string
|
||||
DisableGravatar bool
|
||||
|
||||
// Log settings.
|
||||
// Log settings
|
||||
LogRootPath string
|
||||
LogModes []string
|
||||
LogConfigs []string
|
||||
|
||||
// Attachment settings.
|
||||
// Attachment settings
|
||||
AttachmentPath string
|
||||
AttachmentAllowedTypes string
|
||||
AttachmentMaxSize int64
|
||||
AttachmentMaxFiles int
|
||||
AttachmentEnabled bool
|
||||
|
||||
// Time settings.
|
||||
// Time settings
|
||||
TimeFormat string
|
||||
|
||||
// Cache settings.
|
||||
// Cache settings
|
||||
CacheAdapter string
|
||||
CacheInternal int
|
||||
CacheConn string
|
||||
|
||||
// Session settings.
|
||||
// Session settings
|
||||
SessionConfig session.Options
|
||||
|
||||
// Git settings.
|
||||
// Git settings
|
||||
Git struct {
|
||||
MaxGitDiffLines int
|
||||
GcArgs []string `delim:" "`
|
||||
}
|
||||
|
||||
// Cron tasks.
|
||||
// Cron tasks
|
||||
Cron struct {
|
||||
UpdateMirror struct {
|
||||
Enabled bool
|
||||
@ -174,17 +174,19 @@ var (
|
||||
} `ini:"cron.check_repo_stats"`
|
||||
}
|
||||
|
||||
// I18n settings.
|
||||
// I18n settings
|
||||
Langs, Names []string
|
||||
dateLangs map[string]string
|
||||
|
||||
// Other settings.
|
||||
// Highlight settings are loaded in modules/template/hightlight.go
|
||||
|
||||
// Other settings
|
||||
ShowFooterBranding bool
|
||||
ShowFooterVersion bool
|
||||
|
||||
// Global setting objects.
|
||||
// Global setting objects
|
||||
Cfg *ini.File
|
||||
CustomPath string // Custom directory path.
|
||||
CustomPath string // Custom directory path
|
||||
CustomConf string
|
||||
ProdMode bool
|
||||
RunUser string
|
||||
|
@ -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 ""
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
"github.com/gogits/gogs/modules/ssh"
|
||||
"github.com/gogits/gogs/modules/template"
|
||||
"github.com/gogits/gogs/modules/user"
|
||||
)
|
||||
|
||||
@ -55,6 +56,7 @@ func NewServices() {
|
||||
// GlobalInit is for global configuration reload-able.
|
||||
func GlobalInit() {
|
||||
setting.NewContext()
|
||||
template.NewContext()
|
||||
log.Trace("Custom path: %s", setting.CustomPath)
|
||||
log.Trace("Log path: %s", setting.LogRootPath)
|
||||
models.LoadConfigs()
|
||||
|
Loading…
Reference in New Issue
Block a user