mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-18 03:49:46 +00: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
|
bg-BG = bg
|
||||||
it-IT = it
|
it-IT = it
|
||||||
|
|
||||||
|
; Extension mapping to highlight class
|
||||||
|
; e.g. .toml=ini
|
||||||
|
[highlight.mapping]
|
||||||
|
|
||||||
[other]
|
[other]
|
||||||
SHOW_FOOTER_BRANDING = false
|
SHOW_FOOTER_BRANDING = false
|
||||||
; Show version information about gogs and go in the footer
|
; 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 (
|
var (
|
||||||
// Build information.
|
// Build information
|
||||||
BuildTime string
|
BuildTime string
|
||||||
BuildGitHash string
|
BuildGitHash string
|
||||||
|
|
||||||
// App settings.
|
// App settings
|
||||||
AppVer string
|
AppVer string
|
||||||
AppName string
|
AppName string
|
||||||
AppUrl string
|
AppUrl string
|
||||||
|
@ -55,7 +55,7 @@ var (
|
||||||
AppPath string
|
AppPath string
|
||||||
AppDataPath = "data"
|
AppDataPath = "data"
|
||||||
|
|
||||||
// Server settings.
|
// Server settings
|
||||||
Protocol Scheme
|
Protocol Scheme
|
||||||
Domain string
|
Domain string
|
||||||
HttpAddr, HttpPort string
|
HttpAddr, HttpPort string
|
||||||
|
@ -71,7 +71,7 @@ var (
|
||||||
EnableGzip bool
|
EnableGzip bool
|
||||||
LandingPageUrl LandingPage
|
LandingPageUrl LandingPage
|
||||||
|
|
||||||
// Security settings.
|
// Security settings
|
||||||
InstallLock bool
|
InstallLock bool
|
||||||
SecretKey string
|
SecretKey string
|
||||||
LogInRememberDays int
|
LogInRememberDays int
|
||||||
|
@ -79,13 +79,13 @@ var (
|
||||||
CookieRememberName string
|
CookieRememberName string
|
||||||
ReverseProxyAuthUser string
|
ReverseProxyAuthUser string
|
||||||
|
|
||||||
// Database settings.
|
// Database settings
|
||||||
UseSQLite3 bool
|
UseSQLite3 bool
|
||||||
UseMySQL bool
|
UseMySQL bool
|
||||||
UsePostgreSQL bool
|
UsePostgreSQL bool
|
||||||
UseTiDB bool
|
UseTiDB bool
|
||||||
|
|
||||||
// Webhook settings.
|
// Webhook settings
|
||||||
Webhook struct {
|
Webhook struct {
|
||||||
QueueLength int
|
QueueLength int
|
||||||
DeliverTimeout int
|
DeliverTimeout int
|
||||||
|
@ -94,7 +94,7 @@ var (
|
||||||
PagingNum int
|
PagingNum int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repository settings.
|
// Repository settings
|
||||||
Repository struct {
|
Repository struct {
|
||||||
AnsiCharset string
|
AnsiCharset string
|
||||||
ForcePrivate bool
|
ForcePrivate bool
|
||||||
|
@ -104,7 +104,7 @@ var (
|
||||||
RepoRootPath string
|
RepoRootPath string
|
||||||
ScriptType string
|
ScriptType string
|
||||||
|
|
||||||
// UI settings.
|
// UI settings
|
||||||
ExplorePagingNum int
|
ExplorePagingNum int
|
||||||
IssuePagingNum int
|
IssuePagingNum int
|
||||||
FeedMaxCommitNum int
|
FeedMaxCommitNum int
|
||||||
|
@ -113,47 +113,47 @@ var (
|
||||||
AdminNoticePagingNum int
|
AdminNoticePagingNum int
|
||||||
AdminOrgPagingNum int
|
AdminOrgPagingNum int
|
||||||
|
|
||||||
// Markdown sttings.
|
// Markdown sttings
|
||||||
Markdown struct {
|
Markdown struct {
|
||||||
EnableHardLineBreak bool
|
EnableHardLineBreak bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Picture settings.
|
// Picture settings
|
||||||
PictureService string
|
PictureService string
|
||||||
AvatarUploadPath string
|
AvatarUploadPath string
|
||||||
GravatarSource string
|
GravatarSource string
|
||||||
DisableGravatar bool
|
DisableGravatar bool
|
||||||
|
|
||||||
// Log settings.
|
// Log settings
|
||||||
LogRootPath string
|
LogRootPath string
|
||||||
LogModes []string
|
LogModes []string
|
||||||
LogConfigs []string
|
LogConfigs []string
|
||||||
|
|
||||||
// Attachment settings.
|
// Attachment settings
|
||||||
AttachmentPath string
|
AttachmentPath string
|
||||||
AttachmentAllowedTypes string
|
AttachmentAllowedTypes string
|
||||||
AttachmentMaxSize int64
|
AttachmentMaxSize int64
|
||||||
AttachmentMaxFiles int
|
AttachmentMaxFiles int
|
||||||
AttachmentEnabled bool
|
AttachmentEnabled bool
|
||||||
|
|
||||||
// Time settings.
|
// Time settings
|
||||||
TimeFormat string
|
TimeFormat string
|
||||||
|
|
||||||
// Cache settings.
|
// Cache settings
|
||||||
CacheAdapter string
|
CacheAdapter string
|
||||||
CacheInternal int
|
CacheInternal int
|
||||||
CacheConn string
|
CacheConn string
|
||||||
|
|
||||||
// Session settings.
|
// Session settings
|
||||||
SessionConfig session.Options
|
SessionConfig session.Options
|
||||||
|
|
||||||
// Git settings.
|
// Git settings
|
||||||
Git struct {
|
Git struct {
|
||||||
MaxGitDiffLines int
|
MaxGitDiffLines int
|
||||||
GcArgs []string `delim:" "`
|
GcArgs []string `delim:" "`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cron tasks.
|
// Cron tasks
|
||||||
Cron struct {
|
Cron struct {
|
||||||
UpdateMirror struct {
|
UpdateMirror struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
|
@ -174,17 +174,19 @@ var (
|
||||||
} `ini:"cron.check_repo_stats"`
|
} `ini:"cron.check_repo_stats"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// I18n settings.
|
// I18n settings
|
||||||
Langs, Names []string
|
Langs, Names []string
|
||||||
dateLangs map[string]string
|
dateLangs map[string]string
|
||||||
|
|
||||||
// Other settings.
|
// Highlight settings are loaded in modules/template/hightlight.go
|
||||||
|
|
||||||
|
// Other settings
|
||||||
ShowFooterBranding bool
|
ShowFooterBranding bool
|
||||||
ShowFooterVersion bool
|
ShowFooterVersion bool
|
||||||
|
|
||||||
// Global setting objects.
|
// Global setting objects
|
||||||
Cfg *ini.File
|
Cfg *ini.File
|
||||||
CustomPath string // Custom directory path.
|
CustomPath string // Custom directory path
|
||||||
CustomConf string
|
CustomConf string
|
||||||
ProdMode bool
|
ProdMode bool
|
||||||
RunUser string
|
RunUser string
|
||||||
|
|
|
@ -7,6 +7,8 @@ package template
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -16,13 +18,13 @@ var (
|
||||||
"copying": true,
|
"copying": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// File names that are representing highlight class.
|
// File names that are representing highlight classes.
|
||||||
highlightFileNames = map[string]bool{
|
highlightFileNames = map[string]bool{
|
||||||
"dockerfile": true,
|
"dockerfile": true,
|
||||||
"makefile": true,
|
"makefile": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions that are same as highlight class.
|
// Extensions that are same as highlight classes.
|
||||||
highlightExts = map[string]bool{
|
highlightExts = map[string]bool{
|
||||||
".arm": true,
|
".arm": true,
|
||||||
".as": true,
|
".as": true,
|
||||||
|
@ -57,8 +59,18 @@ var (
|
||||||
".ts": true,
|
".ts": true,
|
||||||
".vb": 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
|
// FileNameToHighlightClass returns the best match for highlight class name
|
||||||
// based on the rule of highlight.js.
|
// based on the rule of highlight.js.
|
||||||
func FileNameToHighlightClass(fname string) string {
|
func FileNameToHighlightClass(fname string) string {
|
||||||
|
@ -76,5 +88,10 @@ func FileNameToHighlightClass(fname string) string {
|
||||||
return ext[1:]
|
return ext[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name, ok := highlightMapping[ext]
|
||||||
|
if ok {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
"github.com/gogits/gogs/modules/ssh"
|
"github.com/gogits/gogs/modules/ssh"
|
||||||
|
"github.com/gogits/gogs/modules/template"
|
||||||
"github.com/gogits/gogs/modules/user"
|
"github.com/gogits/gogs/modules/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ func NewServices() {
|
||||||
// GlobalInit is for global configuration reload-able.
|
// GlobalInit is for global configuration reload-able.
|
||||||
func GlobalInit() {
|
func GlobalInit() {
|
||||||
setting.NewContext()
|
setting.NewContext()
|
||||||
|
template.NewContext()
|
||||||
log.Trace("Custom path: %s", setting.CustomPath)
|
log.Trace("Custom path: %s", setting.CustomPath)
|
||||||
log.Trace("Log path: %s", setting.LogRootPath)
|
log.Trace("Log path: %s", setting.LogRootPath)
|
||||||
models.LoadConfigs()
|
models.LoadConfigs()
|
||||||
|
|
Loading…
Reference in a new issue