diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-03-16 11:12:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-16 11:12:44 +0800 |
commit | 379289639e44f8fbb1368c4f2a324f52bcb70e7f (patch) | |
tree | bbe0951debfed8f292e8abd1ce1bb6a15072a7e1 /modules/setting/markup.go | |
parent | faf446b37257c84a038004a3655e49bda1f51a0d (diff) | |
download | gitea-379289639e44f8fbb1368c4f2a324f52bcb70e7f.tar.gz gitea-379289639e44f8fbb1368c4f2a324f52bcb70e7f.zip |
split setting.go to multiple files (#6154)
* split setting.go to multiple files
* fix lint
Diffstat (limited to 'modules/setting/markup.go')
-rw-r--r-- | modules/setting/markup.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/modules/setting/markup.go b/modules/setting/markup.go new file mode 100644 index 0000000000..41f3cdd3a1 --- /dev/null +++ b/modules/setting/markup.go @@ -0,0 +1,66 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package setting + +import ( + "regexp" + "strings" + + "code.gitea.io/gitea/modules/log" +) + +// ExternalMarkupParsers represents the external markup parsers +var ( + ExternalMarkupParsers []MarkupParser +) + +// MarkupParser defines the external parser configured in ini +type MarkupParser struct { + Enabled bool + MarkupName string + Command string + FileExtensions []string + IsInputFile bool +} + +func newMarkup() { + extensionReg := regexp.MustCompile(`\.\w`) + for _, sec := range Cfg.Section("markup").ChildSections() { + name := strings.TrimPrefix(sec.Name(), "markup.") + if name == "" { + log.Warn("name is empty, markup " + sec.Name() + "ignored") + continue + } + + extensions := sec.Key("FILE_EXTENSIONS").Strings(",") + var exts = make([]string, 0, len(extensions)) + for _, extension := range extensions { + if !extensionReg.MatchString(extension) { + log.Warn(sec.Name() + " file extension " + extension + " is invalid. Extension ignored") + } else { + exts = append(exts, extension) + } + } + + if len(exts) == 0 { + log.Warn(sec.Name() + " file extension is empty, markup " + name + " ignored") + continue + } + + command := sec.Key("RENDER_COMMAND").MustString("") + if command == "" { + log.Warn(" RENDER_COMMAND is empty, markup " + name + " ignored") + continue + } + + ExternalMarkupParsers = append(ExternalMarkupParsers, MarkupParser{ + Enabled: sec.Key("ENABLED").MustBool(false), + MarkupName: name, + FileExtensions: exts, + Command: command, + IsInputFile: sec.Key("IS_INPUT_FILE").MustBool(false), + }) + } +} |