本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7KB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "regexp"
  7. "strings"
  8. "code.gitea.io/gitea/modules/log"
  9. )
  10. // ExternalMarkupParsers represents the external markup parsers
  11. var (
  12. ExternalMarkupParsers []MarkupParser
  13. )
  14. // MarkupParser defines the external parser configured in ini
  15. type MarkupParser struct {
  16. Enabled bool
  17. MarkupName string
  18. Command string
  19. FileExtensions []string
  20. IsInputFile bool
  21. }
  22. func newMarkup() {
  23. extensionReg := regexp.MustCompile(`\.\w`)
  24. for _, sec := range Cfg.Section("markup").ChildSections() {
  25. name := strings.TrimPrefix(sec.Name(), "markup.")
  26. if name == "" {
  27. log.Warn("name is empty, markup " + sec.Name() + "ignored")
  28. continue
  29. }
  30. extensions := sec.Key("FILE_EXTENSIONS").Strings(",")
  31. var exts = make([]string, 0, len(extensions))
  32. for _, extension := range extensions {
  33. if !extensionReg.MatchString(extension) {
  34. log.Warn(sec.Name() + " file extension " + extension + " is invalid. Extension ignored")
  35. } else {
  36. exts = append(exts, extension)
  37. }
  38. }
  39. if len(exts) == 0 {
  40. log.Warn(sec.Name() + " file extension is empty, markup " + name + " ignored")
  41. continue
  42. }
  43. command := sec.Key("RENDER_COMMAND").MustString("")
  44. if command == "" {
  45. log.Warn(" RENDER_COMMAND is empty, markup " + name + " ignored")
  46. continue
  47. }
  48. ExternalMarkupParsers = append(ExternalMarkupParsers, MarkupParser{
  49. Enabled: sec.Key("ENABLED").MustBool(false),
  50. MarkupName: name,
  51. FileExtensions: exts,
  52. Command: command,
  53. IsInputFile: sec.Key("IS_INPUT_FILE").MustBool(false),
  54. })
  55. }
  56. }
上海开阖软件有限公司 沪ICP备12045867号-1